introduce some generics
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@996 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
f01c8208f6
commit
6743e8ace6
|
@ -170,7 +170,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CAstNode translateConstant(Object constant) {
|
protected CAstNode translateConstant(Object constant) {
|
||||||
return fFactory.makeConstant( constant );
|
return fFactory.makeConstant(constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class JavaTranslatingVisitorImpl implements TranslatingVisitor {
|
protected class JavaTranslatingVisitorImpl implements TranslatingVisitor {
|
||||||
|
@ -215,9 +215,11 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
ClassType superClass = (ClassType) cd.constructorInstance().container().superType();
|
ClassType superClass = (ClassType) cd.constructorInstance().container().superType();
|
||||||
ProcedureInstance defaultSuperCtor = findDefaultCtor(superClass);
|
ProcedureInstance defaultSuperCtor = findDefaultCtor(superClass);
|
||||||
CAstNode[] bodyNodes = new CAstNode[inits.size() + body.statements().size() + 1];
|
CAstNode[] bodyNodes = new CAstNode[inits.size() + body.statements().size() + 1];
|
||||||
CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(defaultSuperCtor), IInvokeInstruction.Dispatch.SPECIAL);
|
CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(defaultSuperCtor),
|
||||||
|
IInvokeInstruction.Dispatch.SPECIAL);
|
||||||
|
|
||||||
CAstNode superCall = makeNode(mc, fFactory, cd, CAstNode.CALL, makeNode(mc, fFactory, cd, CAstNode.SUPER), fFactory.makeConstant(callSiteRef));
|
CAstNode superCall = makeNode(mc, fFactory, cd, CAstNode.CALL, makeNode(mc, fFactory, cd, CAstNode.SUPER), fFactory
|
||||||
|
.makeConstant(callSiteRef));
|
||||||
|
|
||||||
bodyNodes[0] = superCall;
|
bodyNodes[0] = superCall;
|
||||||
insertInitializers(mc, bodyNodes, false, 1);
|
insertInitializers(mc, bodyNodes, false, 1);
|
||||||
|
@ -244,18 +246,16 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
public CAstNode visit(FieldDecl f, MethodContext ctorContext) {
|
public CAstNode visit(FieldDecl f, MethodContext ctorContext) {
|
||||||
// Generate CAST node for the initializer (init())
|
// Generate CAST node for the initializer (init())
|
||||||
// Type targetType = f.memberInstance().container();
|
// Type targetType = f.memberInstance().container();
|
||||||
// Type fieldType = f.type().type();
|
// Type fieldType = f.type().type();
|
||||||
FieldReference fieldRef = fIdentityMapper.getFieldRef(f.fieldInstance());
|
FieldReference fieldRef = fIdentityMapper.getFieldRef(f.fieldInstance());
|
||||||
// We use null to indicate an OBJECT_REF to a static field, as the
|
// We use null to indicate an OBJECT_REF to a static field, as the
|
||||||
// FieldReference doesn't
|
// FieldReference doesn't
|
||||||
// hold enough info to determine this. In this case, (unlike field ref)
|
// hold enough info to determine this. In this case, (unlike field ref)
|
||||||
// we don't have a
|
// we don't have a
|
||||||
// target expr to evaluate.
|
// target expr to evaluate.
|
||||||
CAstNode thisNode =
|
CAstNode thisNode = f.flags().isStatic() ? makeNode(ctorContext, fFactory, null, CAstNode.VOID) : makeNode(ctorContext,
|
||||||
f.flags().isStatic()?
|
fFactory, f, CAstNode.THIS);
|
||||||
makeNode(ctorContext, fFactory, null, CAstNode.VOID):
|
|
||||||
makeNode(ctorContext, fFactory, f, CAstNode.THIS);
|
|
||||||
CAstNode lhsNode = makeNode(ctorContext, fFactory, f, CAstNode.OBJECT_REF, thisNode, fFactory.makeConstant(fieldRef));
|
CAstNode lhsNode = makeNode(ctorContext, fFactory, f, CAstNode.OBJECT_REF, thisNode, fFactory.makeConstant(fieldRef));
|
||||||
|
|
||||||
Expr init = f.init();
|
Expr init = f.init();
|
||||||
|
@ -295,7 +295,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
CAstNode[] eltNodes = new CAstNode[ai.elements().size() + 1];
|
CAstNode[] eltNodes = new CAstNode[ai.elements().size() + 1];
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|
||||||
eltNodes[idx++] = makeNode(wc, fFactory, ai, CAstNode.NEW, fFactory.makeConstant(newTypeRef), fFactory.makeConstant(ai.elements().size()));
|
eltNodes[idx++] = makeNode(wc, fFactory, ai, CAstNode.NEW, fFactory.makeConstant(newTypeRef), fFactory.makeConstant(ai
|
||||||
|
.elements().size()));
|
||||||
for (Iterator iter = ai.elements().iterator(); iter.hasNext(); idx++) {
|
for (Iterator iter = ai.elements().iterator(); iter.hasNext(); idx++) {
|
||||||
Expr element = (Expr) iter.next();
|
Expr element = (Expr) iter.next();
|
||||||
eltNodes[idx] = walkNodes(element, wc);
|
eltNodes[idx] = walkNodes(element, wc);
|
||||||
|
@ -324,7 +325,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
if (la.operator() == Assign.ASSIGN)
|
if (la.operator() == Assign.ASSIGN)
|
||||||
return makeNode(wc, fFactory, la, CAstNode.ASSIGN, walkNodes(la.left(), lvc), walkNodes(la.right(), wc));
|
return makeNode(wc, fFactory, la, CAstNode.ASSIGN, walkNodes(la.left(), lvc), walkNodes(la.right(), wc));
|
||||||
else
|
else
|
||||||
return makeNode(wc, fFactory, la, CAstNode.ASSIGN_PRE_OP, walkNodes(la.left(), lvc), walkNodes(la.right(), wc), mapAssignOperator(la.operator()));
|
return makeNode(wc, fFactory, la, CAstNode.ASSIGN_PRE_OP, walkNodes(la.left(), lvc), walkNodes(la.right(), wc),
|
||||||
|
mapAssignOperator(la.operator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CAstOperator mapAssignOperator(Assign.Operator op) {
|
protected CAstOperator mapAssignOperator(Assign.Operator op) {
|
||||||
|
@ -400,11 +402,12 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
boolean isIntf = ((ClassType) methodOwner).flags().isInterface();
|
boolean isIntf = ((ClassType) methodOwner).flags().isInterface();
|
||||||
Receiver target = c.target();
|
Receiver target = c.target();
|
||||||
boolean isSpecial = methodInstance.flags().isPrivate() || (target instanceof Special && ((Special) target).kind() == Special.SUPER);
|
boolean isSpecial = methodInstance.flags().isPrivate()
|
||||||
|
|| (target instanceof Special && ((Special) target).kind() == Special.SUPER);
|
||||||
|
|
||||||
CAstNode[] children = new CAstNode[2 + methodInstance.formalTypes().size()]; // including
|
CAstNode[] children = new CAstNode[2 + methodInstance.formalTypes().size()]; // including
|
||||||
// the
|
// the
|
||||||
// MethodReference
|
// MethodReference
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!isStatic)
|
if (!isStatic)
|
||||||
|
@ -454,13 +457,14 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
CallSiteReference callSiteRef = CallSiteReference.make(dummyPC, methodRef, IInvokeInstruction.Dispatch.SPECIAL);
|
CallSiteReference callSiteRef = CallSiteReference.make(dummyPC, methodRef, IInvokeInstruction.Dispatch.SPECIAL);
|
||||||
|
|
||||||
CAstNode[] children = new CAstNode[1 + 1 + ctorInstance.formalTypes().size()]; // including
|
CAstNode[] children = new CAstNode[1 + 1 + ctorInstance.formalTypes().size()]; // including
|
||||||
// the
|
// the
|
||||||
// MethodReference
|
// MethodReference
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
CAstNode targetNode;
|
CAstNode targetNode;
|
||||||
|
|
||||||
targetNode = (cc.kind() == ConstructorCall.THIS) ? makeNode(wc, fFactory, cc, CAstNode.THIS) : makeNode(wc, fFactory, cc, CAstNode.SUPER);
|
targetNode = (cc.kind() == ConstructorCall.THIS) ? makeNode(wc, fFactory, cc, CAstNode.THIS) : makeNode(wc, fFactory, cc,
|
||||||
|
CAstNode.SUPER);
|
||||||
|
|
||||||
children[i++] = targetNode;
|
children[i++] = targetNode;
|
||||||
children[i++] = fFactory.makeConstant(callSiteRef);
|
children[i++] = fFactory.makeConstant(callSiteRef);
|
||||||
|
@ -480,7 +484,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
Expr arg = c.expr();
|
Expr arg = c.expr();
|
||||||
Type castedTo = c.castType().type();
|
Type castedTo = c.castType().type();
|
||||||
|
|
||||||
CAstNode ast = makeNode(wc, fFactory, c, CAstNode.CAST, fFactory.makeConstant(getTypeDict().getCAstTypeFor(castedTo)), walkNodes(arg, wc));
|
CAstNode ast = makeNode(wc, fFactory, c, CAstNode.CAST, fFactory.makeConstant(getTypeDict().getCAstTypeFor(castedTo)),
|
||||||
|
walkNodes(arg, wc));
|
||||||
|
|
||||||
Collection excTargets = wc.getCatchTargets(fCCEType);
|
Collection excTargets = wc.getCatchTargets(fCCEType);
|
||||||
if (!excTargets.isEmpty()) {
|
if (!excTargets.isEmpty()) {
|
||||||
|
@ -488,24 +493,25 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
// (presumably only one)
|
// (presumably only one)
|
||||||
for (Iterator iterator = excTargets.iterator(); iterator.hasNext();) {
|
for (Iterator iterator = excTargets.iterator(); iterator.hasNext();) {
|
||||||
Pair catchPair = (Pair) iterator.next();
|
Pair catchPair = (Pair) iterator.next();
|
||||||
wc.cfg().add(c, catchPair.snd, fCCEType);
|
wc.cfg().add(c, catchPair.snd, fCCEType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// connect exception edge to exit
|
// connect exception edge to exit
|
||||||
wc.cfg().add(c, CAstControlFlowMap.EXCEPTION_TO_EXIT, fCCEType);
|
wc.cfg().add(c, CAstControlFlowMap.EXCEPTION_TO_EXIT, fCCEType);
|
||||||
}
|
}
|
||||||
|
|
||||||
wc.cfg().map(c, ast);
|
wc.cfg().map(c, ast);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Conditional c, WalkContext wc) {
|
public CAstNode visit(Conditional c, WalkContext wc) {
|
||||||
return makeNode(wc, fFactory, c, CAstNode.IF_EXPR, walkNodes(c.cond(), wc), walkNodes(c.consequent(), wc), walkNodes(c.alternative(), wc));
|
return makeNode(wc, fFactory, c, CAstNode.IF_EXPR, walkNodes(c.cond(), wc), walkNodes(c.consequent(), wc), walkNodes(c
|
||||||
|
.alternative(), wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Instanceof io, WalkContext wc) {
|
public CAstNode visit(Instanceof io, WalkContext wc) {
|
||||||
return makeNode(wc, fFactory, io, CAstNode.INSTANCEOF, fFactory.makeConstant(getTypeDict().getCAstTypeFor(io.compareType().type())), walkNodes(io.expr(),
|
return makeNode(wc, fFactory, io, CAstNode.INSTANCEOF, fFactory.makeConstant(getTypeDict().getCAstTypeFor(
|
||||||
wc));
|
io.compareType().type())), walkNodes(io.expr(), wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(BooleanLit bl, WalkContext wc) {
|
public CAstNode visit(BooleanLit bl, WalkContext wc) {
|
||||||
|
@ -543,7 +549,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
String newTypeNameStr;
|
String newTypeNameStr;
|
||||||
TypeReference newTypeRef;
|
TypeReference newTypeRef;
|
||||||
ConstructorInstance ctorInst = n.constructorInstance();
|
ConstructorInstance ctorInst = n.constructorInstance();
|
||||||
MethodReference ctorRef= fIdentityMapper.getMethodRef(ctorInst);
|
MethodReference ctorRef = fIdentityMapper.getMethodRef(ctorInst);
|
||||||
|
|
||||||
if (n.body() != null) {
|
if (n.body() != null) {
|
||||||
fIdentityMapper.mapLocalAnonTypeToMethod((ClassType) n.type(), wc.getEnclosingMethod());
|
fIdentityMapper.mapLocalAnonTypeToMethod((ClassType) n.type(), wc.getEnclosingMethod());
|
||||||
|
@ -552,9 +558,9 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
newTypeNameStr = anonClass.getType().getName();
|
newTypeNameStr = anonClass.getType().getName();
|
||||||
TypeName newTypeName = TypeName.string2TypeName(newTypeNameStr);
|
TypeName newTypeName = TypeName.string2TypeName(newTypeNameStr);
|
||||||
Selector ctorSel= ctorRef.getSelector();
|
Selector ctorSel = ctorRef.getSelector();
|
||||||
newTypeRef = TypeReference.findOrCreate(fClassLoaderRef, newTypeName);
|
newTypeRef = TypeReference.findOrCreate(fClassLoaderRef, newTypeName);
|
||||||
ctorRef= MethodReference.findOrCreate(newTypeRef, ctorSel);
|
ctorRef = MethodReference.findOrCreate(newTypeRef, ctorSel);
|
||||||
} else {
|
} else {
|
||||||
newTypeRef = fIdentityMapper.getTypeRef(n.type());
|
newTypeRef = fIdentityMapper.getTypeRef(n.type());
|
||||||
}
|
}
|
||||||
|
@ -587,15 +593,9 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
handleThrowsFromCall(ctorInst, n, wc);
|
handleThrowsFromCall(ctorInst, n, wc);
|
||||||
|
|
||||||
return
|
return makeNode(wc, fFactory, n, CAstNode.LOCAL_SCOPE, makeNode(wc, fFactory, n, CAstNode.BLOCK_EXPR, makeNode(wc, fFactory,
|
||||||
makeNode(wc, fFactory, n, CAstNode.LOCAL_SCOPE,
|
n, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(tmpName, true)), newNode), callNode, makeNode(wc,
|
||||||
makeNode(wc, fFactory, n, CAstNode.BLOCK_EXPR,
|
fFactory, n, CAstNode.VAR, fFactory.makeConstant(tmpName))));
|
||||||
makeNode(wc, fFactory, n, CAstNode.DECL_STMT,
|
|
||||||
fFactory.makeConstant(new CAstSymbolImpl(tmpName, true)),
|
|
||||||
newNode),
|
|
||||||
callNode,
|
|
||||||
makeNode(wc, fFactory, n, CAstNode.VAR,
|
|
||||||
fFactory.makeConstant(tmpName))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(NewArray na, WalkContext wc) {
|
public CAstNode visit(NewArray na, WalkContext wc) {
|
||||||
|
@ -627,7 +627,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
Type owningType = s.qualifier().type();
|
Type owningType = s.qualifier().type();
|
||||||
TypeReference owningTypeRef = fIdentityMapper.getTypeRef(owningType);
|
TypeReference owningTypeRef = fIdentityMapper.getTypeRef(owningType);
|
||||||
|
|
||||||
return makeNode(wc, fFactory, s, s.kind() == Special.THIS ? CAstNode.THIS : CAstNode.SUPER, fFactory.makeConstant(owningTypeRef));
|
return makeNode(wc, fFactory, s, s.kind() == Special.THIS ? CAstNode.THIS : CAstNode.SUPER, fFactory
|
||||||
|
.makeConstant(owningTypeRef));
|
||||||
} else {
|
} else {
|
||||||
return makeNode(wc, fFactory, s, s.kind() == Special.THIS ? CAstNode.THIS : CAstNode.SUPER);
|
return makeNode(wc, fFactory, s, s.kind() == Special.THIS ? CAstNode.THIS : CAstNode.SUPER);
|
||||||
}
|
}
|
||||||
|
@ -635,11 +636,13 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
public CAstNode visit(Unary u, WalkContext wc) {
|
public CAstNode visit(Unary u, WalkContext wc) {
|
||||||
if (isAssignOp(u.operator())) {
|
if (isAssignOp(u.operator())) {
|
||||||
WalkContext lvc = new AssignmentContext(wc);
|
WalkContext lvc = new AssignmentContext(wc);
|
||||||
if (u.operator().isPrefix())
|
if (u.operator().isPrefix())
|
||||||
return makeNode(wc, fFactory, u, CAstNode.ASSIGN_PRE_OP, walkNodes(u.expr(), lvc), fFactory.makeConstant(1), mapUnaryOpcode(u.operator()));
|
return makeNode(wc, fFactory, u, CAstNode.ASSIGN_PRE_OP, walkNodes(u.expr(), lvc), fFactory.makeConstant(1),
|
||||||
|
mapUnaryOpcode(u.operator()));
|
||||||
else
|
else
|
||||||
return makeNode(wc, fFactory, u, CAstNode.ASSIGN_POST_OP, walkNodes(u.expr(), lvc), fFactory.makeConstant(1), mapUnaryOpcode(u.operator()));
|
return makeNode(wc, fFactory, u, CAstNode.ASSIGN_POST_OP, walkNodes(u.expr(), lvc), fFactory.makeConstant(1),
|
||||||
|
mapUnaryOpcode(u.operator()));
|
||||||
} else if (u.operator() == Unary.POS) // drop useless unary plus
|
} else if (u.operator() == Unary.POS) // drop useless unary plus
|
||||||
// operator
|
// operator
|
||||||
return walkNodes(u.expr(), wc);
|
return walkNodes(u.expr(), wc);
|
||||||
|
@ -661,13 +664,14 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
public CAstNode visit(ArrayAccess aa, WalkContext wc) {
|
public CAstNode visit(ArrayAccess aa, WalkContext wc) {
|
||||||
TypeReference eltTypeRef = fIdentityMapper.getTypeRef(aa.type());
|
TypeReference eltTypeRef = fIdentityMapper.getTypeRef(aa.type());
|
||||||
|
|
||||||
return makeNode(wc, fFactory, aa, CAstNode.ARRAY_REF, walkNodes(aa.array(), wc), fFactory.makeConstant(eltTypeRef), walkNodes(aa.index(), wc));
|
return makeNode(wc, fFactory, aa, CAstNode.ARRAY_REF, walkNodes(aa.array(), wc), fFactory.makeConstant(eltTypeRef),
|
||||||
|
walkNodes(aa.index(), wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Field f, WalkContext wc) {
|
public CAstNode visit(Field f, WalkContext wc) {
|
||||||
Receiver target = f.target();
|
Receiver target = f.target();
|
||||||
Type targetType = target.type();
|
Type targetType = target.type();
|
||||||
// Type fieldType = f.type();
|
// Type fieldType = f.type();
|
||||||
|
|
||||||
if (targetType.isArray()) {
|
if (targetType.isArray()) {
|
||||||
Assertions._assert(f.name().equals("length"));
|
Assertions._assert(f.name().equals("length"));
|
||||||
|
@ -685,17 +689,16 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
// followed by the OBJECT_REF with a null target child (which the
|
// followed by the OBJECT_REF with a null target child (which the
|
||||||
// "back-end"
|
// "back-end"
|
||||||
// CAst -> IR translator interprets as a static ref).
|
// CAst -> IR translator interprets as a static ref).
|
||||||
if (fi.isConstant()) {
|
if (fi.isConstant()) {
|
||||||
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR,
|
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR, targetNode, // can
|
||||||
targetNode, // can have side effects!
|
// have
|
||||||
translateConstant(fi.constantValue()));
|
// side
|
||||||
} else {
|
// effects!
|
||||||
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR,
|
translateConstant(fi.constantValue()));
|
||||||
targetNode,
|
} else {
|
||||||
makeNode(wc, fFactory, f, CAstNode.OBJECT_REF,
|
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR, targetNode, makeNode(wc, fFactory, f, CAstNode.OBJECT_REF,
|
||||||
makeNode(wc, fFactory, null, CAstNode.VOID),
|
makeNode(wc, fFactory, null, CAstNode.VOID), fFactory.makeConstant(fieldRef)));
|
||||||
fFactory.makeConstant(fieldRef)));
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Collection excTargets = wc.getCatchTargets(fNPEType);
|
Collection excTargets = wc.getCatchTargets(fNPEType);
|
||||||
if (!excTargets.isEmpty()) {
|
if (!excTargets.isEmpty()) {
|
||||||
|
@ -713,13 +716,15 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
wc.cfg().map(f, refNode);
|
wc.cfg().map(f, refNode);
|
||||||
|
|
||||||
if (fi.isConstant()) {
|
if (fi.isConstant()) {
|
||||||
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR,
|
return makeNode(wc, fFactory, f, CAstNode.BLOCK_EXPR, refNode, // can
|
||||||
refNode, // can have side effects!
|
// have
|
||||||
translateConstant(fi.constantValue()));
|
// side
|
||||||
} else {
|
// effects!
|
||||||
return refNode;
|
translateConstant(fi.constantValue()));
|
||||||
}
|
} else {
|
||||||
|
return refNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,7 +805,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(If i, WalkContext wc) {
|
public CAstNode visit(If i, WalkContext wc) {
|
||||||
return makeNode(wc, fFactory, i, CAstNode.IF_STMT, walkNodes(i.cond(), wc), walkNodes(i.consequent(), wc), walkNodes(i.alternative(), wc));
|
return makeNode(wc, fFactory, i, CAstNode.IF_STMT, walkNodes(i.cond(), wc), walkNodes(i.consequent(), wc), walkNodes(i
|
||||||
|
.alternative(), wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Labeled l, WalkContext wc) {
|
public CAstNode visit(Labeled l, WalkContext wc) {
|
||||||
|
@ -811,7 +817,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
wc.getLabelMap().put(stmt, l.label());
|
wc.getLabelMap().put(stmt, l.label());
|
||||||
|
|
||||||
CAstNode result = makeNode(wc, fFactory, l, CAstNode.LABEL_STMT, fFactory.makeConstant(l.label()), walkNodes(l.statement(), wc));
|
CAstNode result = makeNode(wc, fFactory, l, CAstNode.LABEL_STMT, fFactory.makeConstant(l.label()), walkNodes(l.statement(),
|
||||||
|
wc));
|
||||||
|
|
||||||
wc.cfg().map(l, result);
|
wc.cfg().map(l, result);
|
||||||
|
|
||||||
|
@ -832,11 +839,13 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node makeBreakTarget(Node loop) {
|
private Node makeBreakTarget(Node loop) {
|
||||||
return fNodeFactory.Labeled(Position.COMPILER_GENERATED, "breakLabel" + loop.position().toString().replace('.', '_'), fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
return fNodeFactory.Labeled(Position.COMPILER_GENERATED, "breakLabel" + loop.position().toString().replace('.', '_'),
|
||||||
|
fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node makeContinueTarget(Node loop) {
|
private Node makeContinueTarget(Node loop) {
|
||||||
return fNodeFactory.Labeled(Position.COMPILER_GENERATED, "continueLabel" + loop.position().toString().replace('.', '_'), fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
return fNodeFactory.Labeled(Position.COMPILER_GENERATED, "continueLabel" + loop.position().toString().replace('.', '_'),
|
||||||
|
fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Do d, WalkContext wc) {
|
public CAstNode visit(Do d, WalkContext wc) {
|
||||||
|
@ -855,8 +864,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
CAstNode continueNode = walkNodes(continueTarget, wc);
|
CAstNode continueNode = walkNodes(continueTarget, wc);
|
||||||
|
|
||||||
return makeNode(wc, fFactory, d, CAstNode.BLOCK_STMT, walkNodes(header, wc), makeNode(wc, fFactory, d, CAstNode.BLOCK_STMT, walkNodes(d.body(), lc),
|
return makeNode(wc, fFactory, d, CAstNode.BLOCK_STMT, walkNodes(header, wc), makeNode(wc, fFactory, d, CAstNode.BLOCK_STMT,
|
||||||
continueNode), loopGoto, walkNodes(breakTarget, wc));
|
walkNodes(d.body(), lc), continueNode), loopGoto, walkNodes(breakTarget, wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(For f, WalkContext wc) {
|
public CAstNode visit(For f, WalkContext wc) {
|
||||||
|
@ -878,8 +887,9 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
CAstNode initsBlock = makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, inits);
|
CAstNode initsBlock = makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, inits);
|
||||||
CAstNode itersBlock = makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, iters);
|
CAstNode itersBlock = makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, iters);
|
||||||
|
|
||||||
return makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, initsBlock, makeNode(wc, fFactory, f, CAstNode.LOOP, walkNodes(f.cond(), wc), makeNode(wc,
|
return makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, initsBlock, makeNode(wc, fFactory, f, CAstNode.LOOP, walkNodes(
|
||||||
fFactory, f, CAstNode.BLOCK_STMT, walkNodes(f.body(), lc), walkNodes(continueTarget, wc), itersBlock)), walkNodes(breakTarget, wc));
|
f.cond(), wc), makeNode(wc, fFactory, f, CAstNode.BLOCK_STMT, walkNodes(f.body(), lc), walkNodes(continueTarget, wc),
|
||||||
|
itersBlock)), walkNodes(breakTarget, wc));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,16 +906,13 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
* The following loop is created sligtly differently than in jscore. It
|
* The following loop is created sligtly differently than in jscore. It
|
||||||
* doesn't have a specific target for continue.
|
* doesn't have a specific target for continue.
|
||||||
*/
|
*/
|
||||||
return makeNode(wc, fFactory, w, CAstNode.BLOCK_STMT, makeNode(wc, fFactory, w, CAstNode.LOOP, walkNodes(c, wc), makeNode(wc, fFactory, w,
|
return makeNode(wc, fFactory, w, CAstNode.BLOCK_STMT, makeNode(wc, fFactory, w, CAstNode.LOOP, walkNodes(c, wc), makeNode(wc,
|
||||||
CAstNode.BLOCK_STMT, walkNodes(b, lc), walkNodes(continueTarget, wc))), walkNodes(breakTarget, wc));
|
fFactory, w, CAstNode.BLOCK_STMT, walkNodes(b, lc), walkNodes(continueTarget, wc))), walkNodes(breakTarget, wc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Switch s, WalkContext wc) {
|
public CAstNode visit(Switch s, WalkContext wc) {
|
||||||
Node breakLabel =
|
Node breakLabel = fNodeFactory.Labeled(Position.COMPILER_GENERATED, "switchBreakLabel"
|
||||||
fNodeFactory.Labeled(
|
+ s.position().toString().replace('.', '_'), fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
||||||
Position.COMPILER_GENERATED,
|
|
||||||
"switchBreakLabel" + s.position().toString().replace('.', '_'),
|
|
||||||
fNodeFactory.Empty(Position.COMPILER_GENERATED));
|
|
||||||
CAstNode breakAst = walkNodes(breakLabel, wc);
|
CAstNode breakAst = walkNodes(breakLabel, wc);
|
||||||
String loopLabel = (String) wc.getLabelMap().get(s);
|
String loopLabel = (String) wc.getLabelMap().get(s);
|
||||||
WalkContext child = new SwitchContext(wc, loopLabel, breakLabel);
|
WalkContext child = new SwitchContext(wc, loopLabel, breakLabel);
|
||||||
|
@ -935,7 +942,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now produce the switch stmt itself
|
// Now produce the switch stmt itself
|
||||||
CAstNode switchAst = makeNode(wc, fFactory, s, CAstNode.SWITCH, walkNodes(cond, wc), makeNode(wc, fFactory, s, CAstNode.BLOCK_STMT, caseNodes));
|
CAstNode switchAst = makeNode(wc, fFactory, s, CAstNode.SWITCH, walkNodes(cond, wc), makeNode(wc, fFactory, s,
|
||||||
|
CAstNode.BLOCK_STMT, caseNodes));
|
||||||
|
|
||||||
wc.cfg().map(s, switchAst);
|
wc.cfg().map(s, switchAst);
|
||||||
wc.cfg().map(breakLabel, breakAst);
|
wc.cfg().map(breakLabel, breakAst);
|
||||||
|
@ -948,13 +956,13 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
public CAstNode visit(Synchronized s, WalkContext wc) {
|
public CAstNode visit(Synchronized s, WalkContext wc) {
|
||||||
CAstNode exprNode = walkNodes(s.expr(), wc);
|
CAstNode exprNode = walkNodes(s.expr(), wc);
|
||||||
String exprName = fFactory.makeUnique();
|
String exprName = fFactory.makeUnique();
|
||||||
CAstNode declStmt =
|
CAstNode declStmt = makeNode(wc, fFactory, s, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(exprName, true)),
|
||||||
makeNode(wc, fFactory, s, CAstNode.DECL_STMT,
|
exprNode);
|
||||||
fFactory.makeConstant(new CAstSymbolImpl(exprName, true)),
|
CAstNode monitorEnterNode = makeNode(wc, fFactory, s, CAstNode.MONITOR_ENTER, makeNode(wc, fFactory, s, CAstNode.VAR,
|
||||||
exprNode);
|
fFactory.makeConstant(exprName)));
|
||||||
CAstNode monitorEnterNode = makeNode(wc, fFactory, s, CAstNode.MONITOR_ENTER, makeNode(wc, fFactory, s, CAstNode.VAR, fFactory.makeConstant(exprName)));
|
|
||||||
CAstNode bodyNodes = walkNodes(s.body(), wc);
|
CAstNode bodyNodes = walkNodes(s.body(), wc);
|
||||||
CAstNode monitorExitNode = makeNode(wc, fFactory, s, CAstNode.MONITOR_EXIT, makeNode(wc, fFactory, s, CAstNode.VAR, fFactory.makeConstant(exprName)));
|
CAstNode monitorExitNode = makeNode(wc, fFactory, s, CAstNode.MONITOR_EXIT, makeNode(wc, fFactory, s, CAstNode.VAR, fFactory
|
||||||
|
.makeConstant(exprName)));
|
||||||
CAstNode tryBody = makeNode(wc, fFactory, s, CAstNode.BLOCK_STMT, monitorEnterNode, bodyNodes);
|
CAstNode tryBody = makeNode(wc, fFactory, s, CAstNode.BLOCK_STMT, monitorEnterNode, bodyNodes);
|
||||||
CAstNode bigBody = makeNode(wc, fFactory, s, CAstNode.UNWIND, tryBody, monitorExitNode);
|
CAstNode bigBody = makeNode(wc, fFactory, s, CAstNode.UNWIND, tryBody, monitorExitNode);
|
||||||
|
|
||||||
|
@ -1016,18 +1024,16 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
Object defaultValue;
|
Object defaultValue;
|
||||||
if (type.isLongOrLess())
|
if (type.isLongOrLess())
|
||||||
defaultValue = new Integer( 0 );
|
defaultValue = new Integer(0);
|
||||||
else if (type.isDouble() || type.isFloat())
|
else if (type.isDouble() || type.isFloat())
|
||||||
defaultValue = new Double(0.0);
|
defaultValue = new Double(0.0);
|
||||||
else
|
else
|
||||||
defaultValue = null;
|
defaultValue = null;
|
||||||
|
|
||||||
boolean isFinal = ld.flags().isFinal();
|
boolean isFinal = ld.flags().isFinal();
|
||||||
|
|
||||||
return makeNode(wc, fFactory, ld, CAstNode.DECL_STMT,
|
return makeNode(wc, fFactory, ld, CAstNode.DECL_STMT, fFactory.makeConstant(new CAstSymbolImpl(ld.name(), isFinal,
|
||||||
fFactory.makeConstant(
|
defaultValue)), initNode);
|
||||||
new CAstSymbolImpl(ld.name(), isFinal, defaultValue)),
|
|
||||||
initNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode visit(Return r, WalkContext wc) {
|
public CAstNode visit(Return r, WalkContext wc) {
|
||||||
|
@ -1070,9 +1076,9 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
protected static final class CompilationUnitEntity implements CAstEntity {
|
protected static final class CompilationUnitEntity implements CAstEntity {
|
||||||
private final String fName;
|
private final String fName;
|
||||||
|
|
||||||
private final List/* <CAstEntity> */fTopLevelDecls;
|
private final Collection<CAstEntity> fTopLevelDecls;
|
||||||
|
|
||||||
public CompilationUnitEntity(SourceFile file, List/* <CAstEntity> */topLevelDecls) {
|
public CompilationUnitEntity(SourceFile file, List<CAstEntity> topLevelDecls) {
|
||||||
fName = (file.package_() == null) ? "" : file.package_().package_().fullName().replace('.', '/');
|
fName = (file.package_() == null) ? "" : file.package_().package_().fullName().replace('.', '/');
|
||||||
fTopLevelDecls = topLevelDecls;
|
fTopLevelDecls = topLevelDecls;
|
||||||
}
|
}
|
||||||
|
@ -1102,7 +1108,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getAllScopedEntities() {
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
return Collections.singletonMap(null, fTopLevelDecls);
|
return Collections.singletonMap(null, fTopLevelDecls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1206,23 +1212,23 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract static class CodeBodyEntity implements CAstEntity {
|
protected abstract static class CodeBodyEntity implements CAstEntity {
|
||||||
private final Map<CAstNode,Set<CAstEntity>> fEntities;
|
private final Map<CAstNode, Collection<CAstEntity>> fEntities;
|
||||||
|
|
||||||
public CodeBodyEntity(Map<CAstNode, CAstEntity> entities) {
|
public CodeBodyEntity(Map<CAstNode, CAstEntity> entities) {
|
||||||
fEntities = new LinkedHashMap<CAstNode, Set<CAstEntity>>();
|
fEntities = new LinkedHashMap<CAstNode, Collection<CAstEntity>>();
|
||||||
for (Iterator keys = entities.keySet().iterator(); keys.hasNext();) {
|
for (Iterator keys = entities.keySet().iterator(); keys.hasNext();) {
|
||||||
CAstNode key = (CAstNode) keys.next();
|
CAstNode key = (CAstNode) keys.next();
|
||||||
fEntities.put(key, Collections.singleton(entities.get(key)));
|
fEntities.put(key, Collections.singleton(entities.get(key)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getAllScopedEntities() {
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
return Collections.unmodifiableMap(fEntities);
|
return Collections.unmodifiableMap(fEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator getScopedEntities(CAstNode construct) {
|
public Iterator getScopedEntities(CAstNode construct) {
|
||||||
if (fEntities.containsKey(construct)) {
|
if (fEntities.containsKey(construct)) {
|
||||||
return ((Set) fEntities.get(construct)).iterator();
|
return (fEntities.get(construct)).iterator();
|
||||||
} else {
|
} else {
|
||||||
return EmptyIterator.instance();
|
return EmptyIterator.instance();
|
||||||
}
|
}
|
||||||
|
@ -1241,15 +1247,15 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
private final String fName;
|
private final String fName;
|
||||||
|
|
||||||
private final List/* <CAstEntity> */fEntities;
|
private final Collection<CAstEntity> fEntities;
|
||||||
|
|
||||||
private final CAstSourcePositionMap.Position sourcePosition;
|
private final CAstSourcePositionMap.Position sourcePosition;
|
||||||
|
|
||||||
private ClassEntity(ClassContext context, List/* <CAstEntity> */entities, ClassDecl cd, Position p) {
|
private ClassEntity(ClassContext context, List<CAstEntity> entities, ClassDecl cd, Position p) {
|
||||||
this(context, entities, cd.type(), cd.name(), p);
|
this(context, entities, cd.type(), cd.name(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassEntity(ClassContext context, List/* <CAstEntity> */entities, ClassType ct, String name, Position p) {
|
private ClassEntity(ClassContext context, List<CAstEntity> entities, ClassType ct, String name, Position p) {
|
||||||
fContext = context;
|
fContext = context;
|
||||||
this.fEntities = entities;
|
this.fEntities = entities;
|
||||||
fCT = ct;
|
fCT = ct;
|
||||||
|
@ -1286,7 +1292,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getAllScopedEntities() {
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
return Collections.singletonMap(null, fEntities);
|
return Collections.singletonMap(null, fEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1341,7 +1347,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
private final String[] argumentNames;
|
private final String[] argumentNames;
|
||||||
|
|
||||||
private ProcedureEntity(CAstNode pdast, TypeSystem system, CodeInstance pd, Type declaringType, String[] argumentNames,
|
private ProcedureEntity(CAstNode pdast, TypeSystem system, CodeInstance pd, Type declaringType, String[] argumentNames,
|
||||||
Map<CAstNode,CAstEntity> entities, MethodContext mc) {
|
Map<CAstNode, CAstEntity> entities, MethodContext mc) {
|
||||||
super(entities);
|
super(entities);
|
||||||
fPdast = pdast;
|
fPdast = pdast;
|
||||||
fSystem = system;
|
fSystem = system;
|
||||||
|
@ -1351,16 +1357,16 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
fMc = mc;
|
fMc = mc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProcedureEntity(CAstNode pdast, TypeSystem system, CodeInstance pd, String[] argumentNames, Map<CAstNode,CAstEntity> entities,
|
private ProcedureEntity(CAstNode pdast, TypeSystem system, CodeInstance pd, String[] argumentNames,
|
||||||
MethodContext mc) {
|
Map<CAstNode, CAstEntity> entities, MethodContext mc) {
|
||||||
this(pdast, system, pd, ((MemberInstance)pd).container(), argumentNames, entities, mc);
|
this(pdast, system, pd, ((MemberInstance) pd).container(), argumentNames, entities, mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List formalTypes() {
|
private List formalTypes() {
|
||||||
if (fPd instanceof ProcedureInstance) {
|
if (fPd instanceof ProcedureInstance) {
|
||||||
return ((ProcedureInstance)fPd).formalTypes();
|
return ((ProcedureInstance) fPd).formalTypes();
|
||||||
} else {
|
} else {
|
||||||
return Collections.EMPTY_LIST;
|
return Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1376,12 +1382,12 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
if (fPd instanceof ConstructorInstance) {
|
if (fPd instanceof ConstructorInstance) {
|
||||||
return MethodReference.initAtom.toString();
|
return MethodReference.initAtom.toString();
|
||||||
} else {
|
} else {
|
||||||
if (fPd instanceof InitializerInstance) {
|
if (fPd instanceof InitializerInstance) {
|
||||||
return MethodReference.clinitName.toString();
|
return MethodReference.clinitName.toString();
|
||||||
} else {
|
} else {
|
||||||
Assertions._assert(fPd instanceof MethodInstance);
|
Assertions._assert(fPd instanceof MethodInstance);
|
||||||
return ((MethodInstance) fPd).name();
|
return ((MethodInstance) fPd).name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1428,7 +1434,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
private List<CAstType> fParameterTypes = null;
|
private List<CAstType> fParameterTypes = null;
|
||||||
|
|
||||||
public CAstType getReturnType() {
|
public CAstType getReturnType() {
|
||||||
return fMc.getTypeDictionary().getCAstTypeFor((fPd instanceof MethodInstance) ? ((MethodInstance) fPd).returnType() : fSystem.Void());
|
return fMc.getTypeDictionary().getCAstTypeFor(
|
||||||
|
(fPd instanceof MethodInstance) ? ((MethodInstance) fPd).returnType() : fSystem.Void());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getArgumentTypes() {
|
public List getArgumentTypes() {
|
||||||
|
@ -1457,20 +1464,17 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
if (fExceptionTypes == null) {
|
if (fExceptionTypes == null) {
|
||||||
fExceptionTypes = new LinkedHashSet<CAstType>();
|
fExceptionTypes = new LinkedHashSet<CAstType>();
|
||||||
|
|
||||||
if (fPd instanceof ProcedureInstance) {
|
if (fPd instanceof ProcedureInstance) {
|
||||||
List exceptions = ((ProcedureInstance)fPd).throwTypes();
|
List exceptions = ((ProcedureInstance) fPd).throwTypes();
|
||||||
|
|
||||||
if (exceptions != null) {
|
if (exceptions != null) {
|
||||||
for (Iterator iterator = exceptions.iterator();
|
for (Iterator iterator = exceptions.iterator(); iterator.hasNext();) {
|
||||||
iterator.hasNext();)
|
Type type = (Type) iterator.next();
|
||||||
{
|
fExceptionTypes.add(fMc.getTypeDictionary().getCAstTypeFor(type));
|
||||||
Type type = (Type) iterator.next();
|
}
|
||||||
fExceptionTypes.add(
|
}
|
||||||
fMc.getTypeDictionary().getCAstTypeFor(type));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fExceptionTypes;
|
return fExceptionTypes;
|
||||||
}
|
}
|
||||||
|
@ -1525,8 +1529,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return EmptyIterator.instance();
|
return EmptyIterator.instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getAllScopedEntities() {
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
return Collections.EMPTY_MAP;
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode getAST() {
|
public CAstNode getAST() {
|
||||||
|
@ -1575,7 +1579,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
CAstNodeTypeMapRecorder getNodeTypeMap();
|
CAstNodeTypeMapRecorder getNodeTypeMap();
|
||||||
|
|
||||||
Collection<Pair<Type,Object>> getCatchTargets(Type label);
|
Collection<Pair<Type, Object>> getCatchTargets(Type label);
|
||||||
|
|
||||||
Node getContinueFor(String label);
|
Node getContinueFor(String label);
|
||||||
|
|
||||||
|
@ -1593,7 +1597,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
List<ClassMember> getInitializers();
|
List<ClassMember> getInitializers();
|
||||||
|
|
||||||
Map<Node,String> getLabelMap();
|
Map<Node, String> getLabelMap();
|
||||||
|
|
||||||
boolean needLVal();
|
boolean needLVal();
|
||||||
}
|
}
|
||||||
|
@ -1629,7 +1633,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return parent.getNodeTypeMap();
|
return parent.getNodeTypeMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Pair<Type,Object>> getCatchTargets(Type label) {
|
public Collection<Pair<Type, Object>> getCatchTargets(Type label) {
|
||||||
return parent.getCatchTargets(label);
|
return parent.getCatchTargets(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1665,7 +1669,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return parent.getInitializers();
|
return parent.getInitializers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Node,String> getLabelMap() {
|
public Map<Node, String> getLabelMap() {
|
||||||
return parent.getLabelMap();
|
return parent.getLabelMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1751,7 +1755,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Node,String> getLabelMap() {
|
public Map<Node, String> getLabelMap() {
|
||||||
Assertions.UNREACHABLE("ClassContext.getLabelMap()");
|
Assertions.UNREACHABLE("ClassContext.getLabelMap()");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1769,11 +1773,11 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
final CAstNodeTypeMapRecorder fNodeTypeMap = new CAstNodeTypeMapRecorder();
|
final CAstNodeTypeMapRecorder fNodeTypeMap = new CAstNodeTypeMapRecorder();
|
||||||
|
|
||||||
private final Map<Node,String> labelMap = new HashMap<Node,String>(2);
|
private final Map<Node, String> labelMap = new HashMap<Node, String>(2);
|
||||||
|
|
||||||
private final Map<CAstNode,CAstEntity> fEntities;
|
private final Map<CAstNode, CAstEntity> fEntities;
|
||||||
|
|
||||||
public CodeBodyContext(WalkContext parent, Map<CAstNode,CAstEntity> entities) {
|
public CodeBodyContext(WalkContext parent, Map<CAstNode, CAstEntity> entities) {
|
||||||
super(parent);
|
super(parent);
|
||||||
fEntities = entities;
|
fEntities = entities;
|
||||||
}
|
}
|
||||||
|
@ -1798,7 +1802,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return fEntities;
|
return fEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Node,String> getLabelMap() {
|
public Map<Node, String> getLabelMap() {
|
||||||
return labelMap;
|
return labelMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1810,13 +1814,13 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
public class MethodContext extends CodeBodyContext {
|
public class MethodContext extends CodeBodyContext {
|
||||||
final CodeInstance fPI;
|
final CodeInstance fPI;
|
||||||
|
|
||||||
public MethodContext(CodeInstance pi, Map<CAstNode,CAstEntity> entities, WalkContext parent) {
|
public MethodContext(CodeInstance pi, Map<CAstNode, CAstEntity> entities, WalkContext parent) {
|
||||||
super(parent, entities);
|
super(parent, entities);
|
||||||
fPI = pi;
|
fPI = pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Pair<Type,Object>> getCatchTargets(Type label) {
|
public Collection<Pair<Type, Object>> getCatchTargets(Type label) {
|
||||||
return Collections.singleton(new Pair<Type,Object>(fREType, CAstControlFlowMap.EXCEPTION_TO_EXIT));
|
return Collections.singleton(new Pair<Type, Object>(fREType, CAstControlFlowMap.EXCEPTION_TO_EXIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeInstance getEnclosingMethod() {
|
public CodeInstance getEnclosingMethod() {
|
||||||
|
@ -1828,7 +1832,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final Try tryNode;
|
private final Try tryNode;
|
||||||
|
|
||||||
Collection<Pair<Type,Object>> fCatchNodes = new ArrayList<Pair<Type,Object>>();
|
Collection<Pair<Type, Object>> fCatchNodes = new ArrayList<Pair<Type, Object>>();
|
||||||
|
|
||||||
TryCatchContext(WalkContext parent, Try tryNode) {
|
TryCatchContext(WalkContext parent, Try tryNode) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
@ -1836,20 +1840,20 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
for (Iterator catchIter = tryNode.catchBlocks().iterator(); catchIter.hasNext();) {
|
for (Iterator catchIter = tryNode.catchBlocks().iterator(); catchIter.hasNext();) {
|
||||||
Catch c = (Catch) catchIter.next();
|
Catch c = (Catch) catchIter.next();
|
||||||
Pair<Type,Object> p = new Pair<Type,Object>(c.catchType(), c);
|
Pair<Type, Object> p = new Pair<Type, Object>(c.catchType(), c);
|
||||||
|
|
||||||
fCatchNodes.add(p);
|
fCatchNodes.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Pair<Type,Object>> getCatchTargets(Type label) {
|
public Collection<Pair<Type, Object>> getCatchTargets(Type label) {
|
||||||
// Look for all matching targets for this thrown type:
|
// Look for all matching targets for this thrown type:
|
||||||
// if supertpe match, then return only matches at this catch
|
// if supertpe match, then return only matches at this catch
|
||||||
// if subtype match, then matches here and parent matches
|
// if subtype match, then matches here and parent matches
|
||||||
Collection<Pair<Type,Object>> catchNodes = new ArrayList<Pair<Type,Object>>();
|
Collection<Pair<Type, Object>> catchNodes = new ArrayList<Pair<Type, Object>>();
|
||||||
|
|
||||||
for (Iterator<Pair<Type,Object>> iter = fCatchNodes.iterator(); iter.hasNext();) {
|
for (Iterator<Pair<Type, Object>> iter = fCatchNodes.iterator(); iter.hasNext();) {
|
||||||
Pair<Type,Object> p = (Pair<Type,Object>) iter.next();
|
Pair<Type, Object> p = (Pair<Type, Object>) iter.next();
|
||||||
Type catchType = (Type) p.fst;
|
Type catchType = (Type) p.fst;
|
||||||
|
|
||||||
// _must_ be caught
|
// _must_ be caught
|
||||||
|
@ -1892,7 +1896,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Pair<Type,Object>> getCatchTargets(Type label) {
|
public Collection<Pair<Type, Object>> getCatchTargets(Type label) {
|
||||||
Assertions.UNREACHABLE("RootContext.getCatchTargets()");
|
Assertions.UNREACHABLE("RootContext.getCatchTargets()");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1947,7 +1951,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Node,String> getLabelMap() {
|
public Map<Node, String> getLabelMap() {
|
||||||
Assertions.UNREACHABLE("RootContext.getLabelMap()");
|
Assertions.UNREACHABLE("RootContext.getLabelMap()");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2000,7 +2004,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
protected AssignmentContext(WalkContext parent) {
|
protected AssignmentContext(WalkContext parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needLVal() {
|
public boolean needLVal() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2045,7 +2049,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
public URL getURL() {
|
public URL getURL() {
|
||||||
try {
|
try {
|
||||||
String path= p.path();
|
String path = p.path();
|
||||||
return new URL("file:" + (path.length() == 0 ? p.file() : path));
|
return new URL("file:" + (path.length() == 0 ? p.file() : path));
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
Assertions.UNREACHABLE(e.toString());
|
Assertions.UNREACHABLE(e.toString());
|
||||||
|
@ -2184,12 +2188,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return quals;
|
return quals;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processClassMembers(Node n,
|
protected void processClassMembers(Node n, ClassType classType, List<ClassMember> members, DelegatingContext classContext,
|
||||||
ClassType classType,
|
List<CAstEntity> memberEntities) {
|
||||||
List<ClassMember> members,
|
|
||||||
DelegatingContext classContext,
|
|
||||||
List<CAstEntity> memberEntities)
|
|
||||||
{
|
|
||||||
// Collect all initializer-related gorp
|
// Collect all initializer-related gorp
|
||||||
for (Iterator memberIter = members.iterator(); memberIter.hasNext();) {
|
for (Iterator memberIter = members.iterator(); memberIter.hasNext();) {
|
||||||
ClassMember member = (ClassMember) memberIter.next();
|
ClassMember member = (ClassMember) memberIter.next();
|
||||||
|
@ -2225,37 +2225,31 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add class initializer, if needed
|
// add class initializer, if needed
|
||||||
if (! classContext.getStaticInitializers().isEmpty()) {
|
if (!classContext.getStaticInitializers().isEmpty()) {
|
||||||
InitializerInstance initInstance =
|
InitializerInstance initInstance = new InitializerInstance_c(fTypeSystem, n.position(), classType, Flags.STATIC);
|
||||||
new InitializerInstance_c(fTypeSystem,
|
|
||||||
n.position(),
|
|
||||||
classType,
|
|
||||||
Flags.STATIC);
|
|
||||||
|
|
||||||
Map<CAstNode,CAstEntity> childEntities =
|
Map<CAstNode, CAstEntity> childEntities = new HashMap<CAstNode, CAstEntity>();
|
||||||
new HashMap<CAstNode,CAstEntity>();
|
final MethodContext mc = new MethodContext(initInstance, childEntities, classContext);
|
||||||
final MethodContext mc =
|
|
||||||
new MethodContext(initInstance, childEntities, classContext);
|
|
||||||
|
|
||||||
List inits = classContext.getStaticInitializers();
|
List inits = classContext.getStaticInitializers();
|
||||||
CAstNode[] bodyNodes = new CAstNode[inits.size()];
|
CAstNode[] bodyNodes = new CAstNode[inits.size()];
|
||||||
insertInitializers(mc, bodyNodes, true, 0);
|
insertInitializers(mc, bodyNodes, true, 0);
|
||||||
|
|
||||||
CAstNode ast =
|
CAstNode ast = makeNode(mc, fFactory, n, CAstNode.BLOCK_STMT, bodyNodes);
|
||||||
makeNode(mc, fFactory, n, CAstNode.BLOCK_STMT, bodyNodes);
|
|
||||||
|
memberEntities.add(new ProcedureEntity(ast, fTypeSystem, initInstance, new String[0], childEntities, mc));
|
||||||
|
|
||||||
memberEntities.add(new ProcedureEntity(ast, fTypeSystem, initInstance, new String[0], childEntities, mc));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addConstructorsToAnonymousClass(New n, ParsedClassType anonType, ClassContext classContext, List<CAstEntity> memberEntities) {
|
protected void addConstructorsToAnonymousClass(New n, ParsedClassType anonType, ClassContext classContext,
|
||||||
|
List<CAstEntity> memberEntities) {
|
||||||
List superConstructors = ((ClassType) anonType.superType()).constructors();
|
List superConstructors = ((ClassType) anonType.superType()).constructors();
|
||||||
|
|
||||||
for (Iterator iter = superConstructors.iterator(); iter.hasNext();) {
|
for (Iterator iter = superConstructors.iterator(); iter.hasNext();) {
|
||||||
ConstructorInstance superCtor = (ConstructorInstance) iter.next();
|
ConstructorInstance superCtor = (ConstructorInstance) iter.next();
|
||||||
|
|
||||||
Map<CAstNode,CAstEntity> childEntities = new HashMap<CAstNode,CAstEntity>();
|
Map<CAstNode, CAstEntity> childEntities = new HashMap<CAstNode, CAstEntity>();
|
||||||
final MethodContext mc = new MethodContext(superCtor, childEntities, classContext);
|
final MethodContext mc = new MethodContext(superCtor, childEntities, classContext);
|
||||||
|
|
||||||
String[] fakeArguments = new String[superCtor.formalTypes().size() + 1];
|
String[] fakeArguments = new String[superCtor.formalTypes().size() + 1];
|
||||||
|
@ -2267,7 +2261,8 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
|
|
||||||
CAstNode[] bodyNodes = new CAstNode[inits.size() + 1];
|
CAstNode[] bodyNodes = new CAstNode[inits.size() + 1];
|
||||||
|
|
||||||
CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(superCtor), IInvokeInstruction.Dispatch.SPECIAL);
|
CallSiteReference callSiteRef = CallSiteReference.make(0, fIdentityMapper.getMethodRef(superCtor),
|
||||||
|
IInvokeInstruction.Dispatch.SPECIAL);
|
||||||
CAstNode[] children = new CAstNode[fakeArguments.length + 1];
|
CAstNode[] children = new CAstNode[fakeArguments.length + 1];
|
||||||
children[0] = makeNode(mc, fFactory, n, CAstNode.SUPER);
|
children[0] = makeNode(mc, fFactory, n, CAstNode.SUPER);
|
||||||
children[1] = fFactory.makeConstant(callSiteRef);
|
children[1] = fFactory.makeConstant(callSiteRef);
|
||||||
|
@ -2323,7 +2318,7 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
return new ClassEntity(classContext, memberEntities, anonType, anonTypeName, n.position());
|
return new ClassEntity(classContext, memberEntities, anonType, anonTypeName, n.position());
|
||||||
} else if (rootNode instanceof ProcedureDecl) {
|
} else if (rootNode instanceof ProcedureDecl) {
|
||||||
final ProcedureDecl pd = (ProcedureDecl) rootNode;
|
final ProcedureDecl pd = (ProcedureDecl) rootNode;
|
||||||
final Map<CAstNode,CAstEntity> memberEntities = new LinkedHashMap<CAstNode,CAstEntity>();
|
final Map<CAstNode, CAstEntity> memberEntities = new LinkedHashMap<CAstNode, CAstEntity>();
|
||||||
final MethodContext mc = new MethodContext(pd.procedureInstance(), memberEntities, context);
|
final MethodContext mc = new MethodContext(pd.procedureInstance(), memberEntities, context);
|
||||||
|
|
||||||
CAstNode pdAST = null;
|
CAstNode pdAST = null;
|
||||||
|
@ -2386,16 +2381,16 @@ public class PolyglotJava2CAstTranslator implements TranslatorToCAst {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int insertInitializers(WalkContext wc, CAstNode[] initCode, boolean wantStatic, int offset) {
|
private int insertInitializers(WalkContext wc, CAstNode[] initCode, boolean wantStatic, int offset) {
|
||||||
List inits = wantStatic? wc.getStaticInitializers(): wc.getInitializers();
|
List inits = wantStatic ? wc.getStaticInitializers() : wc.getInitializers();
|
||||||
|
|
||||||
for (Iterator iter = inits.iterator(); iter.hasNext(); offset++) {
|
for (Iterator iter = inits.iterator(); iter.hasNext(); offset++) {
|
||||||
ClassMember init = (ClassMember) iter.next();
|
ClassMember init = (ClassMember) iter.next();
|
||||||
CAstNode initNode = walkNodes(init, wc);
|
CAstNode initNode = walkNodes(init, wc);
|
||||||
|
|
||||||
if (initNode != null) {
|
if (initNode != null) {
|
||||||
initCode[offset] = initNode;
|
initCode[offset] = initNode;
|
||||||
} else {
|
} else {
|
||||||
initCode[offset] = makeNode(wc, fFactory, null, CAstNode.EMPTY);
|
initCode[offset] = makeNode(wc, fFactory, null, CAstNode.EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return offset;
|
return offset;
|
||||||
|
|
Loading…
Reference in New Issue