MCPcopy Create free account
hub / github.com/anjo76/angelscript / CompilePostFixExpression

Method CompilePostFixExpression

sdk/angelscript/source/as_compiler.cpp:10361–10418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10359}
10360
10361int asCCompiler::CompilePostFixExpression(asCArray<asCScriptNode *> *postfix, asCExprContext *ctx)
10362{
10363 // Shouldn't send any byte code
10364 asASSERT(ctx->bc.GetLastInstr() == -1);
10365
10366 // Set the context to a dummy type to avoid further
10367 // errors in case the expression fails to compile
10368 ctx->type.SetDummy();
10369
10370 // Evaluate the operands and operators
10371 asCArray<asCExprContext*> free;
10372 asCArray<asCExprContext*> expr;
10373 int ret = 0;
10374 for( asUINT n = 0; ret == 0 && n < postfix->GetLength(); n++ )
10375 {
10376 asCScriptNode *node = (*postfix)[n];
10377 if( node->nodeType == snExprTerm )
10378 {
10379 asCExprContext *e = free.GetLength() ? free.PopLast() : asNEW(asCExprContext)(engine);
10380 expr.PushLast(e);
10381 e->exprNode = node;
10382 ret = CompileExpressionTerm(node, e);
10383 }
10384 else
10385 {
10386 asCExprContext *r = expr.PopLast();
10387 asCExprContext *l = expr.PopLast();
10388
10389 // Now compile the operator
10390 asCExprContext *e = free.GetLength() ? free.PopLast() : asNEW(asCExprContext)(engine);
10391 ret = CompileOperator(node, l, r, e);
10392
10393 expr.PushLast(e);
10394
10395 // Free the operands
10396 l->Clear();
10397 free.PushLast(l);
10398 r->Clear();
10399 free.PushLast(r);
10400 }
10401 }
10402
10403 if( ret == 0 )
10404 {
10405 asASSERT(expr.GetLength() == 1);
10406
10407 // The final result should be moved to the output context
10408 MergeExprBytecodeAndType(ctx, expr[0]);
10409 }
10410
10411 // Clean up
10412 for( asUINT e = 0; e < expr.GetLength(); e++ )
10413 asDELETE(expr[e], asCExprContext);
10414 for( asUINT f = 0; f < free.GetLength(); f++ )
10415 asDELETE(free[f], asCExprContext);
10416
10417 return ret;
10418}

Callers

nothing calls this directly

Calls 6

GetLastInstrMethod · 0.80
SetDummyMethod · 0.80
PopLastMethod · 0.80
PushLastMethod · 0.80
GetLengthMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected