com.sun.tools.javac.code.Symbol.VarSymbol Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol.VarSymbol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Gen.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void visitIdent(JCIdent tree) {
    Symbol sym = tree.sym;
    if (tree.name == names._this || tree.name == names._super) {
        Item res = tree.name == names._this
            ? items.makeThisItem()
            : items.makeSuperItem();
        if (sym.kind == MTH) {
            // Generate code to address the constructor.
            res.load();
            res = items.makeMemberItem(sym, true);
        }
        result = res;
    } else if (sym.kind == VAR && sym.owner.kind == MTH) {
        result = items.makeLocalItem((VarSymbol)sym);
    } else if (isInvokeDynamic(sym)) {
        result = items.makeDynamicItem(sym);
    } else if ((sym.flags() & STATIC) != 0) {
        if (!isAccessSuper(env.enclMethod))
            sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeStaticItem(sym);
    } else {
        items.makeThisItem().load();
        sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeMemberItem(sym, (sym.flags() & PRIVATE) != 0);
    }
}
 
Example #2
Source File: LVTRanges.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String toString() {
    String result = "";
    for (Entry<MethodSymbol, Map<JCTree, List<VarSymbol>>> mainEntry: aliveRangeClosingTrees.entrySet()) {
        result += "Method: \n" + mainEntry.getKey().flatName() + "\n";
        int i = 1;
        for (Entry<JCTree, List<VarSymbol>> treeEntry: mainEntry.getValue().entrySet()) {
            result += "    Tree " + i + ": \n" + treeEntry.getKey().toString() + "\n";
            result += "        Variables closed:\n";
            for (VarSymbol var: treeEntry.getValue()) {
                result += "            " + var.toString();
            }
            result += "\n";
            i++;
        }
    }
    return result;
}
 
Example #3
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * determine the receiver of the method call - the receiver can
 * be a type qualifier, the synthetic receiver parameter or 'super'.
 */
private JCExpression expressionInvoke(VarSymbol rcvr) {
    JCExpression qualifier =
            (rcvr != null) ?
                makeReceiver(rcvr) :
                tree.getQualifierExpression();

    //create the qualifier expression
    JCFieldAccess select = make.Select(qualifier, tree.sym.name);
    select.sym = tree.sym;
    select.type = tree.sym.erasure(types);

    //create the method call expression
    JCExpression apply = make.Apply(List.<JCExpression>nil(), select,
            convertArgs(tree.sym, args.toList(), tree.varargsElement)).
            setType(tree.sym.erasure(types).getReturnType());

    apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType());
    setVarargsIfNeeded(apply, tree.varargsElement);
    return apply;
}
 
Example #4
Source File: Gen.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void visitIdent(JCIdent tree) {
    Symbol sym = tree.sym;
    if (tree.name == names._this || tree.name == names._super) {
        Item res = tree.name == names._this
            ? items.makeThisItem()
            : items.makeSuperItem();
        if (sym.kind == MTH) {
            // Generate code to address the constructor.
            res.load();
            res = items.makeMemberItem(sym, true);
        }
        result = res;
    } else if (sym.kind == VAR && sym.owner.kind == MTH) {
        result = items.makeLocalItem((VarSymbol)sym);
    } else if (isInvokeDynamic(sym)) {
        result = items.makeDynamicItem(sym);
    } else if ((sym.flags() & STATIC) != 0) {
        if (!isAccessSuper(env.enclMethod))
            sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeStaticItem(sym);
    } else {
        items.makeThisItem().load();
        sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeMemberItem(sym, (sym.flags() & PRIVATE) != 0);
    }
}
 
Example #5
Source File: SerializedForm.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void computeDefaultSerializableFields(DocEnv env,
                                              ClassSymbol def,
                                              ClassDocImpl cd) {
    for (Symbol sym : def.members().getSymbols(NON_RECURSIVE)) {
        if (sym != null && sym.kind == VAR) {
            VarSymbol f = (VarSymbol)sym;
            if ((f.flags() & Flags.STATIC) == 0 &&
                (f.flags() & Flags.TRANSIENT) == 0) {
                //### No modifier filtering applied here.
                FieldDocImpl fd = env.getFieldDoc(f);
                //### Add to beginning.
                //### Preserve order used by old 'javadoc'.
                fields.prepend(fd);
            }
        }
    }
}
 
Example #6
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * determine the receiver of the method call - the receiver can
 * be a type qualifier, the synthetic receiver parameter or 'super'.
 */
private JCExpression expressionInvoke(VarSymbol rcvr) {
    JCExpression qualifier =
            (rcvr != null) ?
                makeReceiver(rcvr) :
                tree.getQualifierExpression();

    //create the qualifier expression
    JCFieldAccess select = make.Select(qualifier, tree.sym.name);
    select.sym = tree.sym;
    select.type = tree.sym.erasure(types);

    //create the method call expression
    JCExpression apply = make.Apply(List.<JCExpression>nil(), select,
            convertArgs(tree.sym, args.toList(), tree.varargsElement)).
            setType(tree.sym.erasure(types).getReturnType());

    apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType());
    setVarargsIfNeeded(apply, tree.varargsElement);
    return apply;
}
 
Example #7
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example #8
Source File: SerializedForm.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #9
Source File: SerializedForm.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Symbol sym : def.members().getSymbolsByName(names.fromString(SERIALIZABLE_FIELDS))) {
        if (sym.kind == VAR) {
            VarSymbol f = (VarSymbol)sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #10
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * determine the receiver of the method call - the receiver can
 * be a type qualifier, the synthetic receiver parameter or 'super'.
 */
private JCExpression expressionInvoke(VarSymbol rcvr) {
    JCExpression qualifier =
            (rcvr != null) ?
                makeReceiver(rcvr) :
                tree.getQualifierExpression();

    //create the qualifier expression
    JCFieldAccess select = make.Select(qualifier, tree.sym.name);
    select.sym = tree.sym;
    select.type = tree.sym.erasure(types);

    //create the method call expression
    JCExpression apply = make.Apply(List.<JCExpression>nil(), select,
            convertArgs(tree.sym, args.toList(), tree.varargsElement)).
            setType(tree.sym.erasure(types).getReturnType());

    apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType());
    setVarargsIfNeeded(apply, tree.varargsElement);
    return apply;
}
 
Example #11
Source File: Gen.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void visitIdent(JCIdent tree) {
    Symbol sym = tree.sym;
    if (tree.name == names._this || tree.name == names._super) {
        Item res = tree.name == names._this
            ? items.makeThisItem()
            : items.makeSuperItem();
        if (sym.kind == MTH) {
            // Generate code to address the constructor.
            res.load();
            res = items.makeMemberItem(sym, true);
        }
        result = res;
    } else if (sym.kind == VAR && sym.owner.kind == MTH) {
        result = items.makeLocalItem((VarSymbol)sym);
    } else if (isInvokeDynamic(sym)) {
        result = items.makeDynamicItem(sym);
    } else if ((sym.flags() & STATIC) != 0) {
        if (!isAccessSuper(env.enclMethod))
            sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeStaticItem(sym);
    } else {
        items.makeThisItem().load();
        sym = binaryQualifier(sym, env.enclClass.type);
        result = items.makeMemberItem(sym, (sym.flags() & PRIVATE) != 0);
    }
}
 
Example #12
Source File: Gen.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) {
    List<TypeCompound> tas = sym.getRawTypeAttributes();
    ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<Attribute.TypeCompound>();
    ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<Attribute.TypeCompound>();
    for (TypeCompound ta : tas) {
        if (ta.getPosition().type == TargetType.FIELD) {
            fieldTAs.add(ta);
        } else {
            if (typeAnnoAsserts) {
                Assert.error("Type annotation does not have a valid positior");
            }

            nonfieldTAs.add(ta);
        }
    }
    sym.setTypeAttributes(fieldTAs.toList());
    return nonfieldTAs.toList();
}
 
Example #13
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example #14
Source File: Gen.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** This method will be called after any operation that causes a change to
 *  the bits. Subclasses can thus override it in order to extract information
 *  from the changes produced to the bits by the given operation.
 */
public void changed() {
    if (currentTree != null &&
            stateBeforeOp != BitsState.UNKNOWN &&
            trackTree(currentTree)) {
        List<VarSymbol> locals =
                analyzer.lvtRanges
                .getVars(analyzer.currentMethod, currentTree);
        locals = locals != null ?
                locals : List.<VarSymbol>nil();
        for (JCVariableDecl vardecl : analyzer.vardecls) {
            //once the first is null, the rest will be so.
            if (vardecl == null) {
                break;
            }
            if (trackVar(vardecl.sym) && bitChanged(vardecl.sym.adr)) {
                locals = locals.prepend(vardecl.sym);
            }
        }
        if (!locals.isEmpty()) {
            analyzer.lvtRanges.setEntry(analyzer.currentMethod,
                    currentTree, locals);
        }
    }
}
 
Example #15
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private JCIdent makeThis(Type type, Symbol owner) {
    VarSymbol _this = new VarSymbol(PARAMETER | FINAL | SYNTHETIC,
            names._this,
            type,
            owner);
    return make.Ident(_this);
}
 
Example #16
Source File: ArrayTypeToString.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    for (TypeElement te : tes) {
        for (Element e : renv.getElementsAnnotatedWith(te)) {
            String s = ((VarSymbol) e).type.toString();

            // Normalize output by removing whitespace
            s = s.replaceAll("\\s", "");

            // Expected: "@Foo(0)java.lang.String@Foo(3)[]@Foo(2)[]@Foo(1)[]"
            processingEnv.getMessager().printMessage(Kind.NOTE, s);
        }
    }
    return true;
}
 
Example #17
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) {
        JCClassDecl localCDef = localClassDefs.get(csym);
        if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) {
            BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() {
                @Override
                void addFreeVars(ClassSymbol c) {
                    captureLocalClassDefs(c, lambdaContext);
                }
                @Override
                void visitSymbol(Symbol sym) {
                    if (sym.kind == VAR &&
                            sym.owner.kind == MTH &&
                            ((VarSymbol)sym).getConstValue() == null) {
                        TranslationContext<?> localContext = context();
                        while (localContext != null) {
                            if (localContext.tree.getTag() == LAMBDA) {
                                JCTree block = capturedDecl(localContext.depth, sym);
                                if (block == null) break;
                                ((LambdaTranslationContext)localContext).addSymbol(sym, CAPTURED_VAR);
                            }
                            localContext = localContext.prev;
                        }
                    }
                }
            };
            fvc.scan(localCDef);
        }
}
 
Example #18
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private VarSymbol addParameter(String name, Type p, boolean genArg) {
    VarSymbol vsym = new VarSymbol(PARAMETER | SYNTHETIC, names.fromString(name), p, owner);
    vsym.pos = tree.pos;
    params.append(make.VarDef(vsym, null));
    if (genArg) {
        args.append(make.Ident(vsym));
    }
    return vsym;
}
 
Example #19
Source File: Gen.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) {
    List<TypeCompound> tas = sym.getRawTypeAttributes();
    ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<>();
    ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<>();
    for (TypeCompound ta : tas) {
        Assert.check(ta.getPosition().type != TargetType.UNKNOWN);
        if (ta.getPosition().type == TargetType.FIELD) {
            fieldTAs.add(ta);
        } else {
            nonfieldTAs.add(ta);
        }
    }
    sym.setTypeAttributes(fieldTAs.toList());
    return nonfieldTAs.toList();
}
 
Example #20
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Read a field.
 */
VarSymbol readField() {
    long flags = adjustFieldFlags(nextChar());
    Name name = readName(nextChar());
    Type type = readType(nextChar());
    VarSymbol v = new VarSymbol(flags, name, type, currentOwner);
    readMemberAttrs(v);
    return v;
}
 
Example #21
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private JCExpression makeReceiver(VarSymbol rcvr) {
    if (rcvr == null) return null;
    JCExpression rcvrExpr = make.Ident(rcvr);
    Type rcvrType = tree.ownerAccessible ? tree.sym.enclClass().type : tree.expr.type;
    if (rcvrType == syms.arrayClass.type) {
        // Map the receiver type to the actually type, not just "array"
        rcvrType = tree.getQualifierExpression().type;
    }
    if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) {
        rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType);
    }
    return rcvrExpr;
}
 
Example #22
Source File: Gen.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected boolean trackable(VarSymbol sym) {
    if (isSyntheticOrMandated(sym)) {
        //fast check to avoid tracking synthetic or mandated variables
        return false;
    }
    return super.trackable(sym);
}
 
Example #23
Source File: LVTRanges.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean containsKey(MethodSymbol method, JCTree tree) {
    Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method);
    if (varMap == null) {
        return false;
    }
    return varMap.containsKey(tree);
}
 
Example #24
Source File: Gen.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void visitVarDef(JCVariableDecl tree) {
    VarSymbol v = tree.sym;
    code.newLocal(v);
    if (tree.init != null) {
        checkStringConstant(tree.init.pos(), v.getConstValue());
        if (v.getConstValue() == null || varDebugInfo) {
            Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
            genExpr(tree.init, v.erasure(types)).load();
            items.makeLocalItem(v).store();
            Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
        }
    }
    checkDimension(tree.pos(), v.type);
}
 
Example #25
Source File: LambdaToMethod.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private KlassInfo(JCClassDecl clazz) {
    this.clazz = clazz;
    appendedMethodList = new ListBuffer<>();
    deserializeCases = new HashMap<String, ListBuffer<JCStatement>>();
    MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType,
            List.<Type>nil(), syms.methodClass);
    deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym);
    deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"),
            syms.serializedLambdaType, deserMethodSym);
}
 
Example #26
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
protected JCVariableDecl(JCModifiers mods,
                         Name name,
                         JCExpression vartype,
                         JCExpression init,
                         VarSymbol sym) {
    this.mods = mods;
    this.name = name;
    this.vartype = vartype;
    this.init = init;
    this.sym = sym;
}
 
Example #27
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private VarSymbol addParameter(String name, Type p, boolean genArg) {
    VarSymbol vsym = new VarSymbol(PARAMETER | SYNTHETIC, names.fromString(name), p, owner);
    vsym.pos = tree.pos;
    params.append(make.VarDef(vsym, null));
    if (genArg) {
        args.append(make.Ident(vsym));
    }
    return vsym;
}
 
Example #28
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private JCExpression makeReceiver(VarSymbol rcvr) {
    if (rcvr == null) return null;
    JCExpression rcvrExpr = make.Ident(rcvr);
    Type rcvrType = tree.sym.enclClass().type;
    if (rcvrType == syms.arrayClass.type) {
        // Map the receiver type to the actually type, not just "array"
        rcvrType = tree.getQualifierExpression().type;
    }
    if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) {
        rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType);
    }
    return rcvrExpr;
}
 
Example #29
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private KlassInfo(JCClassDecl clazz) {
    this.clazz = clazz;
    appendedMethodList = new ListBuffer<>();
    deserializeCases = new HashMap<String, ListBuffer<JCStatement>>();
    MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType,
            List.<Type>nil(), syms.methodClass);
    deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym);
    deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"),
            syms.serializedLambdaType, deserMethodSym);
}
 
Example #30
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Attach parameter annotations.
 */
void attachParameterAnnotations(final Symbol method) {
    final MethodSymbol meth = (MethodSymbol)method;
    int numParameters = buf[bp++] & 0xFF;
    List<VarSymbol> parameters = meth.params();
    int pnum = 0;
    while (parameters.tail != null) {
        attachAnnotations(parameters.head);
        parameters = parameters.tail;
        pnum++;
    }
    if (pnum != numParameters) {
        throw badClassFile("bad.runtime.invisible.param.annotations", meth);
    }
}