aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/compiler
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-20 23:43:39 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-20 23:43:39 +0000
commit1a1b9d2feccc15e1bd1a26ff7a7709630d478fe8 (patch)
treebb44f7e1845acf7976503f3cd0f25f17ea476f37 /src/main/javassist/compiler
parent8e20f83d119aef0c906488cd87c7f665fbc3daf6 (diff)
downloadjavassist-1a1b9d2feccc15e1bd1a26ff7a7709630d478fe8.tar.gz
javassist-1a1b9d2feccc15e1bd1a26ff7a7709630d478fe8.zip
Fixed a bug of the token analyzer (double constant).
Improved compilation speed. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@58 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler')
-rw-r--r--src/main/javassist/compiler/Lex.java9
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java36
-rw-r--r--src/main/javassist/compiler/MemberResolver.java32
3 files changed, 58 insertions, 19 deletions
diff --git a/src/main/javassist/compiler/Lex.java b/src/main/javassist/compiler/Lex.java
index baf4742e..76a22fdf 100644
--- a/src/main/javassist/compiler/Lex.java
+++ b/src/main/javassist/compiler/Lex.java
@@ -293,7 +293,8 @@ public class Lex implements TokenId {
token.doubleValue = (double)value;
return FloatConstant;
}
- else if (c2 == 'E' || c2 == 'e' || c2 == '.') {
+ else if (c2 == 'E' || c2 == 'e'
+ || c2 == 'D' || c2 == 'd' || c2 == '.') {
StringBuffer tbuf = textBuffer;
tbuf.setLength(0);
tbuf.append(value);
@@ -308,7 +309,7 @@ public class Lex implements TokenId {
}
private int readDouble(StringBuffer sbuf, int c, Token token) {
- if (c != 'E' && c != 'e') {
+ if (c != 'E' && c != 'e' && c != 'D' && c != 'd') {
sbuf.append((char)c);
for (;;) {
c = getc();
@@ -343,7 +344,9 @@ public class Lex implements TokenId {
if (c == 'F' || c == 'f')
return FloatConstant;
else {
- ungetc(c);
+ if (c != 'D' && c != 'd')
+ ungetc(c);
+
return DoubleConstant;
}
}
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java
index 8499dfb0..2d1a747a 100644
--- a/src/main/javassist/compiler/MemberCodeGen.java
+++ b/src/main/javassist/compiler/MemberCodeGen.java
@@ -283,6 +283,7 @@ public class MemberCodeGen extends CodeGen {
exprType = CLASS;
arrayDim = 0;
className = nfe.getField(); // JVM-internal
+ resolver.recordPackage(className);
isStatic = true;
}
@@ -594,10 +595,9 @@ public class MemberCodeGen extends CodeGen {
/* This method also returns a value in resultStatic.
*/
protected CtField fieldAccess(ASTree expr) throws CompileError {
- CtField f = null;
- boolean is_static = false;
if (expr instanceof Member) {
String name = ((Member)expr).get();
+ CtField f = null;
try {
f = thisClass.getField(name);
}
@@ -606,35 +606,47 @@ public class MemberCodeGen extends CodeGen {
throw new NoFieldException(name, expr);
}
- is_static = Modifier.isStatic(f.getModifiers());
+ boolean is_static = Modifier.isStatic(f.getModifiers());
if (!is_static)
if (inStaticMethod)
throw new CompileError(
"not available in a static method: " + name);
else
bytecode.addAload(0); // this
+
+ resultStatic = is_static;
+ return f;
}
else if (expr instanceof Expr) {
Expr e = (Expr)expr;
int op = e.getOperator();
if (op == MEMBER) {
// static member by # (extension by Javassist)
- f = resolver.lookupField(((Symbol)e.oprand1()).get(),
+ CtField f = resolver.lookupField(((Symbol)e.oprand1()).get(),
(Symbol)e.oprand2());
- is_static = true;
+ resultStatic = true;
+ return f;
}
else if (op == '.') {
+ CtField f = null;
try {
e.oprand1().accept(this);
+ /* Don't call lookupFieldByJvmName2().
+ * The left operand of . is not a class name but
+ * a normal expression.
+ */
if (exprType == CLASS && arrayDim == 0)
f = resolver.lookupFieldByJvmName(className,
(Symbol)e.oprand2());
else
badLvalue();
- is_static = Modifier.isStatic(f.getModifiers());
+ boolean is_static = Modifier.isStatic(f.getModifiers());
if (is_static)
bytecode.addOpcode(POP);
+
+ resultStatic = is_static;
+ return f;
}
catch (NoFieldException nfe) {
if (nfe.getExpr() != e.oprand1())
@@ -645,9 +657,11 @@ public class MemberCodeGen extends CodeGen {
* lookupFieldByJvmName2() throws NoFieldException.
*/
Symbol fname = (Symbol)e.oprand2();
- f = resolver.lookupFieldByJvmName2(nfe.getField(),
- fname, expr);
- is_static = true;
+ String cname = nfe.getField();
+ f = resolver.lookupFieldByJvmName2(cname, fname, expr);
+ resolver.recordPackage(cname);
+ resultStatic = true;
+ return f;
}
}
else
@@ -656,8 +670,8 @@ public class MemberCodeGen extends CodeGen {
else
badLvalue();
- resultStatic = is_static;
- return f;
+ resultStatic = false;
+ return null; // never reach
}
private static void badLvalue() throws CompileError {
diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java
index 6e9c33c1..f266ddf8 100644
--- a/src/main/javassist/compiler/MemberResolver.java
+++ b/src/main/javassist/compiler/MemberResolver.java
@@ -35,6 +35,22 @@ public class MemberResolver implements TokenId {
throw new CompileError("fatal");
}
+ /**
+ * @param jvmClassName a class name. Not a package name.
+ */
+ public void recordPackage(String jvmClassName) {
+ String classname = jvmToJavaName(jvmClassName);
+ for (;;) {
+ int i = classname.lastIndexOf('.');
+ if (i > 0) {
+ classname = classname.substring(0, i);
+ classPool.recordInvalidClassName(classname);
+ }
+ else
+ break;
+ }
+ }
+
public static class Method {
public CtClass declaring;
public MethodInfo info;
@@ -336,12 +352,18 @@ public class MemberResolver implements TokenId {
return lookupClass0(name, notCheckInner);
}
catch (NotFoundException e) {}
-
- try {
- if (name.indexOf('.') < 0)
- return classPool.get("java.lang." + name);
+ if (name.indexOf('.') < 0) {
+ String jlangName = "java.lang." + name;
+ try {
+ CtClass cc = classPool.get(jlangName);
+ // if java.lang... is found, then
+ classPool.recordInvalidClassName(name);
+ return cc;
+ }
+ catch (NotFoundException e) {
+ classPool.recordInvalidClassName(jlangName);
+ }
}
- catch (NotFoundException e) {}
throw new CompileError("no such class: " + name);
}