コード例 #1
0
ファイル: MergeBlocks.cpp プロジェクト: cqzhanghy/binaryen
 void visitBlock(Block *curr) override {
   bool more = true;
   while (more) {
     more = false;
     for (size_t i = 0; i < curr->list.size(); i++) {
       Block* child = curr->list[i]->dyn_cast<Block>();
       if (!child) continue;
       if (child->name.is()) continue; // named blocks can have breaks to them (and certainly do, if we ran RemoveUnusedNames and RemoveUnusedBrs)
       ExpressionList merged;
       for (size_t j = 0; j < i; j++) {
         merged.push_back(curr->list[j]);
       }
       for (auto item : child->list) {
         merged.push_back(item);
       }
       for (size_t j = i + 1; j < curr->list.size(); j++) {
         merged.push_back(curr->list[j]);
       }
       curr->list = merged;
       more = true;
       break;
     }
   }
 }
コード例 #2
0
ファイル: ast.cpp プロジェクト: Dymanik/LenguajesII
		TType* typeChk(Symtable& t,TType* expected = NULL){
            bool err=false;
#ifdef DEBUG
            cout << "values size " << values.size() << endl;
#endif

            TType* elem = values[0]->typeChk(t);

            for(int i=1; i<values.size(); i++){
                if(elem != values[i]->typeChk(t))
                    err=true;
            }

            if(err){
                fprintf(stderr, "Array elements are not the same type.\n");
                return NULL;
            }else{
#ifdef DEBUG
                cout << "cons array type " << elem->name << endl;
#endif
                return new TArray(*elem,values.size());
            }
        
        }
ExpressionList * 
ChannelCommCommonPluginInfo::GetCreatedExpressions(const avtDatabaseMetaData *md)
{
    int i;
    char name[1024], defn[1024];
    ExpressionList *el = new ExpressionList;
    int numMeshes = md->GetNumMeshes();
    for (i = 0 ; i < numMeshes ; i++)
    {
        const avtMeshMetaData *mmd = md->GetMesh(i);
        {
            Expression e2;
            sprintf(name, "operators/ChannelComm/%s", mmd->name.c_str());
            e2.SetName(name);
            e2.SetType(Expression::ScalarMeshVar);
            e2.SetFromOperator(true);
            e2.SetOperatorName("ChannelComm");
            sprintf(defn, "cell_constant(<%s>, 0.)", mmd->name.c_str());
            e2.SetDefinition(defn);
            el->AddExpressions(e2);
        }
    }
    return el;
}
コード例 #4
0
void
AddExpression(ExpressionList &new_list, std::string &var, int time)
{
    char exp_name[1024];
    SNPRINTF(exp_name, 1024, "AVT_TRACE_HIST_%s", var.c_str());
    char exp_defn[1024];
    const char *meshname = var.c_str(); // The expression language will let
                                        // you put in a variable for the
                                        // meshname since it can use that to 
                                        // find the meshname.
    meshname = "quadmesh";
    SNPRINTF(exp_defn, 1024, "pos_cmfe(<[%d]i:%s>, %s, 0.)", time, 
                                                var.c_str(), meshname);

    Expression exp;
    exp.SetName(exp_name);
    exp.SetDefinition(exp_defn);
    exp.SetType(Expression::Unknown);
    new_list.AddExpressions(exp);
}
コード例 #5
0
ファイル: ast.cpp プロジェクト: Dymanik/LenguajesII
		TType* typeChk(Symtable& t,TType* expected = NULL){
            TType* tip;
		    std::vector<TType*> args;
			for(int i=0;i<arguments.size();i++){
                tip = arguments[i]->typeChk(t);
				if(tip == NULL){
                    cerr << "Type of argument " << i << " doesn't exist" << endl;
                }else{
                    args.push_back(tip); 
                }
			}

            if(t.lookupFunc(id.name,args) == NULL){
                cerr << "Function "<<id.name<<" was not declared"<< endl;
			    return NULL;
            }else{
                #ifdef DEBUG
                cerr << "Function call type "<<(t.lookupFunc(id.name,args)->type)->name<< endl;
                #endif
                return t.lookupFunc(id.name,args)->type;
            }
		}
コード例 #6
0
avtContract_p
avtVolumeFilter::ModifyContract(avtContract_p contract)
{
    avtContract_p newcontract = NULL;

    if (primaryVariable != NULL)
    {
        delete [] primaryVariable;
    }

    avtDataRequest_p ds = new avtDataRequest(contract->GetDataRequest());
    const char *var = ds->GetVariable();

    bool setupExpr = false;
    char exprDef[128];
    std::string exprName = (std::string)"_expr_" + (std::string)var;

    if (atts.GetScaling() == VolumeAttributes::Linear)
    {
#ifdef HAVE_LIBSLIVR
        if ((atts.GetRendererType() == VolumeAttributes::RayCastingSLIVR) ||
            ((atts.GetRendererType() == VolumeAttributes::RayCasting) && (atts.GetSampling() == VolumeAttributes::Trilinear)))
            ds->SetDesiredGhostDataType(GHOST_ZONE_DATA);
#endif
        newcontract = new avtContract(contract, ds);
        primaryVariable = new char[strlen(var)+1];
        strcpy(primaryVariable, var);
    }
    else if (atts.GetScaling() == VolumeAttributes::Log)
    {
        setupExpr = true;
        if (atts.GetUseColorVarMin())
        {
            char m[16];
            SNPRINTF(m, 16, "%f", atts.GetColorVarMin());
            SNPRINTF(exprDef, 128, "log10withmin(<%s>, %s)", var, m);
        }
        else
        {
            SNPRINTF(exprDef, 128, "log10(<%s>)", var);
        }
        avtDataRequest_p nds = new avtDataRequest(exprName.c_str(),
                               ds->GetTimestep(), ds->GetRestriction());
        nds->AddSecondaryVariable(var);
#ifdef HAVE_LIBSLIVR
        if ((atts.GetRendererType() == VolumeAttributes::RayCastingSLIVR) ||
            ((atts.GetRendererType() == VolumeAttributes::RayCasting) && (atts.GetSampling() == VolumeAttributes::Trilinear)))
            nds->SetDesiredGhostDataType(GHOST_ZONE_DATA);
#endif
        newcontract = new avtContract(contract, nds);
        primaryVariable = new char[exprName.size()+1];
        strcpy(primaryVariable, exprName.c_str());
    }
    else // VolumeAttributes::Skew)
    {
        setupExpr = true;
        SNPRINTF(exprDef, 128, "var_skew(<%s>, %f)", var,
                 atts.GetSkewFactor());
        avtDataRequest_p nds =
            new avtDataRequest(exprName.c_str(),
                               ds->GetTimestep(), ds->GetRestriction());
        nds->AddSecondaryVariable(var);
#ifdef HAVE_LIBSLIVR
        if ((atts.GetRendererType() == VolumeAttributes::RayCastingSLIVR) ||
            ((atts.GetRendererType() == VolumeAttributes::RayCasting) && (atts.GetSampling() == VolumeAttributes::Trilinear)))
            nds->SetDesiredGhostDataType(GHOST_ZONE_DATA);
#endif
        newcontract = new avtContract(contract, nds);
        primaryVariable = new char[strlen(exprName.c_str())+1];
        strcpy(primaryVariable, exprName.c_str());
    }

    if (setupExpr)
    {
        ExpressionList *elist = ParsingExprList::Instance()->GetList();
        Expression *e = NULL;
        for (int i = 0 ; i < elist->GetNumExpressions() ; i++)
        {
            if (elist->GetExpressions(i).GetName() == exprName)
            {
                e = &(elist->GetExpressions(i));
                break;
            }
        }
        bool shouldDelete = false;
        if (e == NULL)
        {
            e = new Expression();
            shouldDelete = true;
        }

        e->SetName(exprName.c_str());
        e->SetDefinition(exprDef);
        e->SetType(Expression::ScalarMeshVar);
        elist->AddExpressions(*e);
        if (shouldDelete)
            delete e;
    }

    newcontract->NoStreaming();
    newcontract->SetHaveRectilinearMeshOptimizations(true);
    return newcontract;
}
コード例 #7
0
avtContract_p
avtVectorFilter::ModifyContract(avtContract_p contract)
{
    avtContract_p rv = contract;
    avtDataRequest_p ds = contract->GetDataRequest();

    //
    // Create the expression definition
    //
    string edef = string("magnitude(<") + ds->GetVariable() + string(">)");


    ExpressionList *elist = ParsingExprList::Instance()->GetList();
    Expression *e = new Expression();
        
    e->SetName(magVarName.c_str());
    e->SetDefinition(edef.c_str());
    e->SetType(Expression::ScalarMeshVar);
    elist->AddExpressions(*e);
    delete e;

    // Create a new dcontract so that we can add the secondary var.
    avtDataRequest_p nds = new avtDataRequest(ds->GetVariable(),
                ds->GetTimestep(), ds->GetRestriction());
    nds->AddSecondaryVariable(magVarName.c_str());
    rv = new avtContract(contract, nds);
    rv->SetCalculateVariableExtents(magVarName, true);
    
    // If we're not using the stride, then we have to calculate
    // the per-domain vectorc count by dividing by the number of
    // domains, which we can't calculate if we're streaming.
    if (!useStride)
        rv->NoStreaming();

    avtDataAttributes &data = GetInput()->GetInfo().GetAttributes();
    if (contract->GetDataRequest()->MayRequireZones() || 
        contract->GetDataRequest()->MayRequireNodes() ||
        origOnly)
    {
        keepNodeZone = true;
        if (data.ValidActiveVariable())
        {
            if (data.GetCentering() == AVT_NODECENT)
            {
                rv->GetDataRequest()->TurnNodeNumbersOn();
            }
            else if (data.GetCentering() == AVT_ZONECENT)
            {
                rv->GetDataRequest()->TurnZoneNumbersOn();
            }
        }
        else 
        {
            // canot determine variable centering, so turn on both
            // node numbers and zone numbers.
            rv->GetDataRequest()->TurnNodeNumbersOn();
            rv->GetDataRequest()->TurnZoneNumbersOn();
        }
    }
    else
    {
        keepNodeZone = false;
    }

    return rv;
}
コード例 #8
0
ファイル: debugger.cpp プロジェクト: 8l/objeck-lang
void Runtime::Debugger::EvaluateIntFloatReference(Reference* reference, int index, bool is_float) {
  long* array = (long*)ref_mem[index];
  if(array) {
    const int max = array[0];
    const int dim = array[1];

    // de-reference array value
    ExpressionList* indices = reference->GetIndices();
    if(indices) {
      // calculate indices values
      vector<Expression*> expressions = indices->GetExpressions();
      vector<int> values;
      for(size_t i = 0; i < expressions.size(); i++) {
        EvaluateExpression(expressions[i]);
        if(expressions[i]->GetExpressionType() == INT_LIT_EXPR) {
          values.push_back(static_cast<IntegerLiteral*>(expressions[i])->GetValue());
        }
        else {
          values.push_back(expressions[i]->GetIntValue());
        }
      }
      // match the dimensions
      if(expressions.size() == (size_t)dim) {
        // calculate indices
        array += 2;
        int j = dim - 1;
        long array_index = values[j--];
        for(long i = 1; i < dim; i++) {
          array_index *= array[i];
          array_index += values[j--];
        }
        array += dim;

        // check float array bounds
        if(is_float) {
          array_index *= 2;
          if(array_index > -1 && array_index < max * 2) {
            FLOAT_VALUE value;
            memcpy(&value, &array[array_index], sizeof(FLOAT_VALUE));
            reference->SetFloatValue(value);
          }
          else {
            wcout << L"array index out of bounds." << endl;
            is_error = true;
          }
        }
        // check int array bounds
        else {
          if(array_index > -1 && array_index < max) {
            reference->SetIntValue(array[array_index]);
          }
          else {
            wcout << L"array index out of bounds." << endl;
            is_error = true;
          }
        }
      }
      else {
        wcout << L"array dimension mismatch." << endl;
        is_error = true;
      }
    }
    // set array address
    else {
      reference->SetArrayDimension(dim);
      reference->SetArraySize(max);
      reference->SetIntValue(ref_mem[index]);
    }
  }
  else {
    wcout << L"current array value is Nil" << endl;
    is_error = true;
  }
}
コード例 #9
0
avtContract_p
avtCracksClipperFilter::ModifyContract(avtContract_p inContract)
{
    calculateDensity = false;

    if (strncmp(pipelineVariable, "operators/CracksClipper",
                strlen("operators/CracksClipper")) == 0)
    {
        calculateDensity = true;
        varname = pipelineVariable;
    }

    // Retrieve secondary variables, if any, to pass along to the 
    // newly created DataSpec
    avtDataRequest_p inDR = inContract->GetDataRequest();
    avtDataRequest_p outDR; 
    avtDataAttributes &inAtts = GetInput()->GetInfo().GetAttributes();
    if (calculateDensity)
    {
        outDR = new avtDataRequest(inDR, inAtts.GetMeshname().c_str());   
    }
    else
    {
        outDR = new avtDataRequest(inDR);
    }


    std::vector<CharStrRef> vars2 = inDR->GetSecondaryVariablesWithoutDuplicates();

    // Add any previously existing SecondaryVariables.
    for (size_t i = 0; i < vars2.size(); i++)
    {
        outDR->AddSecondaryVariable(*(vars2[i]));
    }
    // Add secondary variables necessary for CracksClipper
    outDR->AddSecondaryVariable(atts.GetCrack1Var().c_str());
    outDR->AddSecondaryVariable(atts.GetCrack2Var().c_str());
    outDR->AddSecondaryVariable(atts.GetCrack3Var().c_str());
    outDR->AddSecondaryVariable(atts.GetStrainVar().c_str());

    if (calculateDensity)
    {
        outDR->AddSecondaryVariable(atts.GetInMassVar().c_str());
    }


    ExpressionList *elist = ParsingExprList::Instance()->GetList();
    Expression *e = new Expression();

    std::string edef = std::string("volume2(<") + inAtts.GetMeshname() + 
                       std::string(">)");
    e->SetName("cracks_vol");
    e->SetDefinition(edef.c_str());
    e->SetType(Expression::ScalarMeshVar);
    elist->AddExpressions(*e);
    delete e;

    outDR->AddSecondaryVariable("cracks_vol");


    avtContract_p rv = new avtContract(inContract, outDR);

    //
    // Since this filter 'clips' the dataset, the zone and possibly
    // node numbers will be invalid, request them when needed.
    //
    if (inContract->GetDataRequest()->MayRequireZones() || 
        inContract->GetDataRequest()->MayRequireNodes())
    {
        if (inAtts.ValidActiveVariable())
        {
            if (inAtts.GetCentering() == AVT_NODECENT)
            {
                rv->GetDataRequest()->TurnNodeNumbersOn();
            }
            else if (inAtts.GetCentering() == AVT_ZONECENT)
            {
                rv->GetDataRequest()->TurnZoneNumbersOn();
            }
        }
        else 
        {
            // canot determine variable centering, so turn on both
            // node numbers and zone numbers.
            rv->GetDataRequest()->TurnNodeNumbersOn();
            rv->GetDataRequest()->TurnZoneNumbersOn();
        }
    }
    return rv; 
}
コード例 #10
0
ファイル: convert.C プロジェクト: burlen/visit_vtk_7_src
int main(int argc, char *argv[])
{
    int  i;

    bool parallel = false;
#ifdef PARALLEL
    parallel = true;
    PAR_Init(argc, argv);
#endif
    VisItInit::Initialize(argc, argv);

    //
    // Initialize the plugin readers.
    //
    DatabasePluginManager *dbmgr = new DatabasePluginManager;
    dbmgr->Initialize(DatabasePluginManager::Engine, parallel);
    dbmgr->LoadPluginsNow();
    if (PAR_Rank() == 0)
        cerr << endl; // whitespace after some expected plugin loading errors

    if (argc < 4)
    {
        UsageAndExit(dbmgr, argv[0]);
    }

    string assumedFormat = "";
    bool noOptions = false;
    bool doClean = false;
    bool disableMIR = false;
    bool disableExpressions = false;
    vector<string> vars;
    int target_chunks = -1;
    bool outputZonal = false;
    long long target_zones = -1;
    //EngineDatabasePluginInfo *edpir = NULL;
    if (argc > 4)
    {
        for (int i = 4 ; i < argc ; i++)
        {
            if (strcmp(argv[i], "-clean") == 0)
                doClean = true;
            else if (strcmp(argv[i], "-nomir") == 0)
                disableMIR = true;
            else if (strcmp(argv[i], "-noexpr") == 0)
                disableExpressions = true;
            else if (strcmp(argv[i], "-variable") == 0)
            {
                if ((i+1) >= argc)
                    UsageAndExit(dbmgr, argv[0]);
                i++;
                vars.push_back(argv[i]);
            }
            else if (strcmp(argv[i], "-output_zonal") == 0)
            {
                outputZonal = true;
            }
            else if (strcmp(argv[i], "-target_chunks") == 0)
            {
                if ((i+1) >= argc)
                    UsageAndExit(dbmgr, argv[0]);
                i++;
                target_chunks = atoi(argv[i]);
            }
            else if (strcmp(argv[i], "-target_zones") == 0)
            {
                if ((i+1) >= argc)
                    UsageAndExit(dbmgr, argv[0]);
                i++;
                target_zones = 0;
                int nchars = strlen(argv[i]);
                for (int j = 0 ; j < nchars ; j++)
                {
                    if (isdigit(argv[i][j]))
                    {
                        target_zones *= 10;
                        target_zones += argv[i][j] - '0';
                    }
                }
            }
            else if (strcmp(argv[i], "-assume_format") == 0)
            {
                if ((i+1) >= argc)
                    UsageAndExit(dbmgr, argv[0]);
                i++;

                assumedFormat = argv[i];
            }
            else if (strcmp(argv[i], "-no_options") == 0)
                noOptions = true;

            else
            {
                //Ignore....
            }
        }
    }


    //
    // Handle read options if we need to.
    //
    HandleReadOptions(noOptions, dbmgr, argv[0], assumedFormat);

    //
    // Instantiate the database.
    //
    avtDatabase *db = NULL;
    vector<string> pluginList;
    TRY
    {
        if (strstr(argv[1], ".visit") != NULL)
            db = avtDatabaseFactory::VisitFile(dbmgr, argv[1], 0, pluginList);
        else
            db = avtDatabaseFactory::FileList(dbmgr, argv+1, 1, 0, pluginList);
    }
    CATCHALL
    {
        if (PAR_Rank() == 0)
            cerr << "The file " << argv[1] << " does not exist or could "
                 << "not be opened." << endl;
        PAR_Exit();
        exit(EXIT_FAILURE);
    }
    ENDTRY

    if (db == NULL)
    {
        if (PAR_Rank() == 0)
            cerr << "Could not open file " << argv[1] << ".  Tried using plugins ";
        for (size_t i = 0 ; i < pluginList.size() ; i++)
        {
            if (PAR_Rank() == 0)
            {
                cerr << pluginList[i];
                if (i != pluginList.size()-1)
                    cerr << ", ";
                else
                    cerr << endl;
            }
        }
    }

    //
    // Set the write options as the default.
    // Walk through the write options and have the user iterate over them
    // from the command line. [MCM] I believe predicating ONLY the FillOptions...
    // call on value of noOptions permits write options to flow from config
    // file settings correctly.
    //
    EngineDatabasePluginInfo *edpi = GetPluginInfo(dbmgr, argv[0], argv[3]);
    DBOptionsAttributes *opts = edpi->GetWriteOptions();
    if (!noOptions)
        FillOptionsFromCommandline(opts);
    edpi->SetWriteOptions(opts);

    //
    // Make sure this format has a writer.
    //
    avtDatabaseWriter *wrtr = edpi->GetWriter();
    if (wrtr == NULL)
    {
        if (PAR_Rank() == 0)
            cerr << "No writer defined for file type " << argv[3] << ".\n"
                 << "Please see a VisIt developer." << endl;
        UsageAndExit(dbmgr, argv[0]);
    }
    if (doClean)
        wrtr->SetShouldAlwaysDoMIR(doClean);
    if (disableMIR)
        wrtr->SetShouldNeverDoMIR(disableMIR);
    if (disableExpressions)
        wrtr->SetShouldNeverDoExpressions(disableExpressions);
    if (target_zones > 0)
    {
        bool canDoIt = wrtr->SetTargetZones(target_zones);
        if (!canDoIt)
        {
            if (PAR_Rank() == 0)
                cerr << "This writer does not support the \"-target_zones\" option"
                     << endl;
            UsageAndExit(dbmgr, argv[0]);
        }
    }
    if (target_chunks > 0)
    {
        bool canDoIt = wrtr->SetTargetChunks(target_chunks);
        if (!canDoIt)
        {
            if (PAR_Rank() == 0)
                cerr << "This writer does not support the \"-target_chunks\" "
                     << "option" << endl;
            UsageAndExit(dbmgr, argv[0]);
        }
    }
    if (outputZonal)
    {
        bool canDoIt = wrtr->SetOutputZonal(outputZonal);
        if (!canDoIt)
        {
            if (PAR_Rank() == 0)
                cerr << "This writer does not support the \"-output_zonal\" "
                     << "option" << endl;
            UsageAndExit(dbmgr, argv[0]);
        }
    }

    //
    // Figure out which mesh to operate on.
    // Assume MetaData for timestep 0 is sufficient for what we need here
    //
    const avtDatabaseMetaData *md = db->GetMetaData(0);
    //const avtMeshMetaData *mmd = NULL;
    string meshname = "";
    if (md->GetNumMeshes() >= 1)
    {
        if (md->GetNumMeshes() > 1)
        {
            if (PAR_Rank() == 0)
            {
                cerr << "There are multiple meshes in the file.  This program can "
                     << "only\nhandle one mesh at a time.  I am using mesh: ";
                cerr << md->GetMesh(0)->name << endl;
            }
        }
        meshname = md->GetMesh(0)->name;
    }
    else if (md->GetNumMeshes() < 1)
    {
        if (md->GetNumCurves() > 0)
        {
            if (PAR_Rank() == 0)
                cerr << "Cannot find any meshes, converting curves." << endl;
            meshname = md->GetCurve(0)->name;
        }
        else
        {
            if (PAR_Rank() == 0)
                cerr << "Cannot find any valid meshes or curves to convert.\n"
                     << "Giving up." << endl;
            PAR_Exit();
            exit(EXIT_FAILURE);
        }
    }

#ifndef DISABLE_EXPRESSIONS
    //
    // Hook up the expressions we have associated with the database, so
    // we can get those as well.
    //
    Parser *p = new ExprParser(new avtExprNodeFactory());
    ParsingExprList *l = new ParsingExprList(p);
    ExpressionList *list = l->GetList();
    for (i = 0 ; i < md->GetNumberOfExpressions() ; i++)
    {
        const Expression *e = md->GetExpression(i);
        list->AddExpressions(*e);
    }
#endif

    if (PAR_Rank() == 0)
        cerr << "Operating on " << md->GetNumStates() << " timestep(s)." << endl;
    for (i = 0 ; i < md->GetNumStates() ; i++)
    {
         avtDataObject_p dob = db->GetOutput(meshname.c_str(), i);
#ifndef DISABLE_EXPRESSIONS
         avtExpressionEvaluatorFilter eef;
         eef.SetInput(dob);
         dob = eef.GetOutput();
#endif
         wrtr->SetInput(dob);

         char filename[1024];
         if (strstr(argv[2], "%") != NULL)
             sprintf(filename, argv[2], i);
         else if (md->GetNumStates() == 1)
             strcpy(filename, argv[2]);
         else
             sprintf(filename, "%04d.%s", i, argv[2]);
        
         TRY
         {
             if (vars.size())
             {
                 wrtr->Write("", filename, md, vars, false);
             }
             else
             {
                 wrtr->Write(filename, md);
             } 
         }
         CATCH2(VisItException, e)
         {
             if (PAR_Rank() == 0)
             {
                 cerr << "Error encountered.  Unable to write files." << endl;
                 cerr << "Error was: " << endl;
                 cerr << e.Message() << endl;
             }
             break;
         }
         ENDTRY
    }

    delete dbmgr;

#ifdef PARALLEL
    PAR_Exit();
#endif

    return 0;
}
コード例 #11
0
CommandResult ExpressionInterpreter::interpretCommand(string userInput)
{
    CommandResult result = CommandSuccess;
    string text;
    stringstream ss;
    ss << userInput;

    ExpressionList currentState;
    currentState.push_back(mpRoot);
    ExpressionList nextState;

    while (result == CommandSuccess && !ss.eof())
    {
        ss >> text;
        transform(text.begin(), text.end(), text.begin(), ::tolower);

        ExpressionList::const_iterator iter = currentState.begin();
        ExpressionList::const_iterator end = currentState.end();
        for (; iter != end; ++iter)
        {
            Expression* expr = *iter;
            ExpressionList exprNextList = expr->getNextExpressionClosure(text);
            nextState.splice(nextState.end(), exprNextList);
        }

        if (nextState.size() > 0)
        {
            currentState = nextState;
            nextState.clear();
        }
        else
        {
            mErrorText = "'" + text + "' not recognized.";
            result = CommandInvalid;
        }
    }

    //remove impossible expressions in the final state before checking for ambiguity
    nextState.clear();
    ExpressionList::const_iterator iter = currentState.begin();
    ExpressionList::const_iterator end = currentState.end();
    for (; iter != end; ++iter)
    {
        Expression* expr = *iter;
        if (expr->isExecutable())
        {
            nextState.push_back(expr);
        }
        else
        {
            ExpressionList children = expr->getNextExpressions();

            bool flag = false;

            ExpressionList::const_iterator iter = children.begin();
            ExpressionList::const_iterator end = children.end();
            for (; iter != end; ++iter)
            {
                if ((*iter)->getName()[0] == '[')
                {
                    flag = true;
                }
            }

            if (flag || children.size() == 0)
            {
                nextState.push_back(expr);
            }
        }
    }

    currentState = nextState;

    if (currentState.size() != 1)
    {
        mErrorText = "'" + text + "' ambiguous or incomplete.";
        result = CommandInvalid;
    }

    //run command if executable and non-ambiguous
    if (result == CommandSuccess)
    {
        Expression* expr = *(currentState.begin());

        ExpressionList executables = expr->getClosureExecutables(false);
        if (executables.size() == 1)
        {
            ilmErrorTypes initResult = ilm_init();
            if (ILM_SUCCESS != initResult)
            {
                mErrorText = ILM_ERROR_STRING(initResult);
                result = CommandExecutionFailed;
            }
            else
            {
                Expression* exec = executables.front();
                exec->execute();
                ilm_commitChanges();
                ilm_destroy();
            }
        }
        else if (executables.size() == 0)
        {
            mErrorText = "command is incomplete.";
            result = CommandIncomplete;
        }
        else
        {
            mErrorText = "command is ambiguous.";
            result = CommandIncomplete;
        }
    }

    return result;
}
コード例 #12
0
ファイル: ast.cpp プロジェクト: Dymanik/LenguajesII
 void add(NArray* arr){
     values.push_back(arr);
 }