Search in sources :

Example 61 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Check method checkNonCyclicElementsInternal.

void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) {
    if ((tsym.flags_field & ACYCLIC_ANN) != 0)
        return;
    if ((tsym.flags_field & LOCKED) != 0) {
        log.error(pos, "cyclic.annotation.element");
        return;
    }
    try {
        tsym.flags_field |= LOCKED;
        for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
            Symbol s = e.sym;
            if (s.kind != Kinds.MTH)
                continue;
            checkAnnotationResType(pos, ((MethodSymbol) s).type.getReturnType());
        }
    } finally {
        tsym.flags_field &= ~LOCKED;
        tsym.flags_field |= ACYCLIC_ANN;
    }
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Example 62 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Check method checkCyclicConstructors.

/* *************************************************************************
 * Check for cycles in the constructor call graph.
 **************************************************************************/
/** Check for cycles in the graph of constructors calling other
     *  constructors.
     */
void checkCyclicConstructors(JCClassDecl tree) {
    Map<Symbol, Symbol> callMap = new HashMap<Symbol, Symbol>();
    // enter each constructor this-call into the map
    for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
        JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head);
        if (app == null)
            continue;
        JCMethodDecl meth = (JCMethodDecl) l.head;
        if (TreeInfo.name(app.meth) == names._this) {
            callMap.put(meth.sym, TreeInfo.symbol(app.meth));
        } else {
            meth.sym.flags_field |= ACYCLIC;
        }
    }
    // Check for cycles in the map
    Symbol[] ctors = new Symbol[0];
    ctors = callMap.keySet().toArray(ctors);
    for (Symbol caller : ctors) {
        checkCyclicConstructor(tree, caller, callMap);
    }
}
Also used : Symbol(com.sun.tools.javac.code.Symbol) JCTree(com.sun.tools.javac.tree.JCTree)

Example 63 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Lower method addEnumFieldNameMethod.

private MethodSymbol addEnumFieldNameMethod(JCClassDecl cdef, VarSymbol nameSymbol) {
    // Add the accessor methods for name
    Symbol nameSym = lookupMethod(cdef.pos(), names._name, cdef.type, List.<Type>nil());
    Assert.check(nameSym instanceof MethodSymbol);
    JCStatement ret = make.Return(make.Ident(nameSymbol));
    cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol) nameSym, make.Block(0L, List.of(ret))));
    return (MethodSymbol) nameSym;
}
Also used : Symbol(com.sun.tools.javac.code.Symbol)

Example 64 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Lower method accessSymbol.

/** Return access symbol for a private or protected symbol from an inner class.
     *  @param sym        The accessed private symbol.
     *  @param tree       The accessing tree.
     *  @param enclOp     The closest enclosing operation node of tree,
     *                    null if tree is not a subtree of an operation.
     *  @param protAccess Is access to a protected symbol in another
     *                    package?
     *  @param refSuper   Is access via a (qualified) C.super?
     */
MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp, boolean protAccess, boolean refSuper) {
    ClassSymbol accOwner = refSuper && protAccess ? // access symbol on T.
    (ClassSymbol) ((JCFieldAccess) tree).selected.type.tsym : // class which is a subclass of the symbol's owner.
    accessClass(sym, protAccess, tree);
    Symbol vsym = sym;
    if (sym.owner != accOwner) {
        vsym = sym.clone(accOwner);
        actualSymbols.put(vsym, sym);
    }
    // The access number of the access method.
    Integer anum = accessNums.get(vsym);
    if (anum == null) {
        anum = accessed.length();
        accessNums.put(vsym, anum);
        accessSyms.put(vsym, new MethodSymbol[NCODES]);
        accessed.append(vsym);
    // System.out.println("accessing " + vsym + " in " + vsym.location());
    }
    // The access code of the access method.
    int acode;
    // The argument types of the access method.
    List<Type> argtypes;
    // The result type of the access method.
    Type restype;
    // The thrown exceptions of the access method.
    List<Type> thrown;
    switch(vsym.kind) {
        case VAR:
            acode = accessCode(tree, enclOp);
            if (acode >= FIRSTASGOPcode) {
                OperatorSymbol operator = binaryAccessOperator(acode);
                if (operator.opcode == string_add)
                    argtypes = List.of(syms.objectType);
                else
                    argtypes = operator.type.getParameterTypes().tail;
            } else if (acode == ASSIGNcode)
                argtypes = List.of(vsym.erasure(types));
            else
                argtypes = List.nil();
            restype = vsym.erasure(types);
            thrown = List.nil();
            break;
        case MTH:
            acode = DEREFcode;
            argtypes = vsym.erasure(types).getParameterTypes();
            restype = vsym.erasure(types).getReturnType();
            thrown = vsym.type.getThrownTypes();
            break;
        default:
            throw new AssertionError();
    }
    // making it odd.
    if (protAccess && refSuper)
        acode++;
    // containing the access method.
    if ((vsym.flags() & STATIC) == 0) {
        argtypes = argtypes.prepend(vsym.owner.erasure(types));
    }
    MethodSymbol[] accessors = accessSyms.get(vsym);
    MethodSymbol accessor = accessors[acode];
    if (accessor == null) {
        accessor = new MethodSymbol(STATIC | SYNTHETIC, accessName(anum.intValue(), acode), new MethodType(argtypes, restype, thrown, syms.methodClass), accOwner);
        enterSynthetic(tree.pos(), accessor, accOwner.members());
        accessors[acode] = accessor;
    }
    return accessor;
}
Also used : Type(com.sun.tools.javac.code.Type) Symbol(com.sun.tools.javac.code.Symbol)

Example 65 with Symbol

use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.

the class Lower method visitMethodDef.

public void visitMethodDef(JCMethodDecl tree) {
    if (tree.name == names.init && (currentClass.flags_field & ENUM) != 0) {
        // Add "String $enum$name, int $enum$ordinal" to the beginning of the
        // argument list for each constructor of an enum.
        JCVariableDecl nameParam = make_at(tree.pos()).Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "name"), syms.stringType, tree.sym);
        nameParam.mods.flags |= SYNTHETIC;
        nameParam.sym.flags_field |= SYNTHETIC;
        JCVariableDecl ordParam = make.Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "ordinal"), syms.intType, tree.sym);
        ordParam.mods.flags |= SYNTHETIC;
        ordParam.sym.flags_field |= SYNTHETIC;
        tree.params = tree.params.prepend(ordParam).prepend(nameParam);
        MethodSymbol m = tree.sym;
        Type olderasure = m.erasure(types);
        m.erasure_field = new MethodType(olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType), olderasure.getReturnType(), olderasure.getThrownTypes(), syms.methodClass);
        if (target.compilerBootstrap(m.owner)) {
            // Initialize synthetic name field
            Symbol nameVarSym = lookupSynthetic(names.fromString("$name"), tree.sym.owner.members());
            JCIdent nameIdent = make.Ident(nameParam.sym);
            JCIdent id1 = make.Ident(nameVarSym);
            JCAssign newAssign = make.Assign(id1, nameIdent);
            newAssign.type = id1.type;
            JCExpressionStatement nameAssign = make.Exec(newAssign);
            nameAssign.type = id1.type;
            tree.body.stats = tree.body.stats.prepend(nameAssign);
            // Initialize synthetic ordinal field
            Symbol ordinalVarSym = lookupSynthetic(names.fromString("$ordinal"), tree.sym.owner.members());
            JCIdent ordIdent = make.Ident(ordParam.sym);
            id1 = make.Ident(ordinalVarSym);
            newAssign = make.Assign(id1, ordIdent);
            newAssign.type = id1.type;
            JCExpressionStatement ordinalAssign = make.Exec(newAssign);
            ordinalAssign.type = id1.type;
            tree.body.stats = tree.body.stats.prepend(ordinalAssign);
        }
    }
    JCMethodDecl prevMethodDef = currentMethodDef;
    MethodSymbol prevMethodSym = currentMethodSym;
    try {
        currentMethodDef = tree;
        currentMethodSym = tree.sym;
        visitMethodDefInternal(tree);
    } finally {
        currentMethodDef = prevMethodDef;
        currentMethodSym = prevMethodSym;
    }
}
Also used : Type(com.sun.tools.javac.code.Type) Symbol(com.sun.tools.javac.code.Symbol)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)195 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)56 Type (com.sun.tools.javac.code.Type)54 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)53 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)45 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)36 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)29 JCTree (com.sun.tools.javac.tree.JCTree)28 ClassType (com.sun.tools.javac.code.Type.ClassType)18 Tree (com.sun.source.tree.Tree)17 ExpressionTree (com.sun.source.tree.ExpressionTree)15 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)15 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)15 ClassTree (com.sun.source.tree.ClassTree)14 MethodTree (com.sun.source.tree.MethodTree)14 Name (com.sun.tools.javac.util.Name)14 IdentifierTree (com.sun.source.tree.IdentifierTree)13 ArrayType (com.sun.tools.javac.code.Type.ArrayType)12 MethodType (com.sun.tools.javac.code.Type.MethodType)12 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)12