Example #1
0
/**
 * Unfolds formal parameters to real parameters in called function
 *
 * @param fParams: list of formal parameters
 * @param rParams: list of real parameters
 * @return: unfolded macro
 */
ASTForm* unfoldCall(ASTForm* form, IdentList* fParams, ASTList* rParams) {
	assert(form->kind == aCall);
	ASTForm_Call* callForm = static_cast<ASTForm_Call*>(form);

	PredLibEntry* called = predicateLib.lookup(callForm->n);
	ASTList* realParams = static_cast<ASTList*>(callForm->args->copy());

	for(AST** ast = realParams->begin(); ast != realParams->end(); ++ast) {
		(*ast) = (*ast)->unfoldMacro(fParams, rParams);
	}

	ASTForm* clonnedFormula = (called->ast)->clone();
	ASTForm* unfoldedFormula = _unfoldCore(clonnedFormula, called->formals, realParams);
	// Fixme: this is segfaulting something i guess? 
	//delete realParams;
	callForm->detach();
	//delete callForm;

	return unfoldedFormula;
}
QString MakefileHandler::resolveVariable( const QString& variable, AutoTools::ProjectAST* ast )
{
    if ( !ast )
        return variable;

    kdDebug(9020) << k_funcinfo << "attempting to resolve '" << variable << "'"<< endl;
    ASTList childList = ast->children();
    ASTList::iterator it( childList.begin() ), clEnd( childList.end() );
    for ( ; it != clEnd; ++it )
    {
        if ( ( *it )->nodeType() == AutoTools::AST::AssignmentAST )
        {
            AutoTools::AssignmentAST* assignment = static_cast<AutoTools::AssignmentAST*>( ( *it ) );
            if ( variable.find( assignment->scopedID ) != -1 )
            {
                kdDebug(9020) << k_funcinfo << "Resolving variable '" << variable << "' to '"
                              << assignment->values.join( QString::null ).stripWhiteSpace() << "'" << endl;
                return assignment->values.join( QString::null ).stripWhiteSpace();
            }
        }
    }

    return variable;
}