+public void parseInitializers(ClassDescriptor cn){
+ Vector fv=cn.getFieldVec();
+ int pos = 0;
+ 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.addBlockStatementAt(new BlockExpressionNode(an), pos);
+ }
+ }
+ pos++;
+ }
+ }
+ }
+
+ private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
+ ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
+ ecd.setAsEnum();
+ if(cn != null) {
+ ecd.setSurroundingClass(cn.getSymbol());
+ ecd.setSurrounding(cn);
+ cn.addEnum(ecd);
+ }
+ if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)||
+ ecd.getSymbol().equals(TypeUtil.TagClass))) {
+ ecd.setSuper(TypeUtil.ObjectClass);
+ }
+ ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
+ parseEnumBody(ecd, pn.getChild("enumbody"));
+ return ecd;
+ }
+
+ private void parseEnumBody(ClassDescriptor cn, ParseNode pn) {
+ ParseNode decls=pn.getChild("enum_constants_list");
+ if (decls!=null) {
+ ParseNodeVector pnv=decls.getChildren();
+ for(int i=0; i<pnv.size(); i++) {
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"enum_constant")) {
+ parseEnumConstant(cn,decl);
+ } else throw new Error();
+ }
+ }
+ }
+
+ private void parseEnumConstant(ClassDescriptor cn, ParseNode pn) {
+ cn.addEnumConstant(pn.getChild("name").getTerminal());
+ }
+
+ public ClassDescriptor parseInterfaceDecl(ParseNode pn) {
+ ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
+ //cn.setAsInterface();
+ if (!isEmpty(pn.getChild("superIF").getTerminal())) {
+ /* parse inherited interface name */
+ ParseNode snlist=pn.getChild("superIF").getChild("extend_interface_list");
+ ParseNodeVector pnv=snlist.getChildren();
+ for(int i=0; i<pnv.size(); i++) {
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"type")) {
+ NameDescriptor nd=parseName(decl.getChild("class").getChild("name"));
+ cn.addSuperInterface(nd.toString());
+ }
+ }
+ }
+ cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
+ parseInterfaceBody(cn, pn.getChild("interfacebody"));
+ return cn;
+ }
+
+ private void parseInterfaceBody(ClassDescriptor cn, ParseNode pn) {
+ assert(cn.isInterface());
+ ParseNode decls=pn.getChild("interface_member_declaration_list");
+ if (decls!=null) {
+ ParseNodeVector pnv=decls.getChildren();
+ for(int i=0; i<pnv.size(); i++) {
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"constant")) {
+ parseInterfaceConstant(cn,decl);
+ } else if (isNode(decl,"method")) {
+ parseInterfaceMethod(cn,decl.getChild("method_declaration"));
+ } else throw new Error();
+ }
+ }
+ }
+
+ private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
+ if (pn!=null) {
+ parseFieldDecl(cn,pn.getChild("field_declaration"));
+ return;
+ }
+ throw new Error();
+ }
+
+ private void parseInterfaceMethod(ClassDescriptor cn, ParseNode pn) {
+ ParseNode headern=pn.getChild("header");
+ ParseNode bodyn=pn.getChild("body");
+ MethodDescriptor md=parseMethodHeader(headern.getChild("method_header"));
+ md.getModifiers().addModifier(Modifiers.PUBLIC);
+ md.getModifiers().addModifier(Modifiers.ABSTRACT);
+ try {
+ BlockNode bn=parseBlock(bodyn);
+ cn.addMethod(md);
+ state.addTreeCode(md,bn);
+
+ // this is a hack for investigating new language features
+ // at the AST level, someday should evolve into a nice compiler
+ // option *wink*
+ //if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
+ // md.getSymbol().equals( ***put your method in here like: "main" )
+ //) {
+ // bn.setStyle( BlockNode.NORMAL );
+ // System.out.println( bn.printNode( 0 ) );
+ //}
+
+ } catch (Exception e) {
+ System.out.println("Error with method:"+md.getSymbol());
+ e.printStackTrace();
+ throw new Error();
+ } catch (Error e) {
+ System.out.println("Error with method:"+md.getSymbol());
+ e.printStackTrace();
+ throw new Error();
+ }
+ }
+