From 31b7d2a796838e33ae18d23bd8ffd7d7bc8f0d85 Mon Sep 17 00:00:00 2001 From: jzhou Date: Sat, 3 Dec 2011 01:42:41 +0000 Subject: [PATCH] Fix another inner class bug: every inner class along the inherited chain has a pointer to its enclosing class; If an inner class inherits from another inner class, when it calls the constructor of its super class, it passes in its enclosing class for the superenclosing class by default --- Robust/src/IR/Tree/BuildIR.java | 29 ++++++++++++-- Robust/src/IR/Tree/SemanticCheck.java | 48 ++++++++++++++++++----- Robust/src/Tests/DoTests | 2 +- Robust/src/Tests/inner.java | 2 + Robust/src/Tests/output/inner.output.goal | 5 +++ 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index a12dcf0a..7b14d103 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -184,18 +184,41 @@ public class BuildIR { public void parseInitializers(ClassDescriptor cn) { Vector fv=cn.getFieldVec(); + Iterator methodit = cn.getMethods(); + HashMap md2pos = new HashMap(); + while(methodit.hasNext()) { + MethodDescriptor currmd=(MethodDescriptor)methodit.next(); + if(currmd.isConstructor()) { + BlockNode bn=state.getMethodBody(currmd); + // if there are super(...) invokation, the initializers should be invoked after that + int i = 0; + for(; i < bn.size(); i++) { + if(Kind.BlockExpressionNode==bn.get(i).kind() + &&(((BlockExpressionNode)bn.get(i)).getExpression() instanceof MethodInvokeNode) + &&((MethodInvokeNode)(((BlockExpressionNode)bn.get(i)).getExpression())).getMethodName().equals("super")) { + break; + } + } + if(i==bn.size()) { + md2pos.put(currmd, 0); + } else { + md2pos.put(currmd, i+1); + } + } + } int pos = 0; for(int i=0; i