Search in sources :

Example 16 with FunctionDecl

use of abs.frontend.ast.FunctionDecl in project abstools by abstools.

the class PartialFunctionTest method assertHasFunction.

private FunctionDecl assertHasFunction(Model model, String regex) {
    FunctionDecl result = getFunction(model, Pattern.compile(regex));
    String errorMessage = "No expanded function with name " + regex + " created" + " (functions: " + getFunctions(model) + ")";
    assertNotNull(errorMessage, result);
    Decl decl = model.lookup(new KindedName(Kind.FUN, result.getName()));
    assertFalse("Could not lookup function " + result.getName(), decl.isUnknown());
    return result;
}
Also used : PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) KindedName(abs.frontend.typechecker.KindedName) PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) FunctionDecl(abs.frontend.ast.FunctionDecl)

Example 17 with FunctionDecl

use of abs.frontend.ast.FunctionDecl in project abstools by abstools.

the class JavaGeneratorHelper method generateBuiltInFnApp.

public static void generateBuiltInFnApp(PrintStream stream, FnApp app) {
    FunctionDecl d = (FunctionDecl) app.getDecl();
    String name = d.getName();
    if (!builtInFunctionExists(name)) {
        throw new NotImplementedYetException(app, "The built in function '" + name + "' is not implemented in the Java backend.");
    }
    // if builtin function returns a non-builtin type, cast the returned value to that type
    boolean returnsGeneratedDataType = !JavaBackend.isBuiltinDataType(app.getType());
    if (returnsGeneratedDataType)
        stream.print("((" + JavaBackend.getQualifiedString(app.getType()) + ")");
    stream.print(ABSBuiltInFunctions.class.getName() + "." + name);
    String firstArgs = null;
    if (Constants.isFunctionalBreakPointFunctionName(d.getModuleDecl().getName() + "." + name))
        firstArgs = generateFunctionalBreakPointArgs(app);
    generateArgs(stream, firstArgs, app.getParams(), d.getTypes());
    if (returnsGeneratedDataType)
        stream.print(")");
}
Also used : ABSBuiltInFunctions(abs.backend.java.lib.runtime.ABSBuiltInFunctions) NotImplementedYetException(abs.common.NotImplementedYetException) FunctionDecl(abs.frontend.ast.FunctionDecl)

Example 18 with FunctionDecl

use of abs.frontend.ast.FunctionDecl in project abstools by abstools.

the class AnnotationUtil method annotateCall.

/**
 * <p>Annotates the parent Statement or Function node with an ExpansionCall annotation.</p>
 *
 * <p>If said node already has an annotation with the ExpansionCall type, the expansionIndex will be added to the
 * existing annotation.</p>
 *
 * @param call the call to use as a starting point to look for a Stmt or FunctionDecl parent
 * @param expansionId the ID of the called Expansion
 * @throws IllegalArgumentException if there is no Stmt or FunctionDecl parent
 */
public static void annotateCall(FnApp call, int expansionId) {
    Stmt parent = call.closestParent(Stmt.class);
    if (parent == null) {
        FunctionDecl parentFunction = call.closestParent(FunctionDecl.class);
        if (parentFunction == null) {
            throw new IllegalArgumentException("Function call has no parent Statement or FunctionDecl: " + call);
        }
        addToAnnotations(parentFunction.getAnnotations(), expansionCallType(), expansionId);
    } else {
        addToAnnotations(parent.getAnnotations(), expansionCallType(), expansionId);
    }
}
Also used : Stmt(abs.frontend.ast.Stmt) FunctionDecl(abs.frontend.ast.FunctionDecl)

Aggregations

FunctionDecl (abs.frontend.ast.FunctionDecl)18 Model (abs.frontend.ast.Model)12 Test (org.junit.Test)12 FrontendTest (abs.frontend.FrontendTest)10 PureExp (abs.frontend.ast.PureExp)8 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)6 Decl (abs.frontend.ast.Decl)3 FnApp (abs.frontend.ast.FnApp)3 FunctionDef (abs.frontend.ast.FunctionDef)3 IntLiteral (abs.frontend.ast.IntLiteral)2 Stmt (abs.frontend.ast.Stmt)2 ABSBuiltInFunctions (abs.backend.java.lib.runtime.ABSBuiltInFunctions)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 NotImplementedYetException (abs.common.NotImplementedYetException)1 TypeError (abs.frontend.analyser.TypeError)1 ASTNode (abs.frontend.ast.ASTNode)1 Access (abs.frontend.ast.Access)1 AddExp (abs.frontend.ast.AddExp)1 ClassDecl (abs.frontend.ast.ClassDecl)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1