Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
08a6b377
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
08a6b377
编写于
11月 14, 2011
作者:
K
ksrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7106166: (javac) re-factor EndPos parser
Reviewed-by: jjg
上级
cf1a9a23
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
274 addition
and
123 deletion
+274
-123
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
+3
-2
src/share/classes/com/sun/tools/javac/comp/Lower.java
src/share/classes/com/sun/tools/javac/comp/Lower.java
+6
-6
src/share/classes/com/sun/tools/javac/jvm/CRTable.java
src/share/classes/com/sun/tools/javac/jvm/CRTable.java
+6
-8
src/share/classes/com/sun/tools/javac/jvm/Gen.java
src/share/classes/com/sun/tools/javac/jvm/Gen.java
+8
-14
src/share/classes/com/sun/tools/javac/parser/EndPosTable.java
...share/classes/com/sun/tools/javac/parser/EndPosTable.java
+56
-0
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
...share/classes/com/sun/tools/javac/parser/JavacParser.java
+139
-35
src/share/classes/com/sun/tools/javac/parser/ParserFactory.java
...are/classes/com/sun/tools/javac/parser/ParserFactory.java
+2
-6
src/share/classes/com/sun/tools/javac/tree/JCTree.java
src/share/classes/com/sun/tools/javac/tree/JCTree.java
+4
-3
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
+28
-28
src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
...re/classes/com/sun/tools/javac/util/DiagnosticSource.java
+5
-4
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
+3
-2
src/share/classes/com/sun/tools/javac/util/Log.java
src/share/classes/com/sun/tools/javac/util/Log.java
+3
-2
test/tools/javac/6304921/TestLog.java
test/tools/javac/6304921/TestLog.java
+5
-4
test/tools/javac/failover/CheckAttributedTree.java
test/tools/javac/failover/CheckAttributedTree.java
+3
-7
test/tools/javac/tree/TreePosTest.java
test/tools/javac/tree/TreePosTest.java
+3
-2
未找到文件。
src/share/classes/com/sun/tools/javac/api/JavacTrees.java
浏览文件 @
08a6b377
...
...
@@ -59,6 +59,7 @@ import com.sun.tools.javac.comp.Env;
import
com.sun.tools.javac.comp.MemberEnter
;
import
com.sun.tools.javac.comp.Resolve
;
import
com.sun.tools.javac.model.JavacElements
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.processing.JavacProcessingEnvironment
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
com.sun.tools.javac.tree.JCTree
;
...
...
@@ -140,8 +141,8 @@ public class JavacTrees extends Trees {
}
public
long
getEndPosition
(
CompilationUnitTree
file
,
Tree
tree
)
{
Map
<
JCTree
,
Integer
>
endPositions
=
((
JCCompilationUnit
)
file
).
endPositions
;
return
TreeInfo
.
getEndPos
((
JCTree
)
tree
,
endPos
itions
);
EndPosTable
endPosTable
=
((
JCCompilationUnit
)
file
).
endPositions
;
return
TreeInfo
.
getEndPos
((
JCTree
)
tree
,
endPos
Table
);
}
};
}
...
...
src/share/classes/com/sun/tools/javac/comp/Lower.java
浏览文件 @
08a6b377
...
...
@@ -40,6 +40,7 @@ import com.sun.tools.javac.tree.JCTree.*;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.jvm.Target
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Flags
.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Flags
.
BLOCK
;
...
...
@@ -127,7 +128,7 @@ public class Lower extends TreeTranslator {
/** A hash table mapping syntax trees to their ending source positions.
*/
Map
<
JCTree
,
Integer
>
endPositions
;
EndPosTable
endPosTable
;
/**************************************************************************
* Global mappings
...
...
@@ -2195,9 +2196,8 @@ public class Lower extends TreeTranslator {
}
else
{
make_at
(
tree
.
pos
());
T
result
=
super
.
translate
(
tree
);
if
(
endPositions
!=
null
&&
result
!=
tree
)
{
Integer
endPos
=
endPositions
.
remove
(
tree
);
if
(
endPos
!=
null
)
endPositions
.
put
(
result
,
endPos
);
if
(
endPosTable
!=
null
&&
result
!=
tree
)
{
endPosTable
.
replaceTree
(
tree
,
result
);
}
return
result
;
}
...
...
@@ -3675,7 +3675,7 @@ public class Lower extends TreeTranslator {
try
{
attrEnv
=
env
;
this
.
make
=
make
;
endPos
itions
=
env
.
toplevel
.
endPositions
;
endPos
Table
=
env
.
toplevel
.
endPositions
;
currentClass
=
null
;
currentMethodDef
=
null
;
outermostClassDef
=
(
cdef
.
hasTag
(
CLASSDEF
))
?
(
JCClassDecl
)
cdef
:
null
;
...
...
@@ -3704,7 +3704,7 @@ public class Lower extends TreeTranslator {
// note that recursive invocations of this method fail hard
attrEnv
=
null
;
this
.
make
=
null
;
endPos
itions
=
null
;
endPos
Table
=
null
;
currentClass
=
null
;
currentMethodDef
=
null
;
outermostClassDef
=
null
;
...
...
src/share/classes/com/sun/tools/javac/jvm/CRTable.java
浏览文件 @
08a6b377
...
...
@@ -31,6 +31,7 @@ import com.sun.tools.javac.tree.*;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.List
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
com.sun.tools.javac.parser.EndPosTable
;
/** This class contains the CharacterRangeTable for some method
* and the hashtable for mapping trees or lists of trees to their
...
...
@@ -54,9 +55,9 @@ implements CRTFlags {
*/
private
Map
<
Object
,
SourceRange
>
positions
=
new
HashMap
<
Object
,
SourceRange
>();
/** The
hashtable
for ending positions stored in the parser.
/** The
object
for ending positions stored in the parser.
*/
private
Map
<
JCTree
,
Integer
>
endPositions
;
private
EndPosTable
endPosTable
;
/** The tree of the method this table is intended for.
* We should traverse this tree to get source ranges.
...
...
@@ -65,9 +66,9 @@ implements CRTFlags {
/** Constructor
*/
public
CRTable
(
JCTree
.
JCMethodDecl
tree
,
Map
<
JCTree
,
Integer
>
endPositions
)
{
public
CRTable
(
JCTree
.
JCMethodDecl
tree
,
EndPosTable
endPosTable
)
{
this
.
methodTree
=
tree
;
this
.
endPos
itions
=
endPositions
;
this
.
endPos
Table
=
endPosTable
;
}
/** Create a new CRTEntry and add it to the entries.
...
...
@@ -534,10 +535,7 @@ implements CRTFlags {
if
(
tree
==
null
)
return
Position
.
NOPOS
;
if
(
tree
.
hasTag
(
JCTree
.
Tag
.
BLOCK
))
return
((
JCBlock
)
tree
).
endpos
;
Integer
endpos
=
endPositions
.
get
(
tree
);
if
(
endpos
!=
null
)
return
endpos
.
intValue
();
return
Position
.
NOPOS
;
return
endPosTable
.
getEndPos
(
tree
);
}
}
...
...
src/share/classes/com/sun/tools/javac/jvm/Gen.java
浏览文件 @
08a6b377
...
...
@@ -26,8 +26,6 @@
package
com.sun.tools.javac.jvm
;
import
java.util.*
;
import
javax.lang.model.element.ElementKind
;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.List
;
...
...
@@ -39,6 +37,7 @@ import com.sun.tools.javac.code.Symbol.*;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.jvm.Code.*
;
import
com.sun.tools.javac.jvm.Items.*
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Flags
.*;
...
...
@@ -197,9 +196,10 @@ public class Gen extends JCTree.Visitor {
*/
private
int
nerrs
=
0
;
/** A hash table mapping syntax trees to their ending source positions.
/** An object containing mappings of syntax trees to their
* ending source positions.
*/
private
Map
<
JCTree
,
Integer
>
endPositions
;
EndPosTable
endPosTable
;
/** Generate code to load an integer constant.
* @param n The integer to be loaded.
...
...
@@ -482,20 +482,14 @@ public class Gen extends JCTree.Visitor {
JCStatement
init
=
make
.
at
(
vdef
.
pos
()).
Assignment
(
sym
,
vdef
.
init
);
initCode
.
append
(
init
);
if
(
endPositions
!=
null
)
{
Integer
endPos
=
endPositions
.
remove
(
vdef
);
if
(
endPos
!=
null
)
endPositions
.
put
(
init
,
endPos
);
}
endPosTable
.
replaceTree
(
vdef
,
init
);
}
else
if
(
sym
.
getConstValue
()
==
null
)
{
// Initialize class (static) variables only if
// they are not compile-time constants.
JCStatement
init
=
make
.
at
(
vdef
.
pos
).
Assignment
(
sym
,
vdef
.
init
);
clinitCode
.
append
(
init
);
if
(
endPositions
!=
null
)
{
Integer
endPos
=
endPositions
.
remove
(
vdef
);
if
(
endPos
!=
null
)
endPositions
.
put
(
init
,
endPos
);
}
endPosTable
.
replaceTree
(
vdef
,
init
);
}
else
{
checkStringConstant
(
vdef
.
init
.
pos
(),
sym
.
getConstValue
());
}
...
...
@@ -2217,7 +2211,7 @@ public class Gen extends JCTree.Visitor {
attrEnv
=
env
;
ClassSymbol
c
=
cdef
.
sym
;
this
.
toplevel
=
env
.
toplevel
;
this
.
endPos
itions
=
toplevel
.
endPositions
;
this
.
endPos
Table
=
toplevel
.
endPositions
;
// If this is a class definition requiring Miranda methods,
// add them.
if
(
generateIproxies
&&
...
...
@@ -2253,7 +2247,7 @@ public class Gen extends JCTree.Visitor {
attrEnv
=
null
;
this
.
env
=
null
;
toplevel
=
null
;
endPos
itions
=
null
;
endPos
Table
=
null
;
nerrs
=
0
;
}
}
...
...
src/share/classes/com/sun/tools/javac/parser/EndPos
Parser
.java
→
src/share/classes/com/sun/tools/javac/parser/EndPos
Table
.java
浏览文件 @
08a6b377
/*
* Copyright (c) 20
05, 2008
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 20
11
, 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
...
...
@@ -22,81 +22,35 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
com.sun.tools.javac.parser
;
import
java.util.Map
;
import
java.util.HashMap
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.TreeInfo
;
import
static
com
.
sun
.
tools
.
javac
.
tree
.
JCTree
.*;
/**
* This class is similar to Parser except that it stores ending
* positions for the tree nodes.
*
* Specifies the methods to access a mappings of syntax trees to end positions.
* <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></p>
* 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></p>
*/
public
class
EndPosParser
extends
JavacParser
{
public
EndPosParser
(
ParserFactory
fac
,
Lexer
S
,
boolean
keepDocComments
,
boolean
keepLineMap
)
{
super
(
fac
,
S
,
keepDocComments
,
keepLineMap
);
this
.
S
=
S
;
endPositions
=
new
HashMap
<
JCTree
,
Integer
>();
}
public
interface
EndPosTable
{
private
Lexer
S
;
/** A hashtable to store ending positions
*
of source ranges indexed by the tree nodes.
*
Defined only if option flag genEndPos is set.
/**
* This method will return the end position of a given tree, otherwise a
* Positions.NOPOS will be returned.
*
@param tree JCTree
*
@return position of the source tree or Positions.NOPOS for non-existent mapping
*/
Map
<
JCTree
,
Integer
>
endPositions
;
/** {@inheritDoc} */
@Override
protected
void
storeEnd
(
JCTree
tree
,
int
endpos
)
{
int
errorEndPos
=
getErrorEndPos
();
endPositions
.
put
(
tree
,
errorEndPos
>
endpos
?
errorEndPos
:
endpos
);
}
/** {@inheritDoc} */
@Override
protected
<
T
extends
JCTree
>
T
to
(
T
t
)
{
storeEnd
(
t
,
token
.
endPos
);
return
t
;
}
/** {@inheritDoc} */
@Override
protected
<
T
extends
JCTree
>
T
toP
(
T
t
)
{
storeEnd
(
t
,
S
.
prevToken
().
endPos
);
return
t
;
}
@Override
public
JCCompilationUnit
parseCompilationUnit
()
{
JCCompilationUnit
t
=
super
.
parseCompilationUnit
();
t
.
endPositions
=
endPositions
;
return
t
;
}
/** {@inheritDoc} */
@Override
JCExpression
parExpression
()
{
int
pos
=
token
.
pos
;
JCExpression
t
=
super
.
parExpression
();
return
toP
(
F
.
at
(
pos
).
Parens
(
t
));
}
/** {@inheritDoc} */
@Override
public
int
getEndPos
(
JCTree
tree
)
{
return
TreeInfo
.
getEndPos
(
tree
,
endPositions
);
}
public
int
getEndPos
(
JCTree
tree
);
/**
* Give an old tree and a new tree, the old tree will be replaced with
* the new tree, the position of the new tree will be that of the old
* tree.
* not exist.
* @param oldtree a JCTree to be replaced
* @param newtree a JCTree to be replaced with
* @return position of the old tree or Positions.NOPOS for non-existent mapping
*/
public
int
replaceTree
(
JCTree
oldtree
,
JCTree
newtree
);
}
src/share/classes/com/sun/tools/javac/parser/JavacParser.java
浏览文件 @
08a6b377
...
...
@@ -83,12 +83,16 @@ public class JavacParser implements Parser {
/** The name table. */
private
Names
names
;
/** End position mappings container */
private
final
AbstractEndPosTable
endPosTable
;
/** Construct a parser from a given scanner, tree factory and log.
*/
protected
JavacParser
(
ParserFactory
fac
,
Lexer
S
,
boolean
keepDocComments
,
boolean
keepLineMap
)
{
boolean
keepLineMap
,
boolean
keepEndPositions
)
{
this
.
S
=
S
;
nextToken
();
// prime the pump
this
.
F
=
fac
.
F
;
...
...
@@ -110,8 +114,14 @@ public class JavacParser implements Parser {
docComments
=
keepDocComments
?
new
HashMap
<
JCTree
,
String
>()
:
null
;
this
.
keepLineMap
=
keepLineMap
;
this
.
errorTree
=
F
.
Erroneous
();
endPosTable
=
newEndPosTable
(
keepEndPositions
);
}
protected
AbstractEndPosTable
newEndPosTable
(
boolean
keepEndPositions
)
{
return
keepEndPositions
?
new
SimpleEndPosTable
()
:
new
EmptyEndPosTable
();
}
/** Switch: Should generics be recognized?
*/
boolean
allowGenerics
;
...
...
@@ -389,37 +399,21 @@ public class JavacParser implements Parser {
/* -------- source positions ------- */
private
int
errorEndPos
=
-
1
;
private
void
setErrorEndPos
(
int
errPos
)
{
if
(
errPos
>
errorEndPos
)
errorEndPos
=
errPos
;
endPosTable
.
setErrorEndPos
(
errPos
);
}
pr
otected
int
getErrorEndPos
(
)
{
return
errorEndPos
;
pr
ivate
void
storeEnd
(
JCTree
tree
,
int
endpos
)
{
endPosTable
.
storeEnd
(
tree
,
endpos
)
;
}
/**
* Store ending position for a tree.
* @param tree The tree.
* @param endpos The ending position to associate with the tree.
*/
protected
void
storeEnd
(
JCTree
tree
,
int
endpos
)
{}
/**
* Store ending position for a tree. The ending position should
* be the ending position of the current token.
* @param t The tree.
*/
protected
<
T
extends
JCTree
>
T
to
(
T
t
)
{
return
t
;
}
private
<
T
extends
JCTree
>
T
to
(
T
t
)
{
return
endPosTable
.
to
(
t
);
}
/**
* Store ending position for a tree. The ending position should
* be greater of the ending position of the previous token and errorEndPos.
* @param t The tree.
*/
protected
<
T
extends
JCTree
>
T
toP
(
T
t
)
{
return
t
;
}
private
<
T
extends
JCTree
>
T
toP
(
T
t
)
{
return
endPosTable
.
toP
(
t
);
}
/** Get the start position for a tree node. The start position is
* defined to be the position of the first character of the first
...
...
@@ -439,7 +433,7 @@ public class JavacParser implements Parser {
* @param tree The tree node
*/
public
int
getEndPos
(
JCTree
tree
)
{
return
Position
.
NOPOS
;
return
endPosTable
.
getEndPos
(
tree
)
;
}
...
...
@@ -1362,7 +1356,7 @@ public class JavacParser implements Parser {
int
pos
=
token
.
pos
;
nextToken
();
accept
(
CLASS
);
if
(
token
.
pos
==
errorEndPos
)
{
if
(
token
.
pos
==
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
Name
name
=
null
;
if
(
token
.
kind
==
IDENTIFIER
)
{
...
...
@@ -1542,10 +1536,11 @@ public class JavacParser implements Parser {
/** ParExpression = "(" Expression ")"
*/
JCExpression
parExpression
()
{
int
pos
=
token
.
pos
;
accept
(
LPAREN
);
JCExpression
t
=
parseExpression
();
accept
(
RPAREN
);
return
t
;
return
t
oP
(
F
.
at
(
pos
).
Parens
(
t
))
;
}
/** Block = "{" BlockStatements "}"
...
...
@@ -1661,7 +1656,7 @@ public class JavacParser implements Parser {
// error recovery
if
(
token
.
pos
==
lastErrPos
)
return
stats
.
toList
();
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
skip
(
false
,
true
,
true
,
true
);
lastErrPos
=
token
.
pos
;
}
...
...
@@ -2270,7 +2265,7 @@ public class JavacParser implements Parser {
boolean
checkForImports
=
true
;
boolean
firstTypeDecl
=
true
;
while
(
token
.
kind
!=
EOF
)
{
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
skip
(
checkForImports
,
false
,
false
,
false
);
if
(
token
.
kind
==
EOF
)
...
...
@@ -2304,6 +2299,7 @@ public class JavacParser implements Parser {
toplevel
.
docComments
=
docComments
;
if
(
keepLineMap
)
toplevel
.
lineMap
=
S
.
getLineMap
();
toplevel
.
endPositions
=
this
.
endPosTable
;
return
toplevel
;
}
...
...
@@ -2494,7 +2490,7 @@ public class JavacParser implements Parser {
while
(
token
.
kind
!=
RBRACE
&&
token
.
kind
!=
EOF
)
{
defs
.
appendList
(
classOrInterfaceBodyDeclaration
(
enumName
,
false
));
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
skip
(
false
,
true
,
true
,
false
);
}
...
...
@@ -2556,7 +2552,7 @@ public class JavacParser implements Parser {
*/
List
<
JCTree
>
classOrInterfaceBody
(
Name
className
,
boolean
isInterface
)
{
accept
(
LBRACE
);
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
skip
(
false
,
true
,
false
,
false
);
if
(
token
.
kind
==
LBRACE
)
...
...
@@ -2565,7 +2561,7 @@ public class JavacParser implements Parser {
ListBuffer
<
JCTree
>
defs
=
new
ListBuffer
<
JCTree
>();
while
(
token
.
kind
!=
RBRACE
&&
token
.
kind
!=
EOF
)
{
defs
.
appendList
(
classOrInterfaceBodyDeclaration
(
className
,
isInterface
));
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
skip
(
false
,
true
,
true
,
false
);
}
...
...
@@ -2697,7 +2693,7 @@ public class JavacParser implements Parser {
defaultValue
=
null
;
}
accept
(
SEMI
);
if
(
token
.
pos
<=
errorEndPos
)
{
if
(
token
.
pos
<=
e
ndPosTable
.
e
rrorEndPos
)
{
// error recovery
skip
(
false
,
true
,
false
,
false
);
if
(
token
.
kind
==
LBRACE
)
{
...
...
@@ -3028,4 +3024,112 @@ public class JavacParser implements Parser {
allowTWR
=
true
;
}
}
/*
* a functional source tree and end position mappings
*/
protected
class
SimpleEndPosTable
extends
AbstractEndPosTable
{
private
final
Map
<
JCTree
,
Integer
>
endPosMap
;
SimpleEndPosTable
()
{
endPosMap
=
new
HashMap
<
JCTree
,
Integer
>();
}
protected
void
storeEnd
(
JCTree
tree
,
int
endpos
)
{
endPosMap
.
put
(
tree
,
errorEndPos
>
endpos
?
errorEndPos
:
endpos
);
}
protected
<
T
extends
JCTree
>
T
to
(
T
t
)
{
storeEnd
(
t
,
token
.
endPos
);
return
t
;
}
protected
<
T
extends
JCTree
>
T
toP
(
T
t
)
{
storeEnd
(
t
,
S
.
prevToken
().
endPos
);
return
t
;
}
public
int
getEndPos
(
JCTree
tree
)
{
Integer
value
=
endPosMap
.
get
(
tree
);
return
(
value
==
null
)
?
Position
.
NOPOS
:
value
;
}
public
int
replaceTree
(
JCTree
oldTree
,
JCTree
newTree
)
{
Integer
pos
=
endPosMap
.
remove
(
oldTree
);
if
(
pos
!=
null
)
{
endPosMap
.
put
(
newTree
,
pos
);
return
pos
;
}
return
Position
.
NOPOS
;
}
}
/*
* a default skeletal implementation without any mapping overhead.
*/
protected
class
EmptyEndPosTable
extends
AbstractEndPosTable
{
protected
void
storeEnd
(
JCTree
tree
,
int
endpos
)
{
/* empty */
}
protected
<
T
extends
JCTree
>
T
to
(
T
t
)
{
return
t
;
}
protected
<
T
extends
JCTree
>
T
toP
(
T
t
)
{
return
t
;
}
public
int
getEndPos
(
JCTree
tree
)
{
return
Position
.
NOPOS
;
}
public
int
replaceTree
(
JCTree
oldTree
,
JCTree
newTree
)
{
return
Position
.
NOPOS
;
}
}
protected
abstract
class
AbstractEndPosTable
implements
EndPosTable
{
/**
* Store the last error position.
*/
protected
int
errorEndPos
;
/**
* Store ending position for a tree, the value of which is the greater
* of last error position and the given ending position.
* @param tree The tree.
* @param endpos The ending position to associate with the tree.
*/
protected
abstract
void
storeEnd
(
JCTree
tree
,
int
endpos
);
/**
* Store current token's ending position for a tree, the value of which
* will be the greater of last error position and the ending position of
* the current token.
* @param t The tree.
*/
protected
abstract
<
T
extends
JCTree
>
T
to
(
T
t
);
/**
* Store current token's ending position for a tree, the value of which
* will be the greater of last error position and the ending position of
* the previous token.
* @param t The tree.
*/
protected
abstract
<
T
extends
JCTree
>
T
toP
(
T
t
);
/**
* Set the error position during the parsing phases, the value of which
* will be set only if it is greater than the last stored error position.
* @param errPos The error position
*/
protected
void
setErrorEndPos
(
int
errPos
)
{
if
(
errPos
>
errorEndPos
)
{
errorEndPos
=
errPos
;
}
}
}
}
src/share/classes/com/sun/tools/javac/parser/ParserFactory.java
浏览文件 @
08a6b377
/*
* Copyright (c) 1999, 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
1
, 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
...
...
@@ -75,10 +75,6 @@ public class ParserFactory {
public
Parser
newParser
(
CharSequence
input
,
boolean
keepDocComments
,
boolean
keepEndPos
,
boolean
keepLineMap
)
{
Lexer
lexer
=
scannerFactory
.
newScanner
(
input
,
keepDocComments
);
if
(
keepEndPos
)
{
return
new
EndPosParser
(
this
,
lexer
,
keepDocComments
,
keepLineMap
);
}
else
{
return
new
JavacParser
(
this
,
lexer
,
keepDocComments
,
keepLineMap
);
}
return
new
JavacParser
(
this
,
lexer
,
keepDocComments
,
keepLineMap
,
keepEndPos
);
}
}
src/share/classes/com/sun/tools/javac/tree/JCTree.java
浏览文件 @
08a6b377
...
...
@@ -39,6 +39,7 @@ import com.sun.tools.javac.util.List;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.code.Scope.*
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.source.tree.*
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
BoundKind
.*;
...
...
@@ -450,7 +451,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
}
// for default DiagnosticPosition
public
int
getEndPosition
(
Map
<
JCTree
,
Integer
>
endPosTable
)
{
public
int
getEndPosition
(
EndPosTable
endPosTable
)
{
return
TreeInfo
.
getEndPos
(
this
,
endPosTable
);
}
...
...
@@ -467,7 +468,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
* @param docComments A hashtable that stores all documentation comments
* indexed by the tree nodes they refer to.
* defined only if option -s is set.
* @param endPositions A
hashtable that stores
ending positions of source
* @param endPositions A
n object encapsulating
ending positions of source
* ranges indexed by the tree nodes they belong to.
* Defined only if option -Xjcov is set.
*/
...
...
@@ -481,7 +482,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public
StarImportScope
starImportScope
;
public
Position
.
LineMap
lineMap
=
null
;
public
Map
<
JCTree
,
String
>
docComments
=
null
;
public
Map
<
JCTree
,
Integer
>
endPositions
=
null
;
public
EndPosTable
endPositions
=
null
;
protected
JCCompilationUnit
(
List
<
JCAnnotation
>
packageAnnotations
,
JCExpression
pid
,
List
<
JCTree
>
defs
,
...
...
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
浏览文件 @
08a6b377
...
...
@@ -28,10 +28,10 @@ package com.sun.tools.javac.tree;
import
com.sun.source.tree.Tree
;
import
com.sun.tools.javac.comp.AttrContext
;
import
com.sun.tools.javac.comp.Env
;
import
java.util.Map
;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree.*
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Flags
.*;
...
...
@@ -346,17 +346,17 @@ public class TreeInfo {
/** The end position of given tree, given a table of end positions generated by the parser
*/
public
static
int
getEndPos
(
JCTree
tree
,
Map
<
JCTree
,
Integer
>
endPositions
)
{
public
static
int
getEndPos
(
JCTree
tree
,
EndPosTable
endPosTable
)
{
if
(
tree
==
null
)
return
Position
.
NOPOS
;
if
(
endPos
itions
==
null
)
{
if
(
endPos
Table
==
null
)
{
// fall back on limited info in the tree
return
endPos
(
tree
);
}
Integer
mapPos
=
endPositions
.
get
(
tree
);
if
(
mapPos
!=
null
)
int
mapPos
=
endPosTable
.
getEndPos
(
tree
);
if
(
mapPos
!=
Position
.
NOPOS
)
return
mapPos
;
switch
(
tree
.
getTag
())
{
...
...
@@ -364,7 +364,7 @@ public class TreeInfo {
case
SL_ASG:
case
SR_ASG:
case
USR_ASG:
case
PLUS_ASG:
case
MINUS_ASG:
case
MUL_ASG:
case
DIV_ASG:
case
MOD_ASG:
return
getEndPos
(((
JCAssignOp
)
tree
).
rhs
,
endPos
itions
);
return
getEndPos
(((
JCAssignOp
)
tree
).
rhs
,
endPos
Table
);
case
OR:
case
AND:
case
BITOR:
case
BITXOR:
case
BITAND:
case
EQ:
case
NE:
case
LT:
case
GT:
...
...
@@ -372,62 +372,62 @@ public class TreeInfo {
case
SR:
case
USR:
case
PLUS:
case
MINUS:
case
MUL:
case
DIV:
case
MOD:
return
getEndPos
(((
JCBinary
)
tree
).
rhs
,
endPos
itions
);
return
getEndPos
(((
JCBinary
)
tree
).
rhs
,
endPos
Table
);
case
CASE:
return
getEndPos
(((
JCCase
)
tree
).
stats
.
last
(),
endPos
itions
);
return
getEndPos
(((
JCCase
)
tree
).
stats
.
last
(),
endPos
Table
);
case
CATCH:
return
getEndPos
(((
JCCatch
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCCatch
)
tree
).
body
,
endPos
Table
);
case
CONDEXPR:
return
getEndPos
(((
JCConditional
)
tree
).
falsepart
,
endPos
itions
);
return
getEndPos
(((
JCConditional
)
tree
).
falsepart
,
endPos
Table
);
case
FORLOOP:
return
getEndPos
(((
JCForLoop
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCForLoop
)
tree
).
body
,
endPos
Table
);
case
FOREACHLOOP:
return
getEndPos
(((
JCEnhancedForLoop
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCEnhancedForLoop
)
tree
).
body
,
endPos
Table
);
case
IF:
{
JCIf
node
=
(
JCIf
)
tree
;
if
(
node
.
elsepart
==
null
)
{
return
getEndPos
(
node
.
thenpart
,
endPos
itions
);
return
getEndPos
(
node
.
thenpart
,
endPos
Table
);
}
else
{
return
getEndPos
(
node
.
elsepart
,
endPos
itions
);
return
getEndPos
(
node
.
elsepart
,
endPos
Table
);
}
}
case
LABELLED:
return
getEndPos
(((
JCLabeledStatement
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCLabeledStatement
)
tree
).
body
,
endPos
Table
);
case
MODIFIERS:
return
getEndPos
(((
JCModifiers
)
tree
).
annotations
.
last
(),
endPos
itions
);
return
getEndPos
(((
JCModifiers
)
tree
).
annotations
.
last
(),
endPos
Table
);
case
SYNCHRONIZED:
return
getEndPos
(((
JCSynchronized
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCSynchronized
)
tree
).
body
,
endPos
Table
);
case
TOPLEVEL:
return
getEndPos
(((
JCCompilationUnit
)
tree
).
defs
.
last
(),
endPos
itions
);
return
getEndPos
(((
JCCompilationUnit
)
tree
).
defs
.
last
(),
endPos
Table
);
case
TRY:
{
JCTry
node
=
(
JCTry
)
tree
;
if
(
node
.
finalizer
!=
null
)
{
return
getEndPos
(
node
.
finalizer
,
endPos
itions
);
return
getEndPos
(
node
.
finalizer
,
endPos
Table
);
}
else
if
(!
node
.
catchers
.
isEmpty
())
{
return
getEndPos
(
node
.
catchers
.
last
(),
endPos
itions
);
return
getEndPos
(
node
.
catchers
.
last
(),
endPos
Table
);
}
else
{
return
getEndPos
(
node
.
body
,
endPos
itions
);
return
getEndPos
(
node
.
body
,
endPos
Table
);
}
}
case
WILDCARD:
return
getEndPos
(((
JCWildcard
)
tree
).
inner
,
endPos
itions
);
return
getEndPos
(((
JCWildcard
)
tree
).
inner
,
endPos
Table
);
case
TYPECAST:
return
getEndPos
(((
JCTypeCast
)
tree
).
expr
,
endPos
itions
);
return
getEndPos
(((
JCTypeCast
)
tree
).
expr
,
endPos
Table
);
case
TYPETEST:
return
getEndPos
(((
JCInstanceOf
)
tree
).
clazz
,
endPos
itions
);
return
getEndPos
(((
JCInstanceOf
)
tree
).
clazz
,
endPos
Table
);
case
POS:
case
NEG:
case
NOT:
case
COMPL:
case
PREINC:
case
PREDEC:
return
getEndPos
(((
JCUnary
)
tree
).
arg
,
endPos
itions
);
return
getEndPos
(((
JCUnary
)
tree
).
arg
,
endPos
Table
);
case
WHILELOOP:
return
getEndPos
(((
JCWhileLoop
)
tree
).
body
,
endPos
itions
);
return
getEndPos
(((
JCWhileLoop
)
tree
).
body
,
endPos
Table
);
case
ERRONEOUS:
{
JCErroneous
node
=
(
JCErroneous
)
tree
;
if
(
node
.
errs
!=
null
&&
node
.
errs
.
nonEmpty
())
return
getEndPos
(
node
.
errs
.
last
(),
endPos
itions
);
return
getEndPos
(
node
.
errs
.
last
(),
endPos
Table
);
}
}
return
Position
.
NOPOS
;
...
...
@@ -444,7 +444,7 @@ public class TreeInfo {
public
JCTree
getTree
()
{
return
tree
;
}
public
int
getStartPosition
()
{
return
TreeInfo
.
getStartPos
(
tree
);
}
public
int
getPreferredPosition
()
{
return
endPos
;
}
public
int
getEndPosition
(
Map
<
JCTree
,
Integer
>
endPosTable
)
{
public
int
getEndPosition
(
EndPosTable
endPosTable
)
{
return
TreeInfo
.
getEndPos
(
tree
,
endPosTable
);
}
};
...
...
src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java
浏览文件 @
08a6b377
/*
* Copyright (c) 1999, 20
08
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 20
11
, 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
...
...
@@ -32,6 +32,7 @@ import java.util.Map;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
static
com
.
sun
.
tools
.
javac
.
util
.
LayoutCharacters
.*;
...
...
@@ -128,11 +129,11 @@ public class DiagnosticSource {
}
}
public
Map
<
JCTree
,
Integer
>
getEndPosTable
()
{
public
EndPosTable
getEndPosTable
()
{
return
endPosTable
;
}
public
void
setEndPosTable
(
Map
<
JCTree
,
Integer
>
t
)
{
public
void
setEndPosTable
(
EndPosTable
t
)
{
if
(
endPosTable
!=
null
&&
endPosTable
!=
t
)
throw
new
IllegalStateException
(
"endPosTable already set"
);
endPosTable
=
t
;
...
...
@@ -199,7 +200,7 @@ public class DiagnosticSource {
/** The underlying file object. */
protected
JavaFileObject
fileObject
;
protected
Map
<
JCTree
,
Integer
>
endPosTable
;
protected
EndPosTable
endPosTable
;
/** A soft reference to the content of the file object. */
protected
SoftReference
<
char
[]>
refBuf
;
...
...
src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
浏览文件 @
08a6b377
...
...
@@ -35,6 +35,7 @@ import javax.tools.JavaFileObject;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
static
com
.
sun
.
tools
.
javac
.
util
.
JCDiagnostic
.
DiagnosticType
.*;
...
...
@@ -313,7 +314,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
/** If there is a tree node, and if endPositions are available, get
* the end position of the tree node. Otherwise, just returns the
* same as getPreferredPosition(). */
int
getEndPosition
(
Map
<
JCTree
,
Integer
>
endPosTable
);
int
getEndPosition
(
EndPosTable
endPosTable
);
}
/**
...
...
@@ -337,7 +338,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
return
pos
;
}
public
int
getEndPosition
(
Map
<
JCTree
,
Integer
>
endPosTable
)
{
public
int
getEndPosition
(
EndPosTable
endPosTable
)
{
return
pos
;
}
...
...
src/share/classes/com/sun/tools/javac/util/Log.java
浏览文件 @
08a6b377
...
...
@@ -38,6 +38,7 @@ import javax.tools.JavaFileObject;
import
com.sun.tools.javac.api.DiagnosticFormatter
;
import
com.sun.tools.javac.main.OptionName
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticType
;
...
...
@@ -250,9 +251,9 @@ public class Log extends AbstractLog {
return
diagListener
!=
null
;
}
public
void
setEndPosTable
(
JavaFileObject
name
,
Map
<
JCTree
,
Integer
>
t
able
)
{
public
void
setEndPosTable
(
JavaFileObject
name
,
EndPosTable
endPosT
able
)
{
name
.
getClass
();
// null check
getSource
(
name
).
setEndPosTable
(
t
able
);
getSource
(
name
).
setEndPosTable
(
endPosT
able
);
}
/** Return current sourcefile.
...
...
test/tools/javac/6304921/TestLog.java
浏览文件 @
08a6b377
/*
* Copyright (c) 2005, 201
0
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 201
1
, 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
...
...
@@ -33,6 +33,7 @@ import java.net.URI;
import
javax.tools.JavaFileObject
;
import
javax.tools.SimpleJavaFileObject
;
import
com.sun.tools.javac.file.JavacFileManager
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.parser.Parser
;
import
com.sun.tools.javac.parser.ParserFactory
;
import
com.sun.tools.javac.tree.JCTree
;
...
...
@@ -97,9 +98,9 @@ public class TestLog
}
private
static
class
LogTester
extends
TreeScanner
{
LogTester
(
Log
log
,
java
.
util
.
Map
<
JCTree
,
Integer
>
endPositions
)
{
LogTester
(
Log
log
,
EndPosTable
endPosTable
)
{
this
.
log
=
log
;
this
.
endPos
itions
=
endPositions
;
this
.
endPos
Table
=
endPosTable
;
}
public
void
visitIf
(
JCTree
.
JCIf
tree
)
{
...
...
@@ -117,7 +118,7 @@ public class TestLog
}
private
Log
log
;
private
java
.
util
.
Map
<
JCTree
,
Integer
>
endPositions
;
private
EndPosTable
endPosTable
;
}
private
static
class
StringJavaFileObject
extends
SimpleJavaFileObject
{
...
...
test/tools/javac/failover/CheckAttributedTree.java
浏览文件 @
08a6b377
...
...
@@ -55,12 +55,8 @@ import java.io.PrintStream;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.tools.Diagnostic
;
import
javax.tools.DiagnosticListener
;
import
javax.tools.JavaFileObject
;
...
...
@@ -72,8 +68,8 @@ import com.sun.source.util.TaskListener;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.code.Symbol
;
import
com.sun.tools.javac.code.Type
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.JCTree.JCClassDecl
;
import
com.sun.tools.javac.tree.JCTree.JCCompilationUnit
;
import
com.sun.tools.javac.tree.JCTree.JCImport
;
import
com.sun.tools.javac.tree.TreeInfo
;
...
...
@@ -421,7 +417,7 @@ public class CheckAttributedTree {
}
JavaFileObject
sourcefile
;
Map
<
JCTree
,
Integer
>
endPosTable
;
EndPosTable
endPosTable
;
Info
encl
;
}
...
...
@@ -437,7 +433,7 @@ public class CheckAttributedTree {
end
=
Integer
.
MAX_VALUE
;
}
Info
(
JCTree
tree
,
Map
<
JCTree
,
Integer
>
endPosTable
)
{
Info
(
JCTree
tree
,
EndPosTable
endPosTable
)
{
this
.
tree
=
tree
;
tag
=
tree
.
getTag
();
start
=
TreeInfo
.
getStartPos
(
tree
);
...
...
test/tools/javac/tree/TreePosTest.java
浏览文件 @
08a6b377
...
...
@@ -73,6 +73,7 @@ import com.sun.source.tree.CompilationUnitTree;
import
com.sun.source.util.JavacTask
;
import
com.sun.tools.javac.api.JavacTool
;
import
com.sun.tools.javac.code.Flags
;
import
com.sun.tools.javac.parser.EndPosTable
;
import
com.sun.tools.javac.tree.JCTree
;
import
com.sun.tools.javac.tree.JCTree.JCCompilationUnit
;
import
com.sun.tools.javac.tree.JCTree.JCNewClass
;
...
...
@@ -435,7 +436,7 @@ public class TreePosTest {
}
JavaFileObject
sourcefile
;
Map
<
JCTree
,
Integer
>
endPosTable
;
EndPosTable
endPosTable
;
Info
encl
;
}
...
...
@@ -452,7 +453,7 @@ public class TreePosTest {
end
=
Integer
.
MAX_VALUE
;
}
Info
(
JCTree
tree
,
Map
<
JCTree
,
Integer
>
endPosTable
)
{
Info
(
JCTree
tree
,
EndPosTable
endPosTable
)
{
this
.
tree
=
tree
;
tag
=
tree
.
getTag
();
start
=
TreeInfo
.
getStartPos
(
tree
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录