Here are the examples of the java api com.feilong.lib.javassist.compiler.ast.ASTList taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
50 Examples
19
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* Converts a clreplaced name into a JVM-internal representation.
*
* It may also expand a simple clreplaced name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
protected String resolveClreplacedName(ASTList name) throws CompileError {
return resolver.resolveClreplacedName(name);
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* member.modifiers
* : ( FINAL | SYNCHRONIZED | ABSTRACT
* | PUBLIC | PROTECTED | PRIVATE | STATIC
* | VOLATILE | TRANSIENT | STRICT )*
*/
private ASTList parseMemberMods() {
int t;
ASTList list = null;
while (true) {
t = lex.lookAhead();
if (t == ABSTRACT || t == FINAL || t == PUBLIC || t == PROTECTED || t == PRIVATE || t == SYNCHRONIZED || t == STATIC || t == VOLATILE || t == TRANSIENT || t == STRICT) {
list = new ASTList(new Keyword(lex.get()), list);
} else {
break;
}
}
return list;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* clreplaced.type : Identifier ( "." Identifier )*
*/
private ASTList parseClreplacedType(SymbolTable tbl) throws CompileError {
ASTList list = null;
for (; ; ) {
if (lex.get() != Identifier) {
throw new SyntaxError(lex);
}
list = ASTList.append(list, new Symbol(lex.getString()));
if (lex.lookAhead() == '.') {
lex.get();
} else {
break;
}
}
return list;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* array.size : [ array.index ]*
*/
private ASTList parseArraySize(SymbolTable tbl) throws CompileError {
ASTList list = null;
while (lex.lookAhead() == '[') {
list = ASTList.append(list, parseArrayIndex(tbl));
}
return list;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* member.declaration
* : method.declaration | field.declaration
*/
public ASTList parseMember(SymbolTable tbl) throws CompileError {
ASTList mem = parseMember1(tbl);
if (mem instanceof MethodDecl) {
return parseMethod2(tbl, (MethodDecl) mem);
}
return mem;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* declaration.or.expression
* : [ FINAL ] built-in-type array.dimension declarators
* | [ FINAL ] clreplaced.type array.dimension declarators
* | expression ';'
* | expr.list ';' if exprList is true
*
* Note: FINAL is currently ignored. This must be fixed
* in future.
*/
private Stmnt parseDeclarationOrExpression(SymbolTable tbl, boolean exprList) throws CompileError {
int t = lex.lookAhead();
while (t == FINAL) {
lex.get();
t = lex.lookAhead();
}
if (isBuiltinType(t)) {
t = lex.get();
int dim = parseArrayDimension();
return parseDeclarators(tbl, new Declarator(t, dim));
} else if (t == Identifier) {
int i = nextIsClreplacedType(0);
if (i >= 0) {
if (lex.lookAhead(i) == Identifier) {
ASTList name = parseClreplacedType(tbl);
int dim = parseArrayDimension();
return parseDeclarators(tbl, new Declarator(name, dim));
}
}
}
Stmnt expr;
if (exprList) {
expr = parseExprList(tbl);
} else {
expr = new Stmnt(EXPR, parseExpression(tbl));
}
if (lex.get() != ';') {
throw new CompileError("; is missing", lex);
}
return expr;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* cast.expr : "(" builtin.type ("[" "]")* ")" unary.expr
* | "(" clreplaced.type ("[" "]")* ")" unary.expr2
*
* unary.expr2 is a unary.expr beginning with "(", NULL, StringL,
* Identifier, THIS, SUPER, or NEW.
*
* Either "(int.clreplaced)" or "(String[].clreplaced)" is a not cast expression.
*/
private ASTree parseCast(SymbolTable tbl) throws CompileError {
int t = lex.lookAhead(1);
if (isBuiltinType(t) && nextIsBuiltinCast()) {
// '('
lex.get();
// primitive type
lex.get();
int dim = parseArrayDimension();
if (lex.get() != ')') {
throw new CompileError(") is missing", lex);
}
return new CastExpr(t, dim, parseUnaryExpr(tbl));
} else if (t == Identifier && nextIsClreplacedCast()) {
// '('
lex.get();
ASTList name = parseClreplacedType(tbl);
int dim = parseArrayDimension();
if (lex.get() != ')') {
throw new CompileError(") is missing", lex);
}
return new CastExpr(name, dim, parseUnaryExpr(tbl));
} else {
return parsePostfix(tbl);
}
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* argument.list : "(" [ expression [ "," expression ]* ] ")"
*/
private ASTList parseArgumentList(SymbolTable tbl) throws CompileError {
if (lex.get() != '(') {
throw new CompileError("( is missing", lex);
}
ASTList list = null;
if (lex.lookAhead() != ')') {
for (; ; ) {
list = ASTList.append(list, parseExpression(tbl));
if (lex.lookAhead() == ',') {
lex.get();
} else {
break;
}
}
}
if (lex.get() != ')') {
throw new CompileError(") is missing", lex);
}
return list;
}
19
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* formal.type : ( build-in-type | clreplaced.type ) array.dimension
*/
private Declarator parseFormalType(SymbolTable tbl) throws CompileError {
int t = lex.lookAhead();
if (isBuiltinType(t) || t == VOID) {
// primitive type
lex.get();
int dim = parseArrayDimension();
return new Declarator(t, dim);
}
ASTList name = parseClreplacedType(tbl);
int dim = parseArrayDimension();
return new Declarator(name, dim);
}
19
Source : MemberResolver.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* Converts a clreplaced name into a JVM-internal representation.
*
* It may also expand a simple clreplaced name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
public String resolveClreplacedName(ASTList name) throws CompileError {
if (name == null) {
return null;
}
return javaToJvmName(lookupClreplacedByName(name).getName());
}
19
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* To support $cflow().
*/
protected void atCflow(ASTList cname) throws CompileError {
exprType = INT;
arrayDim = 0;
clreplacedName = null;
}
18
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public int getMethodArgsLength(ASTList args) {
return ASTList.length(args);
}
18
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* new.expr : clreplaced.type "(" argument.list ")"
* | clreplaced.type array.size [ array.initializer ]
* | primitive.type array.size [ array.initializer ]
*/
private NewExpr parseNew(SymbolTable tbl) throws CompileError {
ArrayInit init = null;
int t = lex.lookAhead();
if (isBuiltinType(t)) {
lex.get();
ASTList size = parseArraySize(tbl);
if (lex.lookAhead() == '{') {
init = parseArrayInitializer(tbl);
}
return new NewExpr(t, size, init);
} else if (t == Identifier) {
ASTList name = parseClreplacedType(tbl);
t = lex.lookAhead();
if (t == '(') {
ASTList args = parseArgumentList(tbl);
return new NewExpr(name, args);
} else if (t == '[') {
ASTList size = parseArraySize(tbl);
if (lex.lookAhead() == '{') {
init = parseArrayInitializer(tbl);
}
return NewExpr.makeObjectArray(name, size, init);
}
}
throw new SyntaxError(lex);
}
18
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
private ASTree parseInstanceOf(SymbolTable tbl, ASTree expr) throws CompileError {
int t = lex.lookAhead();
if (isBuiltinType(t)) {
// primitive type
lex.get();
int dim = parseArrayDimension();
return new InstanceOfExpr(t, dim, expr);
}
ASTList name = parseClreplacedType(tbl);
int dim = parseArrayDimension();
return new InstanceOfExpr(name, dim, expr);
}
18
Source : MemberResolver.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public CtClreplaced lookupClreplacedByName(ASTList name) throws CompileError {
return lookupClreplaced(Declarator.astToClreplacedName(name, '.'), false);
}
18
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* atMethodCallCore() is also called by doit() in NewExpr.ProceedForNew
*
* @param targetClreplaced the clreplaced at which method lookup starts.
*
* @param found not null if the method look has been already done.
*/
public void atMethodCallCore(CtClreplaced targetClreplaced, String mname, ASTList args, boolean isStatic, boolean isSpecial, int aload0pos, MemberResolver.Method found) throws CompileError {
int nargs = getMethodArgsLength(args);
int[] types = new int[nargs];
int[] dims = new int[nargs];
String[] cnames = new String[nargs];
if (!isStatic && found != null && found.isStatic()) {
bytecode.addOpcode(POP);
isStatic = true;
}
@SuppressWarnings("unused")
int stack = bytecode.getStackDepth();
// generate code for evaluating arguments.
atMethodArgs(args, types, dims, cnames);
if (found == null) {
found = resolver.lookupMethod(targetClreplaced, thisClreplaced, thisMethod, mname, types, dims, cnames);
}
if (found == null) {
String msg;
if (mname.equals(MethodInfo.nameInit)) {
msg = "constructor not found";
} else {
msg = "Method " + mname + " not found in " + targetClreplaced.getName();
}
throw new CompileError(msg);
}
atMethodCallCore2(targetClreplaced, mname, isStatic, isSpecial, aload0pos, found);
}
18
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* Converts a clreplaced name into a JVM-internal representation.
*
* It may also expand a simple clreplaced name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
@Override
protected String resolveClreplacedName(ASTList name) throws CompileError {
return resolver.resolveClreplacedName(name);
}
18
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* To support $cflow().
*/
protected void atCflow(ASTList cname) throws CompileError {
StringBuffer sbuf = new StringBuffer();
if (cname == null || cname.tail() != null) {
throw new CompileError("bad " + cflowName);
}
makeCflowName(sbuf, cname.head());
String name = sbuf.toString();
Object[] names = resolver.getClreplacedPool().lookupCflow(name);
if (names == null) {
throw new CompileError("no such " + cflowName + ": " + name);
}
bytecode.addGetstatic((String) names[0], (String) names[1], "Ljavreplacedist/runtime/Cflow;");
bytecode.addInvokevirtual(com.feilong.lib.javreplacedist.runtime.Cflow.clreplaced.getName(), "value", "()I");
exprType = INT;
arrayDim = 0;
clreplacedName = null;
}
17
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* try.statement
* : TRY block.statement
* [ CATCH "(" clreplaced.type Identifier ")" block.statement ]*
* [ FINALLY block.statement ]*
*/
private Stmnt parseTry(SymbolTable tbl) throws CompileError {
// TRY
lex.get();
Stmnt block = parseBlock(tbl);
ASTList catchList = null;
while (lex.lookAhead() == CATCH) {
// CATCH
lex.get();
if (lex.get() != '(') {
throw new SyntaxError(lex);
}
SymbolTable tbl2 = new SymbolTable(tbl);
Declarator d = parseFormalParam(tbl2);
if (d.getArrayDim() > 0 || d.getType() != CLreplaced) {
throw new SyntaxError(lex);
}
if (lex.get() != ')') {
throw new SyntaxError(lex);
}
Stmnt b = parseBlock(tbl2);
catchList = ASTList.append(catchList, new Pair(d, b));
}
Stmnt finallyBlock = null;
if (lex.lookAhead() == FINALLY) {
// FINALLY
lex.get();
finallyBlock = parseBlock(tbl);
}
return Stmnt.make(TRY, block, catchList, finallyBlock);
}
17
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* A method body is not parsed.
*/
public ASTList parseMember1(SymbolTable tbl) throws CompileError {
ASTList mods = parseMemberMods();
Declarator d;
boolean isConstructor = false;
if (lex.lookAhead() == Identifier && lex.lookAhead(1) == '(') {
d = new Declarator(VOID, 0);
isConstructor = true;
} else {
d = parseFormalType(tbl);
}
if (lex.get() != Identifier) {
throw new SyntaxError(lex);
}
String name;
if (isConstructor) {
name = MethodDecl.initName;
} else {
name = lex.getString();
}
d.setVariable(new Symbol(name));
if (isConstructor || lex.lookAhead() == '(') {
return parseMethod1(tbl, isConstructor, mods, d);
}
return parseField(tbl, mods, d);
}
17
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* field.declaration
* : member.modifiers
* formal.type Identifier
* [ "=" expression ] ";"
*/
private FieldDecl parseField(SymbolTable tbl, ASTList mods, Declarator d) throws CompileError {
ASTree expr = null;
if (lex.lookAhead() == '=') {
lex.get();
expr = parseExpression(tbl);
}
int c = lex.get();
if (c == ';') {
return new FieldDecl(mods, new ASTList(d, new ASTList(expr)));
} else if (c == ',') {
throw new CompileError("only one field can be declared in one declaration", lex);
} else {
throw new SyntaxError(lex);
}
}
17
Source : Parser.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* method.declaration
* : member.modifiers
* [ formal.type ]
* Identifier "(" [ formal.parameter ( "," formal.parameter )* ] ")"
* array.dimension
* [ THROWS clreplaced.type ( "," clreplaced.type ) ]
* ( block.statement | ";" )
*
* Note that a method body is not parsed.
*/
private MethodDecl parseMethod1(SymbolTable tbl, boolean isConstructor, ASTList mods, Declarator d) throws CompileError {
if (lex.get() != '(') {
throw new SyntaxError(lex);
}
ASTList parms = null;
if (lex.lookAhead() != ')') {
while (true) {
parms = ASTList.append(parms, parseFormalParam(tbl));
int t = lex.lookAhead();
if (t == ',') {
lex.get();
} else if (t == ')') {
break;
}
}
}
// ')'
lex.get();
d.addArrayDim(parseArrayDimension());
if (isConstructor && d.getArrayDim() > 0) {
throw new SyntaxError(lex);
}
ASTList throwsList = null;
if (lex.lookAhead() == THROWS) {
lex.get();
while (true) {
throwsList = ASTList.append(throwsList, parseClreplacedType(tbl));
if (lex.lookAhead() == ',') {
lex.get();
} else {
break;
}
}
}
return new MethodDecl(mods, new ASTList(d, ASTList.make(parms, throwsList, null)));
}
17
Source : MemberResolver.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public static int getModifiers(ASTList mods) {
int m = 0;
while (mods != null) {
Keyword k = (Keyword) mods.head();
mods = mods.tail();
switch(k.get()) {
case STATIC:
m |= Modifier.STATIC;
break;
case FINAL:
m |= Modifier.FINAL;
break;
case SYNCHRONIZED:
m |= Modifier.SYNCHRONIZED;
break;
case ABSTRACT:
m |= Modifier.ABSTRACT;
break;
case PUBLIC:
m |= Modifier.PUBLIC;
break;
case PROTECTED:
m |= Modifier.PROTECTED;
break;
case PRIVATE:
m |= Modifier.PRIVATE;
break;
case VOLATILE:
m |= Modifier.VOLATILE;
break;
case TRANSIENT:
m |= Modifier.TRANSIENT;
break;
case STRICT:
m |= Modifier.STRICT;
break;
}
}
return m;
}
17
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public CtClreplaced[] makeThrowsList(MethodDecl md) throws CompileError {
CtClreplaced[] clist;
ASTList list = md.getThrows();
if (list == null) {
return null;
}
int i = 0;
clist = new CtClreplaced[list.length()];
while (list != null) {
clist[i++] = resolver.lookupClreplacedByName((ASTList) list.head());
list = list.tail();
}
return clist;
}
17
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public CtClreplaced[] makeParamList(MethodDecl md) throws CompileError {
CtClreplaced[] params;
ASTList plist = md.getParams();
if (plist == null) {
params = new CtClreplaced[0];
} else {
int i = 0;
params = new CtClreplaced[plist.length()];
while (plist != null) {
params[i++] = resolver.lookupClreplaced((Declarator) plist.head());
plist = plist.tail();
}
}
return params;
}
17
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* To support $$. ($$) is equivalent to ($1, ..., $n).
* It can be used only as a parameter list of method call.
*/
public boolean isParamListName(ASTList args) {
if (codeGen.paramTypeList != null && args != null && args.tail() == null) {
ASTree left = args.head();
return (left instanceof Member && ((Member) left).get().equals(codeGen.paramListName));
}
return false;
}
17
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* called by Javac#recordSpecialProceed().
*/
void compileInvokeSpecial(ASTree target, String clreplacedname, String methodname, String descriptor, ASTList args) throws CompileError {
target.accept(this);
int nargs = getMethodArgsLength(args);
atMethodArgs(args, new int[nargs], new int[nargs], new String[nargs]);
setReturnType(descriptor);
addNullIfVoid();
}
17
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* public void atMethodArgs(ASTList args, int[] types, int[] dims,
* String[] cnames) throws CompileError {
* if (!isParamListName(args)) {
* super.atMethodArgs(args, types, dims, cnames);
* return;
* }
*
* CtClreplaced[] params = paramTypeList;
* if (params == null)
* return;
*
* int n = params.length;
* int regno = indexOfParam1();
* for (int i = 0; i < n; ++i) {
* CtClreplaced p = params[i];
* regno += bytecode.addLoad(regno, p);
* setType(p);
* types[i] = exprType;
* dims[i] = arrayDim;
* cnames[i] = clreplacedName;
* }
* }
*/
/*
* called by Javac#recordSpecialProceed().
*/
void compileInvokeSpecial(ASTree target, int methodIndex, String descriptor, ASTList args) throws CompileError {
target.accept(this);
int nargs = getMethodArgsLength(args);
atMethodArgs(args, new int[nargs], new int[nargs], new String[nargs]);
bytecode.addInvokespecial(methodIndex, descriptor);
setReturnType(descriptor, false, false);
addNullIfVoid();
}
17
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* To support $$. ($$) is equivalent to ($1, ..., $n).
* It can be used only as a parameter list of method call.
*/
public boolean isParamListName(ASTList args) {
if (paramTypeList != null && args != null && args.tail() == null) {
ASTree left = args.head();
return (left instanceof Member && ((Member) left).get().equals(paramListName));
}
return false;
}
16
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
protected void atMultiNewArray(int type, ASTList clreplacedname, ASTList size) throws CompileError {
@SuppressWarnings("unused")
int count, dim;
dim = size.length();
for (count = 0; size != null; size = size.tail()) {
ASTree s = size.head();
if (s == null) {
// int[][][] a = new int[3][4][];
break;
}
++count;
s.accept(this);
}
exprType = type;
arrayDim = dim;
if (type == CLreplaced) {
clreplacedName = resolveClreplacedName(clreplacedname);
} else {
clreplacedName = null;
}
}
16
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/**
* @return a pair of the clreplaced declaring the invoked method
* and the MethodInfo of that method. Never null.
*/
public MemberResolver.Method atMethodCallCore(CtClreplaced targetClreplaced, String mname, ASTList args) throws CompileError {
int nargs = getMethodArgsLength(args);
int[] types = new int[nargs];
int[] dims = new int[nargs];
String[] cnames = new String[nargs];
atMethodArgs(args, types, dims, cnames);
MemberResolver.Method found = resolver.lookupMethod(targetClreplaced, thisClreplaced, thisMethod, mname, types, dims, cnames);
if (found == null) {
String clazz = targetClreplaced.getName();
String signature = argTypesToString(types, dims, cnames);
String msg;
if (mname.equals(MethodInfo.nameInit)) {
msg = "cannot find constructor " + clazz + signature;
} else {
msg = mname + signature + " not found in " + clazz;
}
throw new CompileError(msg);
}
String desc = found.info.getDescriptor();
setReturnType(desc);
return found;
}
16
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public void atMethodArgs(ASTList args, int[] types, int[] dims, String[] cnames) throws CompileError {
int i = 0;
while (args != null) {
ASTree a = args.head();
a.accept(this);
types[i] = exprType;
dims[i] = arrayDim;
cnames[i] = clreplacedName;
++i;
args = args.tail();
}
}
16
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
protected void atMultiNewArray(int type, ASTList clreplacedname, ASTList size) throws CompileError {
int count, dim;
dim = size.length();
for (count = 0; size != null; size = size.tail()) {
ASTree s = size.head();
if (s == null) {
// int[][][] a = new int[3][4][];
break;
}
++count;
s.accept(this);
if (exprType != INT) {
throw new CompileError("bad type for array size");
}
}
String desc;
exprType = type;
arrayDim = dim;
if (type == CLreplaced) {
clreplacedName = resolveClreplacedName(clreplacedname);
desc = toJvmArrayName(clreplacedName, dim);
} else {
desc = toJvmTypeName(type, dim);
}
bytecode.addMultiNewarray(desc, count);
}
16
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
private void atNewArrayExpr2(int type, ASTree sizeExpr, String jvmClreplacedname, ArrayInit init) throws CompileError {
if (init == null) {
if (sizeExpr == null) {
throw new CompileError("no array size");
} else {
sizeExpr.accept(this);
}
} else if (sizeExpr == null) {
int s = init.length();
bytecode.addIconst(s);
} else {
throw new CompileError("unnecessary array size specified for new");
}
String elementClreplaced;
if (type == CLreplaced) {
elementClreplaced = resolveClreplacedName(jvmClreplacedname);
bytecode.addAnewarray(MemberResolver.jvmToJavaName(elementClreplaced));
} else {
elementClreplaced = null;
int atype = 0;
switch(type) {
case BOOLEAN:
atype = T_BOOLEAN;
break;
case CHAR:
atype = T_CHAR;
break;
case FLOAT:
atype = T_FLOAT;
break;
case DOUBLE:
atype = T_DOUBLE;
break;
case BYTE:
atype = T_BYTE;
break;
case SHORT:
atype = T_SHORT;
break;
case INT:
atype = T_INT;
break;
case LONG:
atype = T_LONG;
break;
default:
badNewExpr();
break;
}
bytecode.addOpcode(NEWARRAY);
bytecode.add(atype);
}
if (init != null) {
int s = init.length();
ASTList list = init;
for (int i = 0; i < s; i++) {
bytecode.addOpcode(DUP);
bytecode.addIconst(i);
list.head().accept(this);
if (!isRefType(type)) {
atNumCastExpr(exprType, type);
}
bytecode.addOpcode(getArrayWriteOp(type, 0));
list = list.tail();
}
}
exprType = type;
arrayDim = 1;
clreplacedName = elementClreplaced;
}
16
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* public int getMethodArgsLength(ASTList args) {
* if (!isParamListName(args))
* return super.getMethodArgsLength(args);
*
* return paramTypeList.length;
* }
*/
@Override
public int getMethodArgsLength(ASTList args) {
String pname = paramListName;
int n = 0;
while (args != null) {
ASTree a = args.head();
if (a instanceof Member && ((Member) a).get().equals(pname)) {
if (paramTypeList != null) {
n += paramTypeList.length;
}
} else {
++n;
}
args = args.tail();
}
return n;
}
15
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atArrayInit(ArrayInit init) throws CompileError {
ASTList list = init;
while (list != null) {
ASTree h = list.head();
list = list.tail();
if (h != null) {
h.accept(this);
}
}
}
15
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public int getMethodArgsLength(ASTList args) {
String pname = codeGen.paramListName;
int n = 0;
while (args != null) {
ASTree a = args.head();
if (a instanceof Member && ((Member) a).get().equals(pname)) {
if (codeGen.paramTypeList != null) {
n += codeGen.paramTypeList.length;
}
} else {
++n;
}
args = args.tail();
}
return n;
}
15
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atCastExpr(CastExpr expr) throws CompileError {
ASTList clreplacedname = expr.getClreplacedName();
if (clreplacedname != null && expr.getArrayDim() == 0) {
ASTree p = clreplacedname.head();
if (p instanceof Symbol && clreplacedname.tail() == null) {
String typename = ((Symbol) p).get();
if (typename.equals(returnCastName)) {
atCastToRtype(expr);
return;
} else if (typename.equals(wrapperCastName)) {
atCastToWrapper(expr);
return;
}
}
}
super.atCastExpr(expr);
}
15
Source : Javac.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/**
* Compiles a method, constructor, or field declaration
* to a clreplaced.
* A field declaration can declare only one field.
*
* <p>
* In a method or constructor body, $0, $1, ... and $_
* are not available.
*
* @return a <code>CtMethod</code>, <code>CtConstructor</code>,
* or <code>CtField</code> object.
* @see #recordProceed(String,String)
*/
public CtMember compile(String src) throws CompileError {
Parser p = new Parser(new Lex(src));
ASTList mem = p.parseMember1(stable);
try {
if (mem instanceof FieldDecl) {
return compileField((FieldDecl) mem);
}
CtBehavior cb = compileMethod(p, (MethodDecl) mem);
CtClreplaced decl = cb.getDeclaringClreplaced();
cb.getMethodInfo2().rebuildStackMapIf6(decl.getClreplacedPool(), decl.getClreplacedFile2());
return cb;
} catch (BadBytecode bb) {
throw new CompileError(bb.getMessage());
} catch (CannotCompileException e) {
throw new CompileError(e.getMessage());
}
}
14
Source : JvstCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atMethodArgs(ASTList args, int[] types, int[] dims, String[] cnames) throws CompileError {
CtClreplaced[] params = paramTypeList;
String pname = paramListName;
int i = 0;
while (args != null) {
ASTree a = args.head();
if (a instanceof Member && ((Member) a).get().equals(pname)) {
if (params != null) {
int n = params.length;
int regno = indexOfParam1();
for (int k = 0; k < n; ++k) {
CtClreplaced p = params[k];
regno += bytecode.addLoad(regno, p);
setType(p);
types[i] = exprType;
dims[i] = arrayDim;
cnames[i] = clreplacedName;
++i;
}
}
} else {
a.accept(this);
types[i] = exprType;
dims[i] = arrayDim;
cnames[i] = clreplacedName;
++i;
}
args = args.tail();
}
}
13
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
/*
* EXPR must be a + expression.
* atPlusExpr() returns non-null if the given expression is string
* concatenation. The returned value is "new StringBuffer().append..".
*/
private Expr atPlusExpr(BinExpr expr) throws CompileError {
ASTree left = expr.oprand1();
ASTree right = expr.oprand2();
if (right == null) {
// this expression has been already type-checked.
// see atBinExpr() above.
left.accept(this);
return null;
}
if (isPlusExpr(left)) {
Expr newExpr = atPlusExpr((BinExpr) left);
if (newExpr != null) {
right.accept(this);
exprType = CLreplaced;
arrayDim = 0;
clreplacedName = "java/lang/StringBuffer";
return makeAppendCall(newExpr, right);
}
} else {
left.accept(this);
}
int type1 = exprType;
int dim1 = arrayDim;
String cname = clreplacedName;
right.accept(this);
if (isConstant(expr, '+', left, right)) {
return null;
}
if ((type1 == CLreplaced && dim1 == 0 && jvmJavaLangString.equals(cname)) || (exprType == CLreplaced && arrayDim == 0 && jvmJavaLangString.equals(clreplacedName))) {
ASTList sbufClreplaced = ASTList.make(new Symbol("java"), new Symbol("lang"), new Symbol("StringBuffer"));
ASTree e = new NewExpr(sbufClreplaced, null);
exprType = CLreplaced;
arrayDim = 0;
clreplacedName = "java/lang/StringBuffer";
return makeAppendCall(makeAppendCall(e, left), right);
}
computeBinExprType(expr, '+', type1);
return null;
}
13
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atCastExpr(CastExpr expr) throws CompileError {
ASTList clreplacedname = expr.getClreplacedName();
if (clreplacedname != null && expr.getArrayDim() == 0) {
ASTree p = clreplacedname.head();
if (p instanceof Symbol && clreplacedname.tail() == null) {
String typename = ((Symbol) p).get();
if (typename.equals(codeGen.returnCastName)) {
atCastToRtype(expr);
return;
} else if (typename.equals(JvstCodeGen.wrapperCastName)) {
atCastToWrapper(expr);
return;
}
}
}
super.atCastExpr(expr);
}
12
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atNewExpr(NewExpr expr) throws CompileError {
if (expr.isArray()) {
atNewArrayExpr(expr);
} else {
CtClreplaced clazz = resolver.lookupClreplacedByName(expr.getClreplacedName());
String cname = clazz.getName();
ASTList args = expr.getArguments();
atMethodCallCore(clazz, MethodInfo.nameInit, args);
exprType = CLreplaced;
arrayDim = 0;
clreplacedName = MemberResolver.javaToJvmName(cname);
}
}
12
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public void atNewArrayExpr(NewExpr expr) throws CompileError {
int type = expr.getArrayType();
ASTList size = expr.getArraySize();
ASTList clreplacedname = expr.getClreplacedName();
ASTree init = expr.getInitializer();
if (init != null) {
init.accept(this);
}
if (size.length() > 1) {
atMultiNewArray(type, clreplacedname, size);
} else {
ASTree sizeExpr = size.head();
if (sizeExpr != null) {
sizeExpr.accept(this);
}
exprType = type;
arrayDim = 1;
if (type == CLreplaced) {
clreplacedName = resolveClreplacedName(clreplacedname);
} else {
clreplacedName = null;
}
}
}
12
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atNewExpr(NewExpr expr) throws CompileError {
if (expr.isArray()) {
atNewArrayExpr(expr);
} else {
CtClreplaced clazz = resolver.lookupClreplacedByName(expr.getClreplacedName());
String cname = clazz.getName();
ASTList args = expr.getArguments();
bytecode.addNew(cname);
bytecode.addOpcode(DUP);
atMethodCallCore(clazz, MethodInfo.nameInit, args, false, true, -1, null);
exprType = CLreplaced;
arrayDim = 0;
clreplacedName = MemberResolver.javaToJvmName(cname);
}
}
12
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
public void atNewArrayExpr(NewExpr expr) throws CompileError {
int type = expr.getArrayType();
ASTList size = expr.getArraySize();
ASTList clreplacedname = expr.getClreplacedName();
ArrayInit init = expr.getInitializer();
if (size.length() > 1) {
if (init != null) {
throw new CompileError("sorry, multi-dimensional array initializer " + "for new is not supported");
}
atMultiNewArray(type, clreplacedname, size);
return;
}
ASTree sizeExpr = size.head();
atNewArrayExpr2(type, sizeExpr, Declarator.astToClreplacedName(clreplacedname, '/'), init);
}
12
Source : JvstTypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atMethodArgs(ASTList args, int[] types, int[] dims, String[] cnames) throws CompileError {
CtClreplaced[] params = codeGen.paramTypeList;
String pname = codeGen.paramListName;
int i = 0;
while (args != null) {
ASTree a = args.head();
if (a instanceof Member && ((Member) a).get().equals(pname)) {
if (params != null) {
int n = params.length;
for (int k = 0; k < n; ++k) {
CtClreplaced p = params[k];
setType(p);
types[i] = exprType;
dims[i] = arrayDim;
cnames[i] = clreplacedName;
++i;
}
}
} else {
a.accept(this);
types[i] = exprType;
dims[i] = arrayDim;
cnames[i] = clreplacedName;
++i;
}
args = args.tail();
}
}
11
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atCallExpr(CallExpr expr) throws CompileError {
String mname = null;
CtClreplaced targetClreplaced = null;
ASTree method = expr.oprand1();
ASTList args = (ASTList) expr.oprand2();
boolean isStatic = false;
boolean isSpecial = false;
int aload0pos = -1;
MemberResolver.Method cached = expr.getMethod();
if (method instanceof Member) {
mname = ((Member) method).get();
targetClreplaced = thisClreplaced;
if (inStaticMethod || (cached != null && cached.isStatic())) {
// should be static
isStatic = true;
} else {
aload0pos = bytecode.currentPc();
// this
bytecode.addAload(0);
}
} else if (method instanceof Keyword) {
// constructor
isSpecial = true;
// <init>
mname = MethodInfo.nameInit;
targetClreplaced = thisClreplaced;
if (inStaticMethod) {
throw new CompileError("a constructor cannot be static");
}
// this
bytecode.addAload(0);
if (((Keyword) method).get() == SUPER) {
targetClreplaced = MemberResolver.getSuperclreplaced(targetClreplaced);
}
} else if (method instanceof Expr) {
Expr e = (Expr) method;
mname = ((Symbol) e.oprand2()).get();
int op = e.getOperator();
if (op == MEMBER) {
// static method
targetClreplaced = resolver.lookupClreplaced(((Symbol) e.oprand1()).get(), false);
isStatic = true;
} else if (op == '.') {
ASTree target = e.oprand1();
String clreplacedFollowedByDotSuper = TypeChecker.isDotSuper(target);
if (clreplacedFollowedByDotSuper != null) {
isSpecial = true;
targetClreplaced = MemberResolver.getSuperInterface(thisClreplaced, clreplacedFollowedByDotSuper);
if (inStaticMethod || (cached != null && cached.isStatic())) {
// should be static
isStatic = true;
} else {
aload0pos = bytecode.currentPc();
// this
bytecode.addAload(0);
}
} else {
if (target instanceof Keyword) {
if (((Keyword) target).get() == SUPER) {
isSpecial = true;
}
}
try {
target.accept(this);
} catch (NoFieldException nfe) {
if (nfe.getExpr() != target) {
throw nfe;
}
// it should be a static method.
exprType = CLreplaced;
arrayDim = 0;
// JVM-internal
clreplacedName = nfe.getField();
isStatic = true;
}
if (arrayDim > 0) {
targetClreplaced = resolver.lookupClreplaced(javaLangObject, true);
} else if (exprType == CLreplaced) /* && arrayDim == 0 */
{
targetClreplaced = resolver.lookupClreplacedByJvmName(clreplacedName);
} else {
badMethod();
}
}
} else {
badMethod();
}
} else {
fatal();
}
atMethodCallCore(targetClreplaced, mname, args, isStatic, isSpecial, aload0pos, cached);
}
9
Source : TypeChecker.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
public void atCallExpr(CallExpr expr) throws CompileError {
String mname = null;
CtClreplaced targetClreplaced = null;
ASTree method = expr.oprand1();
ASTList args = (ASTList) expr.oprand2();
if (method instanceof Member) {
mname = ((Member) method).get();
targetClreplaced = thisClreplaced;
} else if (method instanceof Keyword) {
// constructor
// <init>
mname = MethodInfo.nameInit;
if (((Keyword) method).get() == SUPER) {
targetClreplaced = MemberResolver.getSuperclreplaced(thisClreplaced);
} else {
targetClreplaced = thisClreplaced;
}
} else if (method instanceof Expr) {
Expr e = (Expr) method;
mname = ((Symbol) e.oprand2()).get();
int op = e.getOperator();
if (op == MEMBER) {
targetClreplaced = resolver.lookupClreplaced(((Symbol) e.oprand1()).get(), false);
} else if (op == '.') {
ASTree target = e.oprand1();
String clreplacedFollowedByDotSuper = isDotSuper(target);
if (clreplacedFollowedByDotSuper != null) {
targetClreplaced = MemberResolver.getSuperInterface(thisClreplaced, clreplacedFollowedByDotSuper);
} else {
try {
target.accept(this);
} catch (NoFieldException nfe) {
if (nfe.getExpr() != target) {
throw nfe;
}
// it should be a static method.
exprType = CLreplaced;
arrayDim = 0;
// JVM-internal
clreplacedName = nfe.getField();
e.setOperator(MEMBER);
e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(clreplacedName)));
}
if (arrayDim > 0) {
targetClreplaced = resolver.lookupClreplaced(javaLangObject, true);
} else if (exprType == CLreplaced) /* && arrayDim == 0 */
{
targetClreplaced = resolver.lookupClreplacedByJvmName(clreplacedName);
} else {
badMethod();
}
}
} else {
badMethod();
}
} else {
fatal();
}
MemberResolver.Method minfo = atMethodCallCore(targetClreplaced, mname, args);
expr.setMethod(minfo);
}
0
Source : MemberCodeGen.java
with Apache License 2.0
from ifeilong
with Apache License 2.0
from ifeilong
@Override
protected void atTryStmnt(Stmnt st) throws CompileError {
Bytecode bc = bytecode;
Stmnt body = (Stmnt) st.getLeft();
if (body == null) {
return;
}
ASTList catchList = (ASTList) st.getRight().getLeft();
Stmnt finallyBlock = (Stmnt) st.getRight().getRight().getLeft();
List<Integer> gotoList = new ArrayList<>();
JsrHook jsrHook = null;
if (finallyBlock != null) {
jsrHook = new JsrHook(this);
}
int start = bc.currentPc();
body.accept(this);
int end = bc.currentPc();
if (start == end) {
throw new CompileError("empty try block");
}
boolean tryNotReturn = !hasReturned;
if (tryNotReturn) {
bc.addOpcode(Opcode.GOTO);
gotoList.add(bc.currentPc());
// correct later
bc.addIndex(0);
}
int var = getMaxLocals();
incMaxLocals(1);
while (catchList != null) {
// catch clause
Pair p = (Pair) catchList.head();
catchList = catchList.tail();
Declarator decl = (Declarator) p.getLeft();
Stmnt block = (Stmnt) p.getRight();
decl.setLocalVar(var);
CtClreplaced type = resolver.lookupClreplacedByJvmName(decl.getClreplacedName());
decl.setClreplacedName(MemberResolver.javaToJvmName(type.getName()));
bc.addExceptionHandler(start, end, bc.currentPc(), type);
bc.growStack(1);
bc.addAstore(var);
hasReturned = false;
if (block != null) {
block.accept(this);
}
if (!hasReturned) {
bc.addOpcode(Opcode.GOTO);
gotoList.add(bc.currentPc());
// correct later
bc.addIndex(0);
tryNotReturn = true;
}
}
if (finallyBlock != null) {
jsrHook.remove(this);
// catch (any) clause
int pcAnyCatch = bc.currentPc();
bc.addExceptionHandler(start, pcAnyCatch, pcAnyCatch, 0);
bc.growStack(1);
bc.addAstore(var);
hasReturned = false;
finallyBlock.accept(this);
if (!hasReturned) {
bc.addAload(var);
bc.addOpcode(ATHROW);
}
addFinally(jsrHook.jsrList, finallyBlock);
}
int pcEnd = bc.currentPc();
patchGoto(gotoList, pcEnd);
hasReturned = !tryNotReturn;
if (finallyBlock != null) {
if (tryNotReturn) {
finallyBlock.accept(this);
}
}
}