package Analysis.Disjoint;
+import java.io.*;
import java.util.*;
import IR.*;
}
+ public void writeState( FlatNode fn, String outputName ) {
+ DefiniteReachState state = makeIn( fn );
+ try {
+ BufferedWriter bw = new BufferedWriter( new FileWriter( outputName+".txt" ) );
+ bw.write( state.toString() );
+ bw.close();
+ } catch( IOException e ) {
+ System.out.println( "ERROR writing definite reachability state:\n "+e );
+ }
+ }
+
+
// get the current state for just after the given
// program point
private DefiniteReachState get( FlatNode fn ) {
rs = new HashMap<TempDescriptor, DefReachKnown>();
}
- // what are the transfer functions that are relevant for this analyis?
+
public void methodEntry(Set<TempDescriptor> parameters) {
// R' := {}
} break;
+ case FKind.FlatGenDefReachNode: {
+ FlatGenDefReachNode fgdrn = (FlatGenDefReachNode) fn;
+ if( doDefiniteReachAnalysis ) {
+ definiteReachAnalysis.writeState( fn, fgdrn.getOutputName() );
+ }
+ } break;
+
+
case FKind.FlatMethod: {
// construct this method's initial heap model (IHM)
// since we're working on the FlatMethod, we know
case FKind.FlatSESEEnterNode:
case FKind.FlatSESEExitNode:
case FKind.FlatGenReachNode:
+ case FKind.FlatGenDefReachNode:
case FKind.FlatExit:
return true;
case FKind.FlatSESEEnterNode:
case FKind.FlatSESEExitNode:
case FKind.FlatGenReachNode:
+ case FKind.FlatGenDefReachNode:
if (!useful.contains(fn)) {
useful.add(fn);
changed=true;
break;
case FKind.FlatGenReachNode:
- // this node is just for generating a reach graph
+ case FKind.FlatGenDefReachNode:
+ // these nodes are just for generating analysis data
// in disjointness analysis at a particular program point
break;
return new NodePair(fgrn, fgrn);
}
+ private NodePair flattenGenDefReachNode(GenDefReachNode gdrn) {
+ FlatGenDefReachNode fgdrn = new FlatGenDefReachNode(gdrn.getOutputName() );
+ return new NodePair(fgdrn, fgdrn);
+ }
+
private NodePair flattenSESENode(SESENode sn) {
if( sn.isStart() ) {
FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn);
case Kind.GenReachNode:
return flattenGenReachNode((GenReachNode)bsn);
+ case Kind.GenDefReachNode:
+ return flattenGenDefReachNode((GenDefReachNode)bsn);
+
case Kind.ContinueBreakNode:
return flattenContinueBreakNode((ContinueBreakNode)bsn);
}
public static final int FlatInstanceOfNode=26;
public static final int FlatExit=27;
public static final int FlatGenReachNode=28;
+ public static final int FlatGenDefReachNode=29;
}
--- /dev/null
+package IR.Flat;
+import IR.TypeDescriptor;
+
+public class FlatGenDefReachNode extends FlatNode {
+ String outputName;
+
+ public FlatGenDefReachNode(String outputName) {
+ this.outputName = outputName;
+ }
+
+ public String getOutputName() {
+ return outputName;
+ }
+
+ public FlatNode clone(TempMap t) {
+ return new FlatGenDefReachNode(outputName);
+ }
+ public void rewriteUse(TempMap t) {
+ }
+ public void rewriteDst(TempMap t) {
+ }
+
+
+ public String toString() {
+ return "FlatGenDefReachNode_"+outputName;
+ }
+
+ public int kind() {
+ return FKind.FlatGenDefReachNode;
+ }
+
+ public TempDescriptor [] writesTemps() {
+ return new TempDescriptor[0];
+ }
+}
ParseNode idopt_pn=pn.getChild("identifier_opt");
ParseNode name_pn=idopt_pn.getChild("name");
// name_pn.getTerminal() gives you the label
+
} else if (isNode(pn,"genreach")) {
String graphName = pn.getChild("graphName").getTerminal();
blockstatements.add(new GenReachNode(graphName) );
+ } else if (isNode(pn,"gen_def_reach")) {
+ String outputName = pn.getChild("outputName").getTerminal();
+ blockstatements.add(new GenDefReachNode(outputName) );
+
} else if(isNode(pn,"labeledstatement")) {
String labeledstatement = pn.getChild("name").getTerminal();
BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild(),labeledstatement);
--- /dev/null
+package IR.Tree;
+
+public class GenDefReachNode extends BlockStatementNode {
+ String outputName;
+
+ public GenDefReachNode(String outputName) {
+ assert outputName != null;
+ this.outputName = outputName;
+ }
+
+ public String printNode(int indent) {
+ return "genDefReach "+outputName;
+ }
+
+ public String getOutputName() {
+ return outputName;
+ }
+
+ public int kind() {
+ return Kind.GenDefReachNode;
+ }
+}
public final static int SwitchLabelNode=31;
public final static int SwitchBlockNode=32;
public final static int ClassTypeNode=33;
+ public final static int GenDefReachNode=34;
}
case Kind.SESENode:
case Kind.GenReachNode:
+ case Kind.GenDefReachNode:
// do nothing, no semantic check for SESEs
return;
}
key_table.put("float", new Integer(Sym.FLOAT));
key_table.put("for", new Integer(Sym.FOR));
key_table.put("genreach", new Integer(Sym.GENREACH));
+ key_table.put("gendefreach", new Integer(Sym.GEN_DEF_REACH));
key_table.put("goto", new Integer(Sym.GOTO));
key_table.put("if", new Integer(Sym.IF));
key_table.put("import", new Integer(Sym.IMPORT));
"else", "enum",
"extends", "external", "final", "finally",
"flag", //keyword for failure aware computation
- "float", "for", "genreach", "getoffset", "global", "goto", "if",
+ "float", "for", "gendefreach", "genreach", "getoffset", "global", "goto", "if",
"implements",
"import", "instanceof", "int",
"interface",
// added for disjoint reachability analysis
terminal GENREACH;
+terminal GEN_DEF_REACH;
// 19.2) The Syntactic Grammar
non terminal ParseNode finally;
//non terminal ParseNode assert_statement;
non terminal ParseNode genreach_statement;
+non terminal ParseNode gen_def_reach_statement;
// 19.12) Expressions
non terminal ParseNode primary, primary_no_new_array;
non terminal ParseNode class_instance_creation_expression;
| sese_statement:st {: RESULT=st; :}
| synchronized_statement:st {: RESULT=st; :}
| genreach_statement:st {: RESULT=st; :}
+ | gen_def_reach_statement:st {: RESULT=st; :}
| throw_statement:st {: RESULT=st; :}
| try_statement:st {: RESULT=st; :}
// | assert_statement
pn.addChild("graphName").addChild(graphName);
RESULT=pn; :}
;
+
+gen_def_reach_statement ::=
+ GEN_DEF_REACH IDENTIFIER:outputName SEMICOLON {:
+ ParseNode pn=new ParseNode("gen_def_reach",parser.lexer.line_num);
+ pn.addChild("outputName").addChild(outputName);
+ RESULT=pn; :}
+ ;
f = yodel( f, g );
+ gendefreach yo;
+
System.out.println( f );
}