this.safename = "___" + name + "___";
this.uniqueid=count++;
this.isglobal=isglobal;
- if (en!=null) throw new Error("Field initializers not implemented");
+ }
+
+ public ExpressionNode getExpressionNode(){
+ return en;
}
public boolean isStatic() {
continue;
if (isNode(type_pn,"class_declaration")) {
ClassDescriptor cn=parseTypeDecl(type_pn);
+ parseInitializers(cn);
if (toanalyze!=null)
toanalyze.add(cn);
state.addClass(cn);
while(!tovisit.isEmpty()) {
ClassDescriptor cd = (ClassDescriptor)tovisit.iterator().next();
tovisit.remove(cd);
-
+ parseInitializers(cd);
if(toanalyze != null) {
toanalyze.add(cd);
}
}
}
}
-
+
+ public void parseInitializers(ClassDescriptor cn){
+ Vector fv=cn.getFieldVec();
+ for(int i=0;i<fv.size();i++) {
+ FieldDescriptor fd=(FieldDescriptor)fv.get(i);
+ if(fd.getExpressionNode()!=null) {
+ Iterator methodit = cn.getMethods();
+ while(methodit.hasNext()){
+ MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+ if(currmd.isConstructor()){
+ BlockNode bn=state.getMethodBody(currmd);
+ NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
+ AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
+ bn.addFirstBlockStatement(new BlockExpressionNode(an));
+ }
+ }
+ }
+ }
+ }
+
private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
ecd.setAsEnum();
dotest WriteFile WriteFile.java
dotest ReadFile ReadFile.java
dotest FileLength FileLength.java
-dotest IntegerTest IntegerTest.java
\ No newline at end of file
+dotest IntegerTest IntegerTest.java
+dotest InitializerTest InitializerTest.java
\ No newline at end of file