示例#1
0
	ProgramPtr Program::remEntryPoints(NodeManager& manager, const ProgramPtr& program, const ExpressionList& entryPoints) {
		ExpressionList list;
		for_each(program->getEntryPoints(), [&list, &entryPoints](const ExpressionPtr& cur) {
			if(!contains(entryPoints, cur, equal_target<ExpressionPtr>())) { list.push_back(cur); }
		});
		return manager.get(Program(list));
	}
示例#2
0
Call* MakeCall(string Name, uint16_t Magic)
{
    ExpressionList Args;
    Args.push_back(new Argument(Name, ARG_STRING));
    Argument* Arg = new Argument(Nsb::StringifyMagic(Magic), ARG_FUNCTION);
    return new Call(Arg, Args, Magic);
}
示例#3
0
    /**
     * Create a new field declaration with exactly one variable in it.
     * If the field is uninitialized, the initializer may be
     * <code>null</code>.
     *
     * @param  context  Context indicating what line and file this
     *                  field is created at
     * @param  type     Type of the field
     * @param  name     Name of the field
     * @param  init     Expression initializing the field, or
     *                  <code>null</code> if the field is uninitialized
     */
    FieldDecl(FEContext *context, Type *type, string name,
	      Expression *init) : FENode(context)
    {
	types = new TypeList;
	names = new NameList;
	inits = new ExpressionList;

	types->push_back(type);
	names->push_back(name);
	inits->push_back(init);
    }
示例#4
0
        NArray(std::string& s){
#ifdef DEBUG
            cout << "string param "<< s.size()<<endl;
            cout << "string param "<< s<<endl;
#endif
            for(int i=0; i<s.size();i++){
                values.push_back(new NChar(s[i]));
            }
#ifdef DEBUG
            cout << "constrc string "<< values.size()<<endl;
#endif
        }
示例#5
0
 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;
     }
   }
 }
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;
}
示例#7
0
 void add(NArray* arr){
     values.push_back(arr);
 }