doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Script_Compiler.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 #ifndef __SCRIPT_COMPILER_H__
29 #define __SCRIPT_COMPILER_H__
30 
31 const char * const RESULT_STRING = "<RESULT>";
32 
33 typedef struct opcode_s {
34  const char *name;
35  const char *opname;
36  int priority;
41 } opcode_t;
42 
43 // These opcodes are no longer necessary:
44 // OP_PUSH_OBJ:
45 // OP_PUSH_OBJENT:
46 
47 enum {
49 
55 
71 
79 
87 
92 
99 
101 
105 
114 
120 
129 
135 
147 
153 
156 
160 
164 
176 
178 
187 
190 
191  OP_BREAK, // placeholder op. not used in final code
192  OP_CONTINUE, // placeholder op. not used in final code
193 
195 };
196 
197 class idCompiler {
198 private:
199  static bool punctuationValid[ 256 ];
200  static const char *punctuation[];
201 
205 
208 
209  bool eof;
210  bool console;
217 
218  idVarDef *scope; // the function being parsed, or NULL
219  const idVarDef *basetype; // for accessing fields
220 
221  float Divide( float numerator, float denominator );
222  void Error( const char *error, ... ) const id_attribute((format(printf,2,3)));
223  void Warning( const char *message, ... ) const id_attribute((format(printf,2,3)));
224  idVarDef *OptimizeOpcode( const opcode_t *op, idVarDef *var_a, idVarDef *var_b );
225  idVarDef *EmitOpcode( const opcode_t *op, idVarDef *var_a, idVarDef *var_b );
226  idVarDef *EmitOpcode( int op, idVarDef *var_a, idVarDef *var_b );
227  bool EmitPush( idVarDef *expression, const idTypeDef *funcArg );
228  void NextToken( void );
229  void ExpectToken( const char *string );
230  bool CheckToken( const char *string );
231  void ParseName( idStr &name );
232  void SkipOutOfFunction( void );
233  void SkipToSemicolon( void );
234  idTypeDef *CheckType( void );
235  idTypeDef *ParseType( void );
236  idVarDef *FindImmediate( const idTypeDef *type, const eval_t *eval, const char *string ) const;
237  idVarDef *GetImmediate( idTypeDef *type, const eval_t *eval, const char *string );
239  idVarDef *SizeConstant( int size );
240  idVarDef *JumpConstant( int value );
241  idVarDef *JumpDef( int jumpfrom, int jumpto );
242  idVarDef *JumpTo( int jumpto );
243  idVarDef *JumpFrom( int jumpfrom );
244  idVarDef *ParseImmediate( void );
245  idVarDef *EmitFunctionParms( int op, idVarDef *func, int startarg, int startsize, idVarDef *object );
247  idVarDef *ParseObjectCall( idVarDef *object, idVarDef *func );
248  idVarDef *ParseEventCall( idVarDef *object, idVarDef *func );
250  idVarDef *LookupDef( const char *name, const idVarDef *baseobj );
251  idVarDef *ParseValue( void );
252  idVarDef *GetTerm( void );
253  bool TypeMatches( etype_t type1, etype_t type2 ) const;
254  idVarDef *GetExpression( int priority );
255  idTypeDef *GetTypeForEventArg( char argType );
256  void PatchLoop( int start, int continuePos );
257  void ParseReturnStatement( void );
258  void ParseWhileStatement( void );
259  void ParseForStatement( void );
260  void ParseDoWhileStatement( void );
261  void ParseIfStatement( void );
262  void ParseStatement( void );
263  void ParseObjectDef( const char *objname );
264  idTypeDef *ParseFunction( idTypeDef *returnType, const char *name );
265  void ParseFunctionDef( idTypeDef *returnType, const char *name );
266  void ParseVariableDef( idTypeDef *type, const char *name );
267  void ParseEventDef( idTypeDef *type, const char *name );
268  void ParseDefs( void );
269  void ParseNamespace( idVarDef *newScope );
270 
271 public :
272  static opcode_t opcodes[];
273 
274  idCompiler();
275  void CompileFile( const char *text, const char *filename, bool console );
276 };
277 
278 #endif /* !__SCRIPT_COMPILER_H__ */
idTypeDef * CheckType(void)
bool TypeMatches(etype_t type1, etype_t type2) const
GLsizei const GLfloat * value
Definition: glext.h:3614
void ParseWhileStatement(void)
void SkipOutOfFunction(void)
static opcode_t opcodes[]
struct opcode_s opcode_t
idVarDef * JumpDef(int jumpfrom, int jumpto)
void ParseDefs(void)
void NextToken(void)
etype_t
GLenum GLsizei GLenum format
Definition: glext.h:2846
void ParseReturnStatement(void)
#define const
Definition: getdate.c:251
idVarDef * EmitOpcode(const opcode_t *op, idVarDef *var_a, idVarDef *var_b)
void ParseName(idStr &name)
idVarDef * ParseImmediate(void)
idParser parser
idVarDef * ParseFunctionCall(idVarDef *func)
void ParseIfStatement(void)
idVarDef * GetTerm(void)
void SkipToSemicolon(void)
idVarDef * type_c
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
void ParseNamespace(idVarDef *newScope)
Definition: Token.h:71
idVarDef * JumpFrom(int jumpfrom)
const char * name
idVarDef * GetExpression(int priority)
const idVarDef * basetype
void ParseForStatement(void)
idVarDef * ParseObjectCall(idVarDef *object, idVarDef *func)
void void idVarDef * OptimizeOpcode(const opcode_t *op, idVarDef *var_a, idVarDef *var_b)
bool CheckToken(const char *string)
idTypeDef * immediateType
void Error(const char *error,...) const id_attribute((format(printf
static const char * punctuation[]
INT32 * numerator
Definition: wglext.h:503
idVarDef * type_b
idVarDef * LookupDef(const char *name, const idVarDef *baseobj)
void ParseDoWhileStatement(void)
idVarDef * SizeConstant(int size)
void ParseObjectDef(const char *objname)
idTypeDef * ParseFunction(idTypeDef *returnType, const char *name)
idParser * parserPtr
idVarDef * GetImmediate(idTypeDef *type, const eval_t *eval, const char *string)
void ParseVariableDef(idTypeDef *type, const char *name)
const char * opname
idVarDef * FindImmediate(const idTypeDef *type, const eval_t *eval, const char *string) const
void ParseEventDef(idTypeDef *type, const char *name)
bool rightAssociative
void ExpectToken(const char *string)
idTypeDef * ParseType(void)
idVarDef * JumpTo(int jumpto)
INT32 INT32 * denominator
Definition: wglext.h:503
void CompileFile(const char *text, const char *filename, bool console)
void PatchLoop(int start, int continuePos)
idVarDef * EmitFunctionParms(int op, idVarDef *func, int startarg, int startsize, idVarDef *object)
#define id_attribute(x)
Definition: sys_public.h:139
float Divide(float numerator, float denominator)
idVarDef * JumpConstant(int value)
eval_t immediate
const GLcharARB * name
Definition: glext.h:3629
GLsizeiptr size
Definition: glext.h:3112
idVarDef * ParseValue(void)
Definition: Str.h:116
idVarDef * ParseEventCall(idVarDef *object, idVarDef *func)
idVarDef * scope
idVarDef * VirtualFunctionConstant(idVarDef *func)
idTypeDef * GetTypeForEventArg(char argType)
idVarDef * type_a
void void Warning(const char *message,...) const id_attribute((format(printf
bool EmitPush(idVarDef *expression, const idTypeDef *funcArg)
static bool punctuationValid[256]
const char *const RESULT_STRING
void ParseStatement(void)
void ParseFunctionDef(idTypeDef *returnType, const char *name)
GLuint start
Definition: glext.h:2845
idVarDef * ParseSysObjectCall(idVarDef *func)