Пример #1
0
static rc
testFunctionCall(void)
{
    FunctionCall *a;
    Constant *c;

    a = createFunctionCall ("f", LIST_MAKE(createConstInt(1), createConstInt(2)));
    c = (Constant *) getNthOfListP(a->args, 0);

    ASSERT_EQUALS_INT(1, INT_VALUE(c), "first arg is 1 const");
    ASSERT_EQUALS_STRING("f", a->functionname, "function name is f");

    return PASS;
}
Пример #2
0
nsresult
txExprParser::createFilterOrStep(txExprLexer& lexer, txIParseContext* aContext,
                                 Expr** aResult)
{
    *aResult = nullptr;

    nsresult rv = NS_OK;
    Token* tok = lexer.peek();

    nsAutoPtr<Expr> expr;
    switch (tok->mType) {
        case Token::FUNCTION_NAME_AND_PAREN:
            rv = createFunctionCall(lexer, aContext, getter_Transfers(expr));
            NS_ENSURE_SUCCESS(rv, rv);
            break;
        case Token::VAR_REFERENCE :
            lexer.nextToken();
            {
                nsCOMPtr<nsIAtom> prefix, lName;
                int32_t nspace;
                nsresult rv = resolveQName(tok->Value(), getter_AddRefs(prefix),
                                           aContext, getter_AddRefs(lName),
                                           nspace);
                NS_ENSURE_SUCCESS(rv, rv);
                expr = new VariableRefExpr(prefix, lName, nspace);
            }
            break;
        case Token::L_PAREN:
            lexer.nextToken();
            rv = createExpr(lexer, aContext, getter_Transfers(expr));
            NS_ENSURE_SUCCESS(rv, rv);

            if (lexer.peek()->mType != Token::R_PAREN) {
                return NS_ERROR_XPATH_PAREN_EXPECTED;
            }
            lexer.nextToken();
            break;
        case Token::LITERAL :
            lexer.nextToken();
            expr = new txLiteralExpr(tok->Value());
            break;
        case Token::NUMBER:
        {
            lexer.nextToken();
            expr = new txLiteralExpr(txDouble::toDouble(tok->Value()));
            break;
        }
        default:
            return createLocationStep(lexer, aContext, aResult);
    }

    if (lexer.peek()->mType == Token::L_BRACKET) {
        nsAutoPtr<FilterExpr> filterExpr(new FilterExpr(expr));

        expr.forget();

        //-- handle predicates
        rv = parsePredicates(filterExpr, lexer, aContext);
        NS_ENSURE_SUCCESS(rv, rv);
        expr = filterExpr.forget();
    }

    *aResult = expr.forget();
    return NS_OK;
}
Пример #3
0
TAC_NODE* generateTacCode(ASTREE* syntaxtree) {
	int i;

	TAC_NODE* code[MAX_SONS];

	for(i=0; i < MAX_SONS; i++) {
		code[i] = NULL;
	}

	if(syntaxtree == NULL) return NULL;

	for (i=0; i < MAX_SONS; i++) {
		code[i] = generateTacCode(syntaxtree->son[i]);
	}
		
	switch (syntaxtree->type) {
		 case AST_PROGRAMA:
		 	return code[0];
		 case AST_DECLARACOES:
		 	return joinTacs(code[0], code[1]);
		 case AST_VARIAVEL:
			if(code[2]!=NULL) {
			 	return createTacNode(TAC_DECLARACAO_VARIAVEL, code[0]->result, code[2]->result, NULL);
			}
			else {
				return createTacNode(TAC_SYMBOL, code[0]->result, NULL, NULL);
			}
		 case AST_VETOR_VAZIO:
		 	return createTacNode(TAC_DECLARACAO_VETOR_VAZIO, code[0]->result, code[2]->result, NULL);
		 case AST_VETOR:
		 	return joinTacs(createTacNode(TAC_DECLARACAO_VETOR, code[0]->result, code[2]->result, NULL), initializeVector(revertTac(code[3]),code[0]->result,0));
		 case AST_INI_VETOR:
		 	return joinTacs(code[0], code[1]);
		 case AST_LISTA_LITERAIS:
		 	return joinTacs(code[0], code[1]);
		 case AST_FUNCAO:
		 	return createFunctionDeclaration(code[0]->result, code[2], code[3]);
		 case AST_PARAMETRO:
		 	return createTacNode(TAC_PARAMETRO, code[0]->result, code[1]->result, NULL);
		 case AST_LISTA_PARAMETRO:
		 	return joinTacs(code[0], code[1]);
		 case AST_COMANDOS:
		 	return joinTacs(code[0], code[1]);
		 case AST_BLOCO:
		 	return code[0];
		 case AST_LISTA_PARAM_CHAMADA:
			return joinTacs(code[0], code[1]);
		 case AST_ACESSO_VETOR:
		 	return createVectorRead(code[0]->result, code[1]);
		 case AST_CHAMADA_FUNCAO:
			return createFunctionCall(code[0]->result, code[1]);
		 case AST_EXPRESSAO_PARENTESES:
		 	return code[0];
		 case AST_OP_SOMA:
		 	return createTacOperation(TAC_OP_SOMA, code[0], code[1]);
		 case AST_OP_SUB:
		 	return createTacOperation(TAC_OP_SUB, code[0], code[1]);
		 case AST_OP_MUL:
			 return createTacOperation(TAC_OP_MUL, code[0], code[1]);
		 case AST_OP_DIV:
		 	return createTacOperation(TAC_OP_DIV, code[0], code[1]);
		 case AST_OP_MENOR:
		 	return createTacOperation(TAC_OP_MENOR, code[0], code[1]);
		 case AST_OP_MAIOR:
		 	return createTacOperation(TAC_OP_MAIOR, code[0], code[1]);
		 case AST_OP_LE:
		 	return createTacOperation(TAC_OP_LE, code[0], code[1]);
		 case AST_OP_GE:
		 	return createTacOperation(TAC_OP_GE, code[0], code[1]);
		 case AST_OP_EQ:
		 	return createTacOperation(TAC_OP_EQ, code[0], code[1]);
		 case AST_OP_NE:
		 	return createTacOperation(TAC_OP_NE, code[0], code[1]);
		 case AST_OP_AND:
		 	return createTacOperation(TAC_OP_AND, code[0], code[1]);
		 case AST_OP_OR:
		 	return createTacOperation(TAC_OP_OR, code[0], code[1]);
		 case AST_ATRIBUICAO:
		 	return joinTacs(code[1], createTacNode(TAC_ATRIBUICAO, code[0]->result, resultAtribuicao(code[1])->result, NULL));
		 case AST_ATRIBUICAO_VETOR:
		 	return createAssignVector(code[0]->result, resultAtribuicao(code[1]), resultAtribuicao(code[2]));
		 case AST_IF:
			return createIF(code[0],code[1]);
		 case AST_IF_ELSE:
			return createIF_ELSE(code[0],code[1],code[2]);
		 case AST_WHILE:
			return createWHILE(code[0], code[1]);
		 case AST_INPUT:
			return createInput(revertTac(code[0]));
		 case AST_LISTA_VARIAVEIS:
			return joinTacs(code[0], code[1]);
		 case AST_OUTPUT:
			return createOutput(revertTac(code[0]));
		 case AST_LISTA_ELEM_EXP:
			return joinTacs(code[0], code[1]);
		 case AST_LISTA_ELEM_STRING:
			return joinTacs(createTacNode(TAC_STRING, syntaxtree->symbol, NULL, NULL), code[0]);
		 case AST_RETURN:
			return joinTacs(code[0], createTacNode(TAC_RETURN, code[0]->result, NULL, NULL));
		 case AST_KW_INT:
		 	return createTacNode(TAC_KW_INT, syntaxtree->symbol, NULL, NULL);
		 case AST_KW_BOOL:
		 	return createTacNode(TAC_KW_BOOL, syntaxtree->symbol, NULL, NULL);
		 case AST_KW_REAL:
		 	return createTacNode(TAC_KW_REAL, syntaxtree->symbol, NULL, NULL);
		 case AST_KW_CHAR:
		 	return createTacNode(TAC_KW_CHAR, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_INT:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_REAL:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_TRUE:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_FALSE:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_CHAR:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_LIT_STRING:
		 	return createTacNode(TAC_SYMBOL, syntaxtree->symbol, NULL, NULL);
		 case AST_COMANDO_VAZIO:
		 	return NULL;
		 case AST_SYMBOL_VAR:
		 	return createTacNode(TAC_SYMBOL_VAR, syntaxtree->symbol, NULL, NULL);
		 case AST_SYMBOL_VET:
		 	return createTacNode(TAC_SYMBOL_VET, syntaxtree->symbol, NULL, NULL);
		 case AST_SYMBOL_FUN:
		 	return createTacNode(TAC_SYMBOL_FUN, syntaxtree->symbol, NULL, NULL);
		 default:
		 	break;
	}
}