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

The following examples show how to use com.sun.tools.javac.code.Symbol.VarSymbol. These examples are extracted from open source projects. 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 Project: openjdk-8   Source File: Gen.java    License: 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 2
Source Project: openjdk-jdk9   Source File: SerializedForm.java    License: 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 3
Source Project: openjdk-8   Source File: SerializedForm.java    License: 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 4
Source Project: openjdk-jdk8u-backup   Source File: Gen.java    License: 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 Project: TencentKona-8   Source File: LambdaToMethod.java    License: 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 6
Source Project: openjdk-jdk9   Source File: Gen.java    License: 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 7
Source Project: jdk8u60   Source File: LambdaToMethod.java    License: 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 Project: openjdk-jdk9   Source File: SerializedForm.java    License: 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 9
Source Project: openjdk-8-source   Source File: LVTRanges.java    License: 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 10
Source Project: hottub   Source File: LambdaToMethod.java    License: 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 Project: openjdk-jdk8u   Source File: LambdaToMethod.java    License: 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 12
Source Project: openjdk-jdk8u   Source File: LambdaToMethod.java    License: 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 13
Source Project: openjdk-8-source   Source File: Gen.java    License: 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 14
Source Project: openjdk-8-source   Source File: Gen.java    License: 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
/** 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 16
Source Project: hottub   Source File: Gen.java    License: 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) {
            genExpr(tree.init, v.erasure(types)).load();
            items.makeLocalItem(v).store();
        }
    }
    checkDimension(tree.pos(), v.type);
}
 
Example 17
/** Construct an expression using the builder, with the given rval
 *  expression as an argument to the builder.  However, the rval
 *  expression must be computed only once, even if used multiple
 *  times in the result of the builder.  We do that by
 *  constructing a "let" expression that saves the rvalue into a
 *  temporary variable and then uses the temporary variable in
 *  place of the expression built by the builder.  The complete
 *  resulting expression is of the form
 *  <pre>
 *    (let <b>TYPE</b> <b>TEMP</b> = <b>RVAL</b>;
 *     in (<b>BUILDER</b>(<b>TEMP</b>)))
 *  </pre>
 *  where <code><b>TEMP</b></code> is a newly declared variable
 *  in the let expression.
 */
JCExpression abstractRval(JCExpression rval, Type type, TreeBuilder builder) {
    rval = TreeInfo.skipParens(rval);
    switch (rval.getTag()) {
    case LITERAL:
        return builder.build(rval);
    case IDENT:
        JCIdent id = (JCIdent) rval;
        if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH)
            return builder.build(rval);
    }
    Name name = TreeInfo.name(rval);
    if (name == names._super || name == names._this)
        return builder.build(rval);
    VarSymbol var =
        new VarSymbol(FINAL|SYNTHETIC,
                      names.fromString(
                                      target.syntheticNameChar()
                                      + "" + rval.hashCode()),
                                  type,
                                  currentMethodSym);
    rval = convert(rval,type);
    JCVariableDecl def = make.VarDef(var, rval); // XXX cast
    JCExpression built = builder.build(make.Ident(var));
    JCExpression res = make.LetExpr(def, built);
    res.type = built.type;
    return res;
}
 
Example 18
Source Project: TencentKona-8   Source File: Gen.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Create a tempory variable.
 *  @param type   The variable's type.
 */
LocalItem makeTemp(Type type) {
    VarSymbol v = new VarSymbol(Flags.SYNTHETIC,
                                names.empty,
                                type,
                                env.enclMethod.sym);
    code.newLocal(v);
    return items.makeLocalItem(v);
}
 
Example 19
Source Project: openjdk-8-source   Source File: LVTRanges.java    License: 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 20
Source Project: openjdk-8-source   Source File: Gen.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Create a tempory variable.
 *  @param type   The variable's type.
 */
LocalItem makeTemp(Type type) {
    VarSymbol v = new VarSymbol(Flags.SYNTHETIC,
                                names.empty,
                                type,
                                env.enclMethod.sym);
    code.newLocal(v);
    return items.makeLocalItem(v);
}
 
Example 21
Source Project: TencentKona-8   Source File: LambdaToMethod.java    License: 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 22
Source Project: openjdk-jdk9   Source File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the FieldDoc of this var symbol.
 */
public FieldDocImpl getFieldDoc(VarSymbol var) {
    FieldDocImpl result = fieldMap.get(var);
    if (result != null) return result;
    result = new FieldDocImpl(this, var);
    fieldMap.put(var, result);
    return result;
}
 
Example 23
Source Project: TencentKona-8   Source File: LambdaToMethod.java    License: 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 24
Source Project: TencentKona-8   Source File: LambdaToMethod.java    License: 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 25
/** Check that variable does not hide variable with same name in
 *  immediately enclosing local scope.
 *  @param pos           Position for error reporting.
 *  @param v             The symbol.
 *  @param s             The scope.
 */
void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) {
    for (Symbol sym : s.getSymbolsByName(v.name)) {
        if (sym.owner != v.owner) break;
        if (sym.kind == VAR &&
            sym.owner.kind.matches(KindSelector.VAL_MTH) &&
            v.name != names.error) {
            duplicateError(pos, sym);
            return;
        }
    }
}
 
Example 26
Source Project: jdk8u60   Source File: Gen.java    License: 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) {
            genExpr(tree.init, v.erasure(types)).load();
            items.makeLocalItem(v).store();
        }
    }
    checkDimension(tree.pos(), v.type);
}
 
Example 27
Source Project: Refaster   Source File: UTemplater.java    License: Apache License 2.0 5 votes vote down vote up
public static ImmutableMap<String, VarSymbol> freeExpressionVariables(
    MethodTree templateMethodDecl) {
  ImmutableMap.Builder<String, VarSymbol> builder = ImmutableMap.builder();
  for (VariableTree param : templateMethodDecl.getParameters()) {
    builder.put(param.getName().toString(), ASTHelpers.getSymbol(param));
  }
  return builder.build();
}
 
Example 28
Source Project: openjdk-8-source   Source File: Gen.java    License: 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 29
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 Project: jdk8u60   Source File: LambdaToMethod.java    License: 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;
}