============ idCompiler::EmitFunctionParms ============ */
| 934 | ============ |
| 935 | */ |
| 936 | idVarDef *idCompiler::EmitFunctionParms( int op, idVarDef *func, int startarg, int startsize, idVarDef *object ) { |
| 937 | idVarDef *e; |
| 938 | const idTypeDef *type; |
| 939 | const idTypeDef *funcArg; |
| 940 | idVarDef *returnDef; |
| 941 | idTypeDef *returnType; |
| 942 | int arg; |
| 943 | int size; |
| 944 | int resultOp; |
| 945 | |
| 946 | type = func->TypeDef(); |
| 947 | if ( func->Type() != ev_function ) { |
| 948 | Error( "'%s' is not a function", func->Name() ); |
| 949 | } |
| 950 | |
| 951 | // copy the parameters to the global parameter variables |
| 952 | arg = startarg; |
| 953 | size = startsize; |
| 954 | if ( !CheckToken( ")" ) ) { |
| 955 | do { |
| 956 | if ( arg >= type->NumParameters() ) { |
| 957 | Error( "too many parameters" ); |
| 958 | } |
| 959 | |
| 960 | e = GetExpression( TOP_PRIORITY ); |
| 961 | |
| 962 | funcArg = type->GetParmType( arg ); |
| 963 | if ( !EmitPush( e, funcArg ) ) { |
| 964 | Error( "type mismatch on parm %i of call to '%s'", arg + 1, func->Name() ); |
| 965 | } |
| 966 | |
| 967 | if ( funcArg->Type() == ev_object ) { |
| 968 | size += type_object.Size(); |
| 969 | } else { |
| 970 | size += funcArg->Size(); |
| 971 | } |
| 972 | |
| 973 | arg++; |
| 974 | } while( CheckToken( "," ) ); |
| 975 | |
| 976 | ExpectToken( ")" ); |
| 977 | } |
| 978 | |
| 979 | if ( arg < type->NumParameters() ) { |
| 980 | Error( "too few parameters for function '%s'", func->Name() ); |
| 981 | } |
| 982 | |
| 983 | if ( op == OP_CALL ) { |
| 984 | EmitOpcode( op, func, 0 ); |
| 985 | } else if ( ( op == OP_OBJECTCALL ) || ( op == OP_OBJTHREAD ) ) { |
| 986 | EmitOpcode( op, object, VirtualFunctionConstant( func ) ); |
| 987 | |
| 988 | // need arg size seperate since script object may be NULL |
| 989 | statement_t &statement = gameLocal.program.GetStatement( gameLocal.program.NumStatements() - 1 ); |
| 990 | statement.c = SizeConstant( func->value.functionPtr->parmTotal ); |
| 991 | // DG: before changes I did to ParseFunctionDef(), func->value.functionPtr->parmTotal was 0 |
| 992 | // if the function declaration/prototype has been parsed already, but the |
| 993 | // definition/implementation hadn't been parsed yet. That was wrong and sometimes |
nothing calls this directly
no test coverage detected