示例#1
0
void BuildASTVisitor::visitItem( ItemAst *node )
{
    if( node->functionArguments )
    {
        FunctionCallAST* call = new FunctionCallAST( aststack.top() );
        ValueAST* val = new ValueAST();
        val->setValue( getTokenString( node->id ) );
        QPair<qint64,qint64> line_col = getTokenLineAndColumn(node->id);
        val->setLine( line_col.first );
        val->setColumn( line_col.second );
        call->setFunctionName( val );
        OrAST* orast = stackTop<OrAST>();
        orast->addScope( call );
        aststack.push( call );
        DefaultVisitor::visitItem( node );
        aststack.pop();
    }else
    {
        SimpleScopeAST* simple = new SimpleScopeAST( aststack.top() );
        ValueAST* val = new ValueAST();
        val->setValue( getTokenString( node->id ) );
        QPair<qint64,qint64> line_col = getTokenLineAndColumn(node->id);
        val->setLine( line_col.first );
        val->setColumn( line_col.second );
        simple->setScopeName( val );
        OrAST* orast = stackTop<OrAST>();
        orast->addScope( simple );
        DefaultVisitor::visitItem( node );
    }
}
示例#2
0
    bool parseStatus(const std::string& message, LibreOfficeKitDocumentType& type, int& nParts, int& currentPart, int& width, int& height)
    {
        StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);

        assert(tokens.count() == 6);
        assert(tokens[0] == "status:");

        std::string typeString;
        if (!getTokenString(tokens[1], "type", typeString))
            return false;

        if (typeString == "text")
            type = LOK_DOCTYPE_TEXT;
        else if (typeString == "spreadsheet")
            type = LOK_DOCTYPE_SPREADSHEET;
        else if (typeString == "presentation")
            type = LOK_DOCTYPE_PRESENTATION;
        else if (typeString == "drawing")
            type = LOK_DOCTYPE_PRESENTATION;
        else if (typeString == "other")
            type = LOK_DOCTYPE_OTHER;
        else
            return false;

        if (!getTokenInteger(tokens[2], "parts", nParts) ||
            !getTokenInteger(tokens[3], "current", currentPart) ||
            !getTokenInteger(tokens[4], "width", width) ||
            !getTokenInteger(tokens[5], "height", height))
            return false;

        return true;
    }
示例#3
0
 bool getTokenString(const Poco::StringTokenizer& tokens, const std::string& name, std::string& value)
 {
     for (size_t i = 0; i < tokens.count(); i++)
     {
         if (getTokenString(tokens[i], name, value))
             return true;
     }
     return false;
 }
//**************************************************
// OperatorRecord::OperatorRecord
//**************************************************
OperatorRecord::OperatorRecord(Type theOperator) :
  Token(theOperator, 0, 0)
{
  if (theOperator != Type::PlusOp && theOperator != Type::MinusOp)
  {
    throw std::invalid_argument(
      "Illegal token type provided to OperatorRecord, " + getTokenString() +
      ", must be either PlusOp or MinusOp.");
  }
}
示例#5
0
void BuildASTVisitor::visitValue( ValueAst *node )
{
    AssignmentAST* assign = dynamic_cast<AssignmentAST*>( aststack.top() );
    if( assign )
    {
        ValueAST* value = new ValueAST( assign );
        value->setValue( getTokenString(node->value) );
        assign->addValue( value );
    }else
    {
        FunctionCallAST* call = stackTop<FunctionCallAST>();
        ValueAST* value = new ValueAST( call );
        value->setValue( getTokenString(node->value) );
        QPair<qint64,qint64> line_col = getTokenLineAndColumn(node->value);
        value->setLine( line_col.first );
        value->setColumn( line_col.second );
        call->addArgument( value );
    }
    DefaultVisitor::visitValue(node);
}
示例#6
0
void BuildASTVisitor::visitOp( OpAst *node )
{
    AssignmentAST* assign = stackTop<AssignmentAST>();
    ValueAST* val = new ValueAST();
    val->setValue( getTokenString( node->optoken ) );
    QPair<qint64,qint64> line_col = getTokenLineAndColumn( node->optoken );
    val->setLine( line_col.first );
    val->setColumn( line_col.second );
    assign->setOp( val );
    DefaultVisitor::visitOp(node);
}
示例#7
0
    inline bool getTokenString(const std::vector<std::string>& tokens,
                               const std::string& name,
                               std::string& value)
    {
        for (const auto& token : tokens)
        {
            if (getTokenString(token, name, value))
            {
                return true;
            }
        }

        return false;
    }
示例#8
0
void BuildASTVisitor::visitStatement( StatementAst *node )
{
    DefaultVisitor::visitStatement(node);
    if( !node->isNewline )
    {
        StatementAST* stmt = stackPop<StatementAST>();
        ValueAST* val = new ValueAST();
        val->setValue( getTokenString( node->id ) );
        QPair<qint64,qint64> line_col = getTokenLineAndColumn( node->id );
        val->setLine( line_col.first );
        val->setColumn( line_col.second );
        if( node->isExclam )
        {
            val->setValue( '!'+val->value() );
        }
        stmt->setIdentifier( val );
        ScopeBodyAST* scope = stackTop<ScopeBodyAST>();
        scope->addStatement(stmt);
    }
}
示例#9
0
// =============================================================================
//
// Try to parse an expression symbol (i.e. an OPER_erator or OPER_erand or a colon)
// from the lexer.
//
ExpressionSymbol* Expression::parseSymbol()
{
	int pos = m_lexer->position();
	ExpressionValue* op = null;

	if (m_lexer->next (TK_Colon))
		return new ExpressionColon;

	// Check for OPER_erator
	for (const OperatorInfo& op : g_Operators)
		if (m_lexer->next (op.token))
			return new ExpressionOperator ((ExpressionOperatorType) (&op - &g_Operators[0]));

	// Check sub-expression
	if (m_lexer->next (TK_ParenStart))
	{
		Expression expr (m_parser, m_lexer, m_type);
		m_lexer->mustGetNext (TK_ParenEnd);
		return expr.getResult()->clone();
	}

	op = new ExpressionValue (m_type);

	// Check function
	if (CommandInfo* comm = findCommandByName (m_lexer->peekNextString()))
	{
		m_lexer->skip();

		if (m_type != TYPE_Unknown && comm->returnvalue != m_type)
			error ("%1 returns an incompatible data type", comm->name);

		op->setBuffer (m_parser->parseCommand (comm));
		return op;
	}

	// Check for variables
	if (m_lexer->next (TK_DollarSign))
	{
		m_lexer->mustGetNext (TK_Symbol);
		Variable* var = m_parser->findVariable (getTokenString());

		if (var == null)
			error ("unknown variable %1", getTokenString());

		if (var->type != m_type)
			error ("expression requires %1, variable $%2 is of type %3",
				dataTypeName (m_type), var->name, dataTypeName (var->type));

		if (var->isarray)
		{
			m_lexer->mustGetNext (TK_BracketStart);
			Expression expr (m_parser, m_lexer, TYPE_Int);
			expr.getResult()->convertToBuffer();
			DataBuffer* buf = expr.getResult()->buffer()->clone();
			buf->writeDWord (DH_PushGlobalArray);
			buf->writeDWord (var->index);
			op->setBuffer (buf);
			m_lexer->mustGetNext (TK_BracketEnd);
		}
		elif (var->writelevel == WRITE_Constexpr)
			op->setValue (var->value);
		else
		{