29 #include "../../idlib/precompiled.h"
32 #include "../Game_local.h"
34 #define FUNCTION_PRIORITY 2
35 #define INT_PRIORITY 2
36 #define NOT_PRIORITY 5
37 #define TILDE_PRIORITY 5
38 #define TOP_PRIORITY 7
42 "+=",
"-=",
"*=",
"/=",
"%=",
"&=",
"|=",
"++",
"--",
43 "&&",
"||",
"<=",
">=",
"==",
"!=",
"::",
";",
",",
44 "~",
"!",
"*",
"/",
"%",
"(",
")",
"-",
"+",
45 "=",
"[",
"]",
".",
"<",
">" ,
"&",
"|",
":",
NULL
235 if ( (
id >= 0 ) && (
id < 256 ) ) {
252 va_start( argptr, message );
253 vsprintf(
string, message, argptr );
270 va_start( argptr, message );
271 vsprintf(
string, message, argptr );
287 memset( &eval, 0,
sizeof( eval ) );
289 if ( eval.
_int < 0 ) {
306 memset( &eval, 0,
sizeof( eval ) );
321 memset( &eval, 0,
sizeof( eval ) );
365 if ( denominator == 0 ) {
366 Error(
"Divide by zero" );
384 etype = type->
Type();
445 Error(
"weird immediate type" );
499 memset( &c, 0,
sizeof( c ) );
541 default: type =
NULL;
break;
603 statement->
a = var_a;
604 statement->
b = var_b;
605 statement->
c = var_c;
685 Error(
"Unexpected end of file inside function '%s'. Missing closing braces.",
scope->
Name() );
687 Error(
"Unexpected end of file inside object '%s'. Missing closing braces.",
scope->
Name() );
689 Error(
"Unexpected end of file inside namespace '%s'. Missing closing braces.",
scope->
Name() );
691 Error(
"Unexpected end of file inside braced section" );
707 for( i = 0; i < 3; i++ ) {
708 if ( !lex.ReadToken( &token2 ) ) {
709 Error(
"Couldn't read vector. '%s' is not in the form of 'x y z'",
token.
c_str() );
712 if ( !lex.CheckTokenType(
TT_NUMBER, 0, &token2 ) ) {
713 Error(
"expected a number following '-' but found '%s' in vector '%s'", token2.c_str(),
token.
c_str() );
719 Error(
"vector '%s' is not in the form of 'x y z'. expected float value, found '%s'",
token.
c_str(), token2.c_str() );
732 if (
token ==
"$" ) {
738 if (
token ==
"{" ) {
743 if (
token ==
"}" ) {
772 if (
token !=
string ) {
788 if (
token !=
string ) {
855 if (
token ==
"float" ) {
857 }
else if (
token ==
"vector" ) {
859 }
else if (
token ==
"entity" ) {
861 }
else if (
token ==
"string" ) {
863 }
else if (
token ==
"void" ) {
865 }
else if (
token ==
"object" ) {
867 }
else if (
token ==
"boolean" ) {
869 }
else if (
token ==
"namespace" ) {
871 }
else if (
token ==
"scriptEvent" ) {
899 Error(
"scriptEvents can only defined in the global namespace" );
903 Error(
"A namespace may only be defined globally, or within another namespace" );
944 Error(
"'%s' is not a function", func->
Name() );
953 Error(
"too many parameters" );
960 Error(
"type mismatch on parm %i of call to '%s'", arg + 1, func->
Name() );
966 size += funcArg->
Size();
975 if ( arg < type->NumParameters() ) {
976 Error(
"too few parameters for function '%s'", func->
Name() );
1000 switch( returnType->
Type() ) {
1026 Error(
"Invalid return type for function '%s'", func->
Name() );
1045 EmitOpcode( resultOp, returnDef, resultDef );
1059 Error(
"'%s' is not a function", funcDef->
Name() );
1063 Error(
"Function '%s' has not been defined yet", funcDef->
GlobalName() );
1069 Error(
"Built-in functions cannot be called as threads" );
1079 Error(
"No 'self' within scope" );
1084 Error(
"Built-in functions cannot be called without an object" );
1114 Error(
"Cannot call built-in functions as a thread" );
1118 Error(
"'%s' is not a function", funcDef->
Name() );
1122 Error(
"\"%s\" cannot be called with object notation", funcDef->
Name() );
1141 Error(
"Cannot call built-in functions as a thread" );
1145 Error(
"'%s' is not a function", funcDef->
Name() );
1149 Error(
"\"%s\" cannot be called with object notation", funcDef->
Name() );
1153 Error(
"\"%s\" is not callable as a 'sys' function", funcDef->
Name() );
1193 Error(
"Unknown value \"%s\"", name );
1197 type_b = field->
Type();
1204 Error(
"Invalid type for ++" );
1210 Error(
"Invalid type for --" );
1280 Error(
"Unknown value \"%s\"", name.
c_str() );
1310 switch( e->
Type() ) {
1316 Error(
"type mismatch for ~" );
1328 switch( e->
Type() ) {
1350 Error(
"Invalid type for !" );
1361 Error(
"type mismatch for !" );
1384 switch( e->
Type() ) {
1393 Error(
"type mismatch for -" );
1408 Error(
"type mismatch for int()" );
1421 Error(
"Invalid thread call" );
1445 if ( type1 == type2 ) {
1475 if ( priority == 0 ) {
1480 if (
token ==
";" ) {
1542 type_b = e2->
Type();
1545 if ( op->
name[ 0 ] ==
'.' ) {
1567 Error(
"type mismatch for '%s'", oldop->
name );
1597 Error(
"Expecting function call after 'thread'" );
1621 Error(
"type mismatch for '%s'", op->
name );
1666 pos->
a =
JumpDef( i, continuePos );
1684 Error(
"expecting return value" );
1713 Error(
"type mismatch for return value" );
1969 Error(
"cannot break outside of a loop" );
1978 Error(
"cannot contine outside of a loop" );
2009 const char *fieldname;
2017 Error(
"Objects cannot be defined within functions or other objects" );
2022 Error(
"'%s' : redefinition; different basic types", objname );
2031 Error(
"Objects may only inherit from objects." );
2057 fieldname =
va(
"%s field", fieldtype->
Name() );
2100 newtype.AddFunctionParm( type, parmName );
2126 Error(
"Functions may not be defined within other functions" );
2157 for( i = 0; i < numParms; i++ ) {
2168 for( i = 0; i < numParms; i++ ) {
2170 Error(
"'%s' defined more than once in function parameters", type->
GetParmName( i ) );
2188 if ( constructorFunc ) {
2194 if ( constructorFunc ) {
2215 if ( destructorFunc ) {
2220 if ( destructorFunc ) {
2269 Error(
"%s redeclared", name );
2304 Error(
"bad initialization for '%s'", name );
2313 Error(
"wrong immediate type for '-' on variable '%s'", name );
2318 Error(
"wrong immediate type for '%s'", name );
2410 Error(
"Unknown event '%s'", name );
2415 if ( !expectedType ) {
2418 if ( returnType != expectedType ) {
2419 Error(
"Return type doesn't match internal return type '%s'", expectedType->
Name() );
2427 num = strlen( format );
2428 for( i = 0; i <
num; i++ ) {
2430 if ( !expectedType || ( expectedType == &
type_void ) ) {
2431 Error(
"Invalid parameter '%c' in definition of '%s' event.", format[ i ], name );
2436 if ( argType != expectedType ) {
2437 Error(
"The type of parm %d ('%s') does not match the internal type '%s' in definition of '%s' event.",
2441 newtype.AddFunctionParm( argType,
"" );
2443 if ( i < num - 1 ) {
2445 Error(
"Too few parameters for event definition. Internal definition has %d parameters.", num );
2451 Error(
"Too many parameters for event definition. Internal definition has %d parameters.", num );
2458 Error(
"Type mismatch on redefinition of '%s'", name );
2467 for( i = 0; i <
num; i++ ) {
2515 Error(
"Unknown object name '%s'", name.
c_str() );
2578 compile_time.
Start();
2622 while( !
eof && !error ) {
2645 compile_time.
Stop();
void SetName(const char *newname)
idTypeDef * CheckType(void)
bool TypeMatches(etype_t type1, etype_t type2) const
GLsizei const GLfloat * value
bool Compare(const idVec3 &a) const
idVarDef * GetDefList(const char *name) const
void ParseWhileStatement(void)
assert(prefInfo.fullscreenBtn)
idVarDef def_string & type_string
void UnreadToken(idToken *token)
int Cmp(const char *text) const
void SkipOutOfFunction(void)
static opcode_t opcodes[]
idVarDef * JumpDef(int jumpfrom, int jumpto)
void Printf(const char *fmt,...) const id_attribute((format(printf
statement_t * AllocStatement(void)
GLenum GLsizei GLenum format
statement_t & GetStatement(int index)
idVarDef * GetDef(const idTypeDef *type, const char *name, const idVarDef *scope) const
void SetNum(int newnum, bool resize=true)
void ParseReturnStatement(void)
#define D_EVENT_ENTITY_NULL
idVarDef * EmitOpcode(const opcode_t *op, idVarDef *var_a, idVarDef *var_b)
void ParseName(idStr &name)
idVarDef * ParseImmediate(void)
const idEventDef * eventdef
idVarDef def_object & type_object
float GetFloatValue(void)
int GetFilenum(const char *name)
idVarDef * ParseFunctionCall(idVarDef *func)
void ParseIfStatement(void)
void SkipToSemicolon(void)
idVarDef def_namespace & type_namespace
int LoadMemory(const char *ptr, int length, const char *name)
void FreeSource(bool keepDefines=false)
void SetTypeDef(idTypeDef *_type)
GLuint GLuint GLsizei GLenum type
void ParseNamespace(idVarDef *newScope)
idVarDef * JumpFrom(int jumpfrom)
idVarDef def_scriptevent & type_scriptevent
int NumParameters(void) const
double Milliseconds(void) const
const char * Name(void) const
idVarDef * GetExpression(int priority)
int Icmp(const char *text) const
const idVarDef * basetype
idVarDef def_void & type_void
const char * GlobalName(void) const
void FreeDef(idVarDef *d, const idVarDef *scope)
void ParseForStatement(void)
const function_t * GetFunction(int funcNumber) const
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)
idVarDef def_vector & type_vector
idTypeDef * immediateType
int ReadToken(idToken *token)
void Error(const char *error,...) const id_attribute((format(printf
void SetString(const char *string, bool constant)
static const char * punctuation[]
const char * GetFilename(int num)
static const idEventDef * FindEvent(const char *name)
const char * GetParmName(int parmNumber) const
idTypeDef * TypeDef(void) const
int GetFunctionNumber(const function_t *func) const
idVarDef def_float & type_float
const char * Name(void) const
idVarDef def_boolean & type_boolean
#define SCRIPT_DEFAULTDEFS
idVarDef * AllocDef(idTypeDef *type, const char *name, idVarDef *scope, bool constant)
idTypeDef * ReturnType(void) const
void AddFunction(const function_t *func)
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)
initialized_t initialized
idVarDef * GetImmediate(idTypeDef *type, const eval_t *eval, const char *string)
idVarDef def_entity & type_entity
#define FUNCTION_PRIORITY
int GetPunctuationId(const char *p)
void ParseVariableDef(idTypeDef *type, const char *name)
int NumFunctions(void) const
void void Warning(const char *str,...) const id_attribute((format(printf
void AddField(idTypeDef *fieldtype, const char *name)
idVarDef def_virtualfunction & type_virtualfunction
idVarDef * FindImmediate(const idTypeDef *type, const eval_t *eval, const char *string) const
idTypeDef * GetParmType(int parmNumber) const
void ParseEventDef(idTypeDef *type, const char *name)
idTypeDef * SuperClass(void) const
idVarDef def_pointer & type_pointer
void ExpectToken(const char *string)
idTypeDef * ParseType(void)
idVarDef * JumpTo(int jumpto)
void SetFieldType(idTypeDef *type)
bool Inherits(const idTypeDef *basetype) const
INT32 INT32 * denominator
idTypeDef * AllocType(idTypeDef &type)
idTypeDef * GetType(idTypeDef &type, bool allocate)
void CompileFile(const char *text, const char *filename, bool console)
idVarDef * FindFreeResultDef(idTypeDef *type, const char *name, idVarDef *scope, const idVarDef *a, const idVarDef *b)
void PatchLoop(int start, int continuePos)
idVarDef * EmitFunctionParms(int op, idVarDef *func, int startarg, int startsize, idVarDef *object)
static WindowRef ValidModeCallbackProc inCallback OSStatus err
idVarDef def_function & type_function
unsigned short linenumber
idTypeDef * FindType(const char *name)
void SetValue(const eval_t &value, bool constant)
float Divide(float numerator, float denominator)
char error[MAX_STRING_CHARS]
idVarDef * JumpConstant(int value)
const char * GetArgFormat(void) const
idVarDef * ParseValue(void)
idVarDef * Next(void) const
int SkipBracedSection(bool parseFirstBrace=true)
idVarDef * ParseEventCall(idVarDef *object, idVarDef *func)
int vsprintf(idStr &string, const char *fmt, va_list argptr)
idVarDef def_argsize & type_argsize
const char * c_str(void) const
idVarDef * VirtualFunctionConstant(idVarDef *func)
idTypeDef * GetTypeForEventArg(char argType)
idVarDef * returnStringDef
void void Warning(const char *message,...) const id_attribute((format(printf
bool EmitPush(idVarDef *expression, const idTypeDef *funcArg)
idVarDef def_jumpoffset & type_jumpoffset
function_t * FindFunction(const char *name) const
idTypeDef * PointerType(void) const
char GetReturnType(void) const
static bool punctuationValid[256]
char * va(const char *fmt,...)
function_t & AllocFunction(idVarDef *def)
const char *const RESULT_STRING
void ParseStatement(void)
int sprintf(idStr &string, const char *fmt,...)
void ParseFunctionDef(idTypeDef *returnType, const char *name)
const char * GetFileName(void) const
void SetObject(idScriptObject *object)
idVarDef * ParseSysObjectCall(idVarDef *func)
idTypeDef * FieldType(void) const