function Gen() { var c = 0; // c is private here this.next = function() {return ++c;} } var gen = new Gen(); console.log(gen.next()); // 1 console.log(gen.next()); // 2 console.log(gen.next()); // 3
/** Add all strings in tree to string buffer. */ void appendStrings(JCTree tree) { tree = TreeInfo.skipParens(tree); if (tree.tag == JCTree.PLUS && tree.type.constValue() == null) { JCBinary op = (JCBinary) tree; if (op.operator.kind == MTH && ((OperatorSymbol) op.operator).opcode == string_add) { appendStrings(op.lhs); appendStrings(op.rhs); return; } } genExpr(tree, tree.type).load(); appendString(tree); }
/** Make a new string buffer. */ void makeStringBuffer(DiagnosticPosition pos) { code.emitop2(new_, makeRef(pos, stringBufferType)); code.emitop0(dup); callMethod( pos, stringBufferType, names.init, List.<Type>nil(), false); }
public void visitMethodDef(JCMethodDecl tree) { // Create a new local environment that points pack at method // definition. Env<GenContext> localEnv = env.dup(tree); localEnv.enclMethod = tree; // The expected type of every return statement in this method // is the method's return type. this.pt = tree.sym.erasure(types).getReturnType(); checkDimension(tree.pos(), tree.sym.erasure(types)); genMethod(tree, localEnv, false); } //where
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); l = genExpr(tree.lhs, tree.lhs.type); if (l.width() > 0) { code.emitop0(dup_x1 + 3 * (l.width() - 1)); appendString(tree.lhs); appendStrings(tree.rhs); bufferToString(tree.pos()); } else { l = genExpr(tree.lhs, tree.lhs.type); completeBinop(tree.lhs, tree.rhs, operator).coerce(tree.lhs.type);
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); appendStrings(tree); bufferToString(tree.pos()); result = items.makeStackItem(syms.stringType); } else if (tree.tag == JCTree.AND) { CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); if (!lcond.isFalse()) { Chain falseJumps = lcond.jumpFalse(); code.resolve(lcond.trueJumps); CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); result = items. makeCondItem(rcond.opcode, CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); if (!lcond.isTrue()) { Chain trueJumps = lcond.jumpTrue(); code.resolve(lcond.falseJumps); CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); result = items. makeCondItem(rcond.opcode, Item od = genExpr(tree.lhs, operator.type.getParameterTypes().head); od.load(); result = completeBinop(tree.lhs, tree.rhs, operator);
code.emitLdc(makeRef(tree.pos(), tree.selected.type)); result = items.makeStackItem(pt); return; boolean accessSuper = isAccessSuper(env.enclMethod); : genExpr(tree.selected, tree.selected.type); } else { base.load(); genNullCheck(tree.selected.pos()); if (isInvokeDynamic(sym)) { result = items.makeDynamicItem(sym); return; } else { sym = binaryQualifier(sym, tree.selected.type);
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); }
/** Add abstract methods for all methods defined in one of * the interfaces of a given class, * provided they are not already implemented in the class. * * @param c The class whose interfaces are searched for methods * for which Miranda methods should be added. * @param site The class in which a definition may be needed. */ void implementInterfaceMethods(ClassSymbol c, ClassSymbol site) { for (List<Type> l = types.interfaces(c.type); l.nonEmpty(); l = l.tail) { ClassSymbol i = (ClassSymbol)l.head.tsym; for (Scope.Entry e = i.members().elems; e != null; e = e.sibling) { if (e.sym.kind == MTH && (e.sym.flags() & STATIC) == 0) { MethodSymbol absMeth = (MethodSymbol)e.sym; MethodSymbol implMeth = absMeth.binaryImplementation(site, types); if (implMeth == null) addAbstractMethod(site, absMeth); else if ((implMeth.flags() & IPROXY) != 0) adjustAbstractMethod(site, implMeth, absMeth); } } implementInterfaceMethods(i, site); } }
JCVariableDecl vdef = (JCVariableDecl) def; VarSymbol sym = vdef.sym; checkDimension(vdef.pos(), sym.type); if (vdef.init != null) { if ((sym.flags() & STATIC) == 0) { initCode.append(init); endPosTable.replaceTree(vdef, init); initTAs.addAll(getAndRemoveNonFieldTAs(sym)); } else if (sym.getConstValue() == null) { clinitCode.append(init); endPosTable.replaceTree(vdef, init); clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); } else { checkStringConstant(vdef.init.pos(), sym.getConstValue()); List<Attribute.TypeCompound> initTAlist = initTAs.toList(); for (JCTree t : methodDefs) { normalizeMethod((JCMethodDecl)t, inits, initTAlist);
JCVariableDecl vdef = (JCVariableDecl) def; VarSymbol sym = vdef.sym; checkDimension(vdef.pos(), sym.type); if (vdef.init != null) { if ((sym.flags() & STATIC) == 0) { checkStringConstant(vdef.init.pos(), sym.getConstValue()); List<JCStatement> inits = initCode.toList(); for (JCTree t : methodDefs) { normalizeMethod((JCMethodDecl)t, inits);
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); } }
/** Insert a reference to given type in the constant pool, * checking for an array with too many dimensions; * return the reference's index. * @param type The type for which a reference is inserted. */ int makeRef(DiagnosticPosition pos, Type type) { checkDimension(pos, type); return pool.put(type.tag == CLASS ? (Object)type.tsym : (Object)type); }
/** Convert string buffer on tos to string. */ void bufferToString(DiagnosticPosition pos) { callMethod( pos, stringBufferType, names.toString, List.<Type>nil(), false); }
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 ((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); } }
private void reassignEarlyHolders( Context context ) { ReflectUtil.field( _attr, "rs" ).set( this ); ReflectUtil.field( DeferredAttr.instance( context ), "rs" ).set( this ); ReflectUtil.field( Check.instance( context ), "rs" ).set( this ); ReflectUtil.field( Infer.instance( context ), "rs" ).set( this ); ReflectUtil.field( Flow.instance( context ), "rs" ).set( this ); ReflectUtil.field( LambdaToMethod.instance( context ), "rs" ).set( this ); ReflectUtil.field( Lower.instance( context ), "rs" ).set( this ); ReflectUtil.field( Gen.instance( context ), "rs" ).set( this ); ReflectUtil.field( ReflectUtil.method( ReflectUtil.type( "com.sun.tools.javac.jvm.StringConcat" ), "instance", Context.class ) .invokeStatic( context ), "rs" ) .set( this ); ReflectUtil.field( JavacTrees.instance( context ), "resolve" ).set( this ); ReflectUtil.field( Annotate.instance( context ), "resolve" ).set( this ); ReflectUtil.field( TransTypes.instance( context ), "resolve" ).set( this ); ReflectUtil.field( JavacElements.instance( context ), "resolve" ).set( this ); }
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); l = genExpr(tree.lhs, tree.lhs.type); if (l.width() > 0) { code.emitop0(dup_x1 + 3 * (l.width() - 1)); appendString(tree.lhs); appendStrings(tree.rhs); bufferToString(tree.pos()); } else { l = genExpr(tree.lhs, tree.lhs.type); completeBinop(tree.lhs, tree.rhs, operator).coerce(tree.lhs.type);
if (operator.opcode == string_add) { makeStringBuffer(tree.pos()); appendStrings(tree); bufferToString(tree.pos()); result = items.makeStackItem(syms.stringType); } else if (tree.getTag() == JCTree.AND) { CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); if (!lcond.isFalse()) { Chain falseJumps = lcond.jumpFalse(); code.resolve(lcond.trueJumps); CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); result = items. makeCondItem(rcond.opcode, CondItem lcond = genCond(tree.lhs, CRT_FLOW_CONTROLLER); if (!lcond.isTrue()) { Chain trueJumps = lcond.jumpTrue(); code.resolve(lcond.falseJumps); CondItem rcond = genCond(tree.rhs, CRT_FLOW_TARGET); result = items. makeCondItem(rcond.opcode, Item od = genExpr(tree.lhs, operator.type.getParameterTypes().head); od.load(); result = completeBinop(tree.lhs, tree.rhs, operator);
code.emitLdc(makeRef(tree.pos(), tree.selected.type)); result = items.makeStackItem(pt); return; boolean accessSuper = isAccessSuper(env.enclMethod); : genExpr(tree.selected, tree.selected.type); } else { base.load(); genNullCheck(tree.selected.pos()); if (isInvokeDynamic(sym)) { result = items.makeDynamicItem(sym); return; } else { sym = binaryQualifier(sym, tree.selected.type);
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); }