/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.javac.comp;
import java.util.*;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.jvm.Target;
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*;
import static com.sun.tools.javac.code.TypeTags.*;
import static com.sun.tools.javac.jvm.ByteCodes.*;
/** This pass translates away some syntactic sugar: inner classes,
* class literals, assertions, foreach loops, etc.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class Lower extends TreeTranslator {
protected static final Context.Key<Lower> lowerKey =
new Context.Key<Lower>();
public static Lower instance(Context context) {
Lower instance = context.get(lowerKey);
if (instance == null)
instance = new Lower(context);
return instance;
}
private Name.Table names;
private Log log;
private Symtab syms;
private Resolve rs;
private Check chk;
private Attr attr;
private TreeMaker make;
private DiagnosticPosition make_pos;
private ClassWriter writer;
private ClassReader reader;
private ConstFold cfolder;
private Target target;
private Source source;
private boolean allowEnums;
private final Name dollarAssertionsDisabled;
private final Name classDollar;
private Types types;
private boolean debugLower;
protected Lower(Context context) {
context.put(lowerKey, this);
names = Name.Table.instance(context);
log = Log.instance(context);
syms = Symtab.instance(context);
rs = Resolve.instance(context);
chk = Check.instance(context);
attr = Attr.instance(context);
make = TreeMaker.instance(context);
writer = ClassWriter.instance(context);
reader = ClassReader.instance(context);
cfolder = ConstFold.instance(context);
target = Target.instance(context);
source = Source.instance(context);
allowEnums = source.allowEnums();
dollarAssertionsDisabled = names.
fromString(target.syntheticNameChar() + "assertionsDisabled");
classDollar = names.
fromString("class" + target.syntheticNameChar());
types = Types.instance(context);
Options options = Options.instance(context);
debugLower = options.get("debuglower") != null;
}
/** The currently enclosing class.
*/
ClassSymbol currentClass;
/** A queue of all translated classes.
*/
ListBuffer<JCTree> translated;
/** Environment for symbol lookup, set by translateTopLevelClass.
*/
Env<AttrContext> attrEnv;
/** A hash table mapping syntax trees to their ending source positions.
*/
Map<JCTree, Integer> endPositions;
/**************************************************************************
* Global mappings
*************************************************************************/
/** A hash table mapping local classes to their definitions.
*/
Map<ClassSymbol, JCClassDecl> classdefs;
/** A hash table mapping virtual accessed symbols in outer subclasses
* to the actually referred symbol in superclasses.
*/
Map<Symbol,Symbol> actualSymbols;
/** The current method definition.
*/
JCMethodDecl currentMethodDef;
/** The current method symbol.
*/
MethodSymbol currentMethodSym;
/** The currently enclosing outermost class definition.
*/
JCClassDecl outermostClassDef;
/** The currently enclosing outermost member definition.
*/
JCTree outermostMemberDef;
/** A navigator class for assembling a mapping from local class symbols
* to class definition trees.
* There is only one case; all other cases simply traverse down the tree.
*/
class ClassMap extends TreeScanner {
/** All encountered class defs are entered into classdefs table.
*/
public void visitClassDef(JCClassDecl tree) {
classdefs.put(tree.sym, tree);
super.visitClassDef(tree);
}
}
ClassMap classMap = new ClassMap();
/** Map a class symbol to its definition.
* @param c The class symbol of which we want to determine the definition.
*/
JCClassDecl classDef(ClassSymbol c) {
// First lookup the class in the classdefs table.
JCClassDecl def = classdefs.get(c);
if (def == null && outermostMemberDef != null) {
// If this fails, traverse outermost member definition, entering all
// local classes into classdefs, and try again.
classMap.scan(outermostMemberDef);
def = classdefs.get(c);
}
if (def == null) {
// If this fails, traverse outermost class definition, entering all
// local classes into classdefs, and try again.
classMap.scan(outermostClassDef);
def = classdefs.get(c);
}
return def;
}
/** A hash table mapping class symbols to lists of free variables.
* accessed by them. Only free variables of the method immediately containing
* a class are associated with that class.
*/
Map<ClassSymbol,List<VarSymbol>> freevarCache;
/** A navigator class for collecting the free variables accessed
* from a local class.
* There is only one case; all other cases simply traverse down the tree.
*/
class FreeVarCollector extends TreeScanner {
/** The owner of the local class.
*/
Symbol owner;
/** The local class.
*/
ClassSymbol clazz;
/** The list of owner's variables accessed from within the local class,
* without any duplicates.
*/
List<VarSymbol> fvs;
FreeVarCollector(ClassSymbol clazz) {
this.clazz = clazz;
this.owner = clazz.owner;
this.fvs = List.nil();
}
/** Add free variable to fvs list unless it is already there.
*/
private void addFreeVar(VarSymbol v) {
for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail)
if (l.head == v) return;
fvs = fvs.prepend(v);
}
/** Add all free variables of class
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Javac内核源码 (1716个子文件)
Lower.class 90KB
Attr.class 83KB
Parser.class 74KB
Gen.class 63KB
Check.class 58KB
ClassReader.class 52KB
Resolve.class 50KB
TreeMaker.class 49KB
Types.class 49KB
TreeCopier.class 46KB
JavaCompiler.class 46KB
HtmlDocletWriter.class 43KB
MemberEnter.class 41KB
ClassWriter.class 39KB
JavacProcessingEnvironment.class 38KB
Flow.class 33KB
Pretty.class 33KB
TransTypes.class 32KB
Code.class 29KB
JavacFileManager.class 27KB
ClassDocImpl.class 27KB
JavacElements.class 25KB
Main.class 25KB
ZipFileIndex.class 22KB
TreeInfo.class 22KB
TreeScanner.class 21KB
CreateSymbols.class 21KB
JavapPrinter.class 20KB
Util.class 20KB
JavacTrees.class 20KB
DocEnv.class 20KB
Enter.class 20KB
JavacTaskImpl.class 19KB
TreeTranslator.class 19KB
CRTable$SourceComputer.class 18KB
Symtab.class 18KB
Apt.class 18KB
RuntimeConstants.class 17KB
Scanner.class 17KB
LLNI.class 17KB
JavadocTool.class 17KB
PrintingProcessor$PrintingElementVisitor.class 17KB
Log.class 16KB
TreeScanner.class 16KB
ClassUseWriter.class 16KB
SimpleTreeVisitor.class 16KB
TagletManager.class 16KB
ClassWriterImpl.class 15KB
JCTree$Factory.class 15KB
HtmlWriter.class 15KB
Main.class 14KB
Configuration.class 14KB
ClassData.class 14KB
JCTree$Visitor.class 13KB
Annotate.class 13KB
Start.class 13KB
JavacTypes.class 13KB
AbstractMemberWriter.class 13KB
Infer.class 13KB
PrintAP$PrintingVisitors.class 12KB
SerializedFormBuilder.class 12KB
JavacTool.class 12KB
List.class 12KB
Symbol$MethodSymbol.class 12KB
BaseFileManager.class 12KB
MethodWriterImpl.class 12KB
Symbol.class 12KB
Type.class 12KB
JavacFiler.class 12KB
Paths.class 11KB
ClassUseMapper.class 11KB
JavaCompiler.class 10KB
AnnotationTypeWriterImpl.class 10KB
ClassReader$AnnotationDeproxy.class 10KB
TagletWriterImpl.class 10KB
FilerImpl.class 10KB
Lower$EnumMapping.class 10KB
DeclarationMaker.class 10KB
DocletInvoker.class 10KB
TypesImpl.class 10KB
Gen$1ComplexityScanner.class 9KB
MemberSummaryBuilder.class 9KB
ParamTaglet.class 9KB
HtmlDoclet.class 9KB
Tree$Kind.class 9KB
BuilderFactory.class 9KB
PackageDocImpl.class 9KB
FieldWriterImpl.class 9KB
ConstFold.class 9KB
RecognizedOptions.class 9KB
DeclarationImpl.class 9KB
Constants.class 9KB
JCTree.class 9KB
RootDocImpl.class 9KB
Keywords.class 9KB
Types$Subst.class 9KB
ExecutableMemberDocImpl.class 9KB
Gen.class 9KB
SourceToHTMLConverter.class 9KB
Messager.class 8KB
共 1716 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
ibenben.org
- 粉丝: 143
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页