From: bdemsky Date: Fri, 25 Feb 2011 01:05:41 +0000 (+0000) Subject: make field shadowing work X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b52b39f48173e26ab1601b86d4d6d65f9e98a795;p=IRC.git make field shadowing work --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 3ee3349f..25f9cbf1 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -3254,7 +3254,7 @@ public class BuildCode { private void generateFlatFieldNode(FlatMethod fm, LocalityBinding lb, FlatFieldNode ffn, PrintWriter output) { if (state.SINGLETM) { //single machine transactional memory case - String field=(ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol(); + String field=ffn.getField().getSafeSymbol(); String src=generateTemp(fm, ffn.getSrc(),lb); String dst=generateTemp(fm, ffn.getDst(),lb); @@ -3274,7 +3274,7 @@ public class BuildCode { } else if (state.DSM) { Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc()); if (status==LocalityAnalysis.GLOBAL) { - String field=(ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol(); + String field=ffn.getField().getSafeSymbol(); String src=generateTemp(fm, ffn.getSrc(),lb); String dst=generateTemp(fm, ffn.getDst(),lb); @@ -3304,7 +3304,7 @@ public class BuildCode { } else if (status==LocalityAnalysis.LOCAL) { if (ffn.getField().getType().isPtr()&& ffn.getField().isGlobal()) { - String field=(ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol(); + String field=ffn.getField().getSafeSymbol(); String src=generateTemp(fm, ffn.getSrc(),lb); String dst=generateTemp(fm, ffn.getDst(),lb); output.println(dst+"="+ src +"->"+field+ ";"); @@ -3351,7 +3351,7 @@ public class BuildCode { output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); } output.println("}"); - output.println("#endif // MGC_STATIC_INIT_CHECK"); + output.println("#endif // MGC_STATIC_INIT_CHECK"); } } } @@ -3361,19 +3361,16 @@ public class BuildCode { output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ ffn.getField().getClassDescriptor().getSafeSymbol()+ffn.getField().getSafeSymbol()+";"); } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"=*"+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ - (ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol()+";"); + output.println(generateTemp(fm, ffn.getDst(),lb)+"=*"+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); } } else if (ffn.getField().isEnum()) { // an Enum value, directly replace the field access as int output.println(generateTemp(fm, ffn.getDst(), lb) + "=" + ffn.getField().enumValue() + ";"); } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ - (ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol()+";"); - } + output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); + } } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ - (ffn.getField().getClassDescriptor()==null?"":ffn.getField().getClassDescriptor().getSafeSymbol()) + ffn.getField().getSafeSymbol()+";"); + output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); } } } diff --git a/Robust/src/IR/Flat/FieldShadow.java b/Robust/src/IR/Flat/FieldShadow.java index 993bc5af..2f5f9abb 100644 --- a/Robust/src/IR/Flat/FieldShadow.java +++ b/Robust/src/IR/Flat/FieldShadow.java @@ -3,33 +3,33 @@ import IR.*; import java.util.*; public class FieldShadow { - public static void handleFieldShadow(State state) { + public static void handleFieldShadow(State state) { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); - HashMap> namemap=new HashMap>(); + HashMap> namemap=new HashMap>(); while(classit.hasNext()) { ClassDescriptor cd=(ClassDescriptor)classit.next(); - handleClass(cd, state, namemap); + handleClass(cd, state, namemap); } - } - - private static void handleClass(ClassDescriptor cd, State state, HashMap> namemap) { - if (cd.getSuperDesc()!=null&&!namemap.containsKey(cd.getSuperDesc())) - handleClass(cd.getSuperDesc(), state, namemap); - HashMap supermap=cd.getSuperDesc()!=null?namemap.get(cd.getSuperDesc()):new HashMap(); - - HashMap fieldmap=new HashMap(); - namemap.put(cd, fieldmap); - - for(Iterator fieldit=cd.getFields();fieldit.hasNext();) { - FieldDescriptor fd=(FieldDescriptor)fieldit.next(); - if (supermap.containsKey(fd.getSymbol())) { - Integer oldint=supermap.get(fd.getSymbol()); - int newint=oldint.intValue()+1; - namemap.put(fd.getSymbol(), new Integer(newint)); - fd.changeSafeSymbol(newint); - } else { - namemap.put(fd.getSymbol(), new Integer(0)); - } - } - } + } + + private static void handleClass(ClassDescriptor cd, State state, HashMap> namemap) { + if (cd.getSuperDesc()!=null&&!namemap.containsKey(cd.getSuperDesc())) + handleClass(cd.getSuperDesc(), state, namemap); + HashMap supermap=cd.getSuperDesc()!=null?namemap.get(cd.getSuperDesc()):new HashMap(); + + HashMap fieldmap=new HashMap(); + namemap.put(cd, fieldmap); + + for(Iterator fieldit=cd.getFields();fieldit.hasNext();) { + FieldDescriptor fd=(FieldDescriptor)fieldit.next(); + if (supermap.containsKey(fd.getSymbol())) { + Integer oldint=supermap.get(fd.getSymbol()); + int newint=oldint.intValue()+1; + fieldmap.put(fd.getSymbol(), new Integer(newint)); + fd.changeSafeSymbol(newint); + } else { + fieldmap.put(fd.getSymbol(), new Integer(0)); + } + } + } } \ No newline at end of file