예제 #1
0
void DotBuilder::doElement(ASTElement* element)
{
  switch (element->getElementType())
  {
    case MELEMENT_BLOCK:
      doBlock(reinterpret_cast<ASTBlock*>(element));
      break;
    case MELEMENT_CONSTANT:
      doConstant(reinterpret_cast<ASTConstant*>(element));
      break;
    case MELEMENT_VARIABLE:
      doVariable(reinterpret_cast<ASTVariable*>(element));
      break;
    case MELEMENT_OPERATOR:
      doOperator(reinterpret_cast<ASTOperator*>(element));
      break;
    case MELEMENT_CALL:
      doCall(reinterpret_cast<ASTCall*>(element));
      break;
    case MELEMENT_TRANSFORM:
      doTransform(reinterpret_cast<ASTTransform*>(element));
      break;
    default:
      MP_ASSERT_NOT_REACHED();
  }
}
varInst *Mission::checkExpression(missionNode *node,int mode){

  varInst *ret=NULL;
  debug(3,node,mode,"checking expression");
  //  printRuntime();

  switch(node->tag){
  case DTAG_AND_EXPR:
  case DTAG_OR_EXPR:
  case DTAG_NOT_EXPR:
  case DTAG_TEST_EXPR:
    {
    bool res=checkBoolExpr(node,mode);
    ret=newVarInst(VI_TEMP);
    ret->type=VAR_BOOL;
    ret->bool_val=res;
    return ret;
    }
    break;
  case DTAG_CONST:
    {
    ret=doConst(node,mode);
    return ret;
    }
    break;
  case DTAG_VAR_EXPR:
    {
    ret=doVariable(node,mode);
    return ret;
    }
    break;
  case DTAG_FMATH:
    {
    ret=doMath(node,mode);
    return ret;
    }
    break;
  case DTAG_CALL:
    {
    ret=doCall(node,mode);
    return ret;
    }
    break;
  case DTAG_EXEC:
    {
    ret=doExec(node,mode);
    return ret;
    }
    break;
  default:
    fatalError(node,mode,"no such expression");
    assert(0);
    break;
  }
  return ret;
}
void Mission::doArguments( missionNode *node, int mode, varInstMap *varmap )
{
    int nr_arguments = 0;
    if (mode == SCRIPT_PARSE) {
        if (parsemode == PARSE_DECL) {
            vector< easyDomNode* >::const_iterator siter;
            for (siter = node->subnodes.begin(); siter != node->subnodes.end(); siter++) {
                missionNode *snode = (missionNode*) *siter;
                if (snode->tag == DTAG_DEFVAR) {
                    doDefVar( snode, mode );
                    nr_arguments++;
                } else {
                    fatalError( node, mode, "only defvars allowed below argument node" );
                    assert( 0 );
                }
            }
            node->script.nr_arguments = nr_arguments;
        }
    }
    nr_arguments = node->script.nr_arguments;
    if (mode == SCRIPT_RUN) {
        if (varmap) {
            int nr_called = varmap->size();
            if (nr_arguments != nr_called) {
                fatalError( node, mode, "wrong number of args in doScript " );
                assert( 0 );
            }
            for (int i = 0; i < nr_arguments; i++) {
                missionNode *defnode = (missionNode*) node->subnodes[i];

                doDefVar( defnode, mode );
                varInst     *vi = doVariable( defnode, mode );

                varInst     *call_vi = (*varmap)[defnode->script.name];
                if (call_vi == NULL) {
                    fatalError( node, mode, "argument var "+node->script.name+" no found in varmap" );
                    assert( 0 );
                }
                assignVariable( vi, call_vi );
            }
        } else
        //no varmap == 0 args
        if (nr_arguments != 0) {
            fatalError( node, mode, "doScript expected to be called with arguments" );
            assert( 0 );
        }
    }
    if (mode == SCRIPT_PARSE) {
        if (parsemode == PARSE_DECL) {
            missionNode *exec_scope = scope_stack.back();
            exec_scope->script.nr_arguments = nr_arguments;
            node->script.nr_arguments = nr_arguments;
        }
    }
}