Search in sources :

Example 1 with VarOrFieldDecl

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

the class JavaGeneratorHelper method isLocalVarUse.

/**
 * checks if astNode is a use of a local variable or parameter
 */
private static boolean isLocalVarUse(ASTNode<?> astNode) {
    if (astNode instanceof VarUse) {
        VarUse v = (VarUse) astNode;
        VarOrFieldDecl decl = v.getDecl();
        if (decl instanceof VarDecl || decl instanceof ParamDecl) {
            return !(decl.getParent() instanceof LetExp);
        }
    }
    return false;
}
Also used : TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(abs.frontend.ast.VarOrFieldDecl) VarDecl(abs.frontend.ast.VarDecl) ParamDecl(abs.frontend.ast.ParamDecl) LetExp(abs.frontend.ast.LetExp) VarUse(abs.frontend.ast.VarUse)

Example 2 with VarOrFieldDecl

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

the class FinalAnnotationTypeExtension method checkAssignStmt.

@Override
public void checkAssignStmt(AssignStmt s) {
    VarOrFieldDecl decl = s.getVar().getDecl();
    if (decl instanceof TypedVarOrFieldDecl) {
        TypedVarOrFieldDecl d = (TypedVarOrFieldDecl) decl;
        // Not sure if this code will encounter delta bodies:
        if (d.isFinal()) {
            String name = d.getName();
            boolean isField = (d instanceof FieldDecl);
            String kind = isField ? "field" : "variable";
            add(new TypeError(s, ErrorMessage.ASSIGN_TO_FINAL, kind, name));
        }
    } else {
    // It's a PatternVarDecl.  Assume these are never final.
    }
}
Also used : VarOrFieldDecl(abs.frontend.ast.VarOrFieldDecl) FieldDecl(abs.frontend.ast.FieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(abs.frontend.ast.VarOrFieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) TypedVarOrFieldDecl(abs.frontend.ast.TypedVarOrFieldDecl) TypeError(abs.frontend.analyser.TypeError)

Aggregations

TypedVarOrFieldDecl (abs.frontend.ast.TypedVarOrFieldDecl)2 VarOrFieldDecl (abs.frontend.ast.VarOrFieldDecl)2 TypeError (abs.frontend.analyser.TypeError)1 FieldDecl (abs.frontend.ast.FieldDecl)1 LetExp (abs.frontend.ast.LetExp)1 ParamDecl (abs.frontend.ast.ParamDecl)1 VarDecl (abs.frontend.ast.VarDecl)1 VarUse (abs.frontend.ast.VarUse)1