Skip to content

Commit d933be2

Browse files
author
rcartwright
committed
This revision fixes a few bugs involving cross references and
incomplete symbols in the presence of errors that were not detected by unit testing. The following files were modified: M src/edu/rice/cs/javalanglevels/SymbolData.java M src/edu/rice/cs/javalanglevels/LanguageLevelVisitor.java M src/edu/rice/cs/javalanglevels/ClassBodyIntermediateVisitor.java git-svn-id: file:///tmp/test-svn/trunk@5391 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 65fb8db commit d933be2

File tree

3 files changed

+52
-41
lines changed

3 files changed

+52
-41
lines changed

javalanglevels/src/edu/rice/cs/javalanglevels/ClassBodyIntermediateVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public Void forConstructorDef(ConstructorDef that) {
228228
VariableData[] vds = formalParameters2VariableData(that.getParameters(), _enclosing);
229229
if (! _checkError()) { // if there was an error converting the formalParameters, don't use them.
230230
md.setParams(vds);
231-
if (!md.addFinalVars(vds)) {
231+
if (! md.addFinalVars(vds)) {
232232
_addAndIgnoreError("You cannot have two method parameters with the same name", that);
233233
}
234234
}

javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelVisitor.java

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -887,29 +887,42 @@ protected SymbolData defineSymbolData(final TypeDefBase typeDefBase, final Strin
887887
// Create the LinkedList for the SymbolDatas of the interfaces
888888
final ArrayList<SymbolData> interfaces = new ArrayList<SymbolData>();
889889

890-
// Get or create SymbolDatas (continuations) for the interfaces
890+
// Get or create SymbolDatas for the interfaces
891891
ReferenceType[] rts = typeDefBase.getInterfaces();
892-
for (final ReferenceType rt: rts) {
893-
SymbolData sD = _lookupTypeFromWithinClass(rt, enclosingClassName);
894-
if (sD != null && ! sD.isInterface()) {
895-
sD.setInterface(true);
896-
// System.err.println("Interface type = " + sD);
897-
// assert false;
892+
for (int i = 0; i < rts.length; i++) {
893+
final ReferenceType rt = rts[i];
894+
final String rtName = rt.getName();
895+
boolean forwardRef = false;
896+
SymbolData iD = _lookupTypeFromWithinClass(rt, enclosingClassName);
897+
if (iD != null && ! iD.isContinuation() && ! iD.isInterface()) {
898+
_addError("The symbol " + rtName + " is not an interface", typeDefBase);
898899
}
899-
interfaces.add(sD); // Note: confirm that null can be added to an ArrayList
900-
if (sD == null) {
901-
// create a fixup for this interface reference
900+
if (iD == null || iD.isContinuation()) { // create a dummy symbol pending fixUp TODO: is this necessary?
901+
iD = new SymbolData(rtName);
902+
forwardRef = true;
903+
}
904+
905+
interfaces.add(iD);
906+
if (forwardRef) {
907+
// create a fixup for this interface slot
908+
final int j = i;
902909
Command fixUp = new Command() {
903910
public void execute() {
904-
SymbolData newSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
905-
assert newSD != null && newSD.isInterface(); // EXPAND
906-
int lastIndex = interfaces.size() - 1;
907-
interfaces.set(lastIndex, newSD);
911+
SymbolData newID = _lookupTypeFromWithinClass(rt, enclosingClassName);
912+
if (newID == null) _addError("The symbol " + rtName + " is not defined", typeDefBase);
913+
else if (! newID.isInterface())
914+
_addError("The symbol " + rtName + " is not an interface", typeDefBase);
915+
interfaces.set(j, newID);
916+
sd.addEnclosingData(newID);
908917
}
909918
};
910919
fixUps.add(fixUp);
911920
}
912921
}
922+
923+
// Set the inferfaces; fixups will be done on the elements of the interface ArrayList, but this does not
924+
// add the found interface to the enclosing data of sd.
925+
sd.setInterfaces(interfaces);
913926

914927
// Create SymbolData variable for superclass
915928
SymbolData superSD = null;
@@ -918,39 +931,32 @@ public void execute() {
918931

919932
if (typeDefBase instanceof InterfaceDef) {
920933
// set Object as the super class of this, so that it will know it implements Object's methods.
921-
superSD = getSymbolData("java.lang.Object", typeDefBase.getSourceInfo(), false);
934+
SymbolData objectSD = getSymbolData("java.lang.Object", typeDefBase.getSourceInfo(), false);
922935
sd.setInterface(true);
923-
sd.setSuperClass(superSD);
936+
sd.setSuperClass(objectSD);
924937
}
925938

926939
else if (typeDefBase instanceof ClassDef) {
940+
sd.setInterface(false);
927941
ClassDef cd = (ClassDef) typeDefBase;
928942
final ReferenceType rt = cd.getSuperclass();
929-
superSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
930-
// if (superSD == null && rt.getName().equals("Object")) {
931-
// System.err.println("ALARM: _lookupTypeFromWithinClass for 'Object' returned null");
932-
// }
933-
sd.setInterface(false);
943+
superSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
934944

935945
if (superSD != null) sd.setSuperClass(superSD);
936946
else {
937947
Command fixUp = new Command() {
938948
public void execute() {
939949
SymbolData newSuperSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
940-
// System.err.println("***** In a FIXUP, looking up type " + rt + " from within " + enclosingClassName);
941950
if (newSuperSD == null)
942-
// newSuperSD = getSymbolData("java.lang.Object", typeDefBase.getSourceInfo(), false);
943-
_addAndIgnoreError("The class " + sd + " has an undefined superclass " + rt, typeDefBase);
944-
else
951+
_addError("The class " + sd + " has an undefined superclass " + rt, typeDefBase);
952+
else // TODO: Does not check that newSuperSD is not an interace
945953
sd.setSuperClass(newSuperSD);
946954
}
947955
};
948956
fixUps.add(fixUp);
949957
}
950958
}
951-
952-
// Set the inferfaces; fixups will be done on the elements of the interface ArrayList
953-
sd.setInterfaces(interfaces);
959+
954960

955961
// Remove symbol name from continuation table.
956962
_log.log("REMOVING continuation " + qualifiedTypeName);
@@ -1091,16 +1097,16 @@ else if (superSD.isInterface()) {
10911097
protected VariableData[] formalParameters2VariableData(FormalParameter[] fps, SymbolData enclosing) {
10921098
assert enclosing != null /* && (enclosing instanceof SymbolData || enclosing instanceof BlockData)*/;
10931099
// BodyData ::= MethodData | BlockData
1100+
10941101
// Utilities.show("formalParameters2VariableData called on " + fps);
1095-
// Should conssolidate with same method in FullJavadVisitor; almost identical
1102+
// Should consolidate with same method in FullJavadVisitor; almost identical
10961103
final VariableData[] varData = new VariableData[fps.length];
10971104
final String enclosingClassName = enclosing.getName();
10981105

1099-
VariableDeclarator vd;
11001106
String[] mav = getFormalParameterMav(enclosing);
11011107

1102-
for (int i = 0; i < varData.length; i++) {
1103-
vd = fps[i].getDeclarator();
1108+
for (int i = 0; i < fps.length; i++) {
1109+
VariableDeclarator vd = fps[i].getDeclarator();
11041110
String name = vd.getName().getText(); // getName returns a Word
11051111

11061112
Type type = vd.getType();
@@ -1118,6 +1124,9 @@ protected VariableData[] formalParameters2VariableData(FormalParameter[] fps, Sy
11181124
if (sd == null) { // TODO !!!: can this happen?
11191125
// To establish a reference to a not-yet-defined type, create a fixup
11201126
final int j = i;
1127+
/* The following is a kludge to make method signature collision detection work (unless different
1128+
* names are used for the same type). */
1129+
varData[j].setType(new SymbolData(typeName));
11211130
Command fixUp = new Command() {
11221131
public void execute() {
11231132
SymbolData newSd = _identifyType(typeName, si, enclosingClassName);
@@ -1132,7 +1141,6 @@ public void execute() {
11321141
varData[i].gotValue();
11331142
varData[i].setIsLocalVariable(true);
11341143
}
1135-
11361144
return varData;
11371145
}
11381146

javalanglevels/src/edu/rice/cs/javalanglevels/SymbolData.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,13 @@ private String _createErrorMessage(MethodData md) {
11141114
message.append(":");
11151115
}
11161116
for (int i = 0; i < params.length; i++) {
1117-
if (i > 0) {
1118-
message.append(",");
1117+
VariableData p = params[i];
1118+
if (p != null && p.getType() != null) {
1119+
if (i > 0) {
1120+
message.append(",");
1121+
}
1122+
message.append(" " + p.getType().getName());
11191123
}
1120-
message.append(" " + params[i].getType().getName());
11211124
}
11221125
return message.toString();
11231126
}
@@ -1131,7 +1134,7 @@ public void addMethod(MethodData method) {
11311134
// Detect repeated methods
11321135
if (repeatedSignature(_methods, method) != null) {
11331136
LanguageLevelVisitor.errors.addLast(new Pair<String, JExpressionIF>(_createErrorMessage(method),
1134-
method.getJExpression()));
1137+
method.getJExpression()));
11351138
}
11361139
else {
11371140
_methods.addLast(method);
@@ -1347,14 +1350,14 @@ public boolean implementsRunnable() {
13471350

13481351
/**Check to see if the interface i appears anywhere in the hierarchy for this class/interface*/
13491352
public boolean hasInterface(SymbolData i) {
1350-
if (i==null) return false;
1353+
if (i == null) return false;
13511354

13521355
if (getInterfaces().contains(i)) { return true; }
13531356

13541357
if ((this.getSuperClass() != null) && this.getSuperClass().hasInterface(i)) { return true; }
13551358

1356-
for (int j = 0; j<getInterfaces().size(); j++) {
1357-
if (getInterfaces().get(j).hasInterface(i)) {return true;}
1359+
for (int j = 0; j < getInterfaces().size(); j++) {
1360+
if (getInterfaces().get(j).hasInterface(i)) return true;
13581361
}
13591362
return false;
13601363
}

0 commit comments

Comments
 (0)