Skip to content

Commit

Permalink
Some refactorings to profit from pattern-driven dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Nov 26, 2014
1 parent 3cdb6cf commit b004933
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProgramDependenceGraph</name>
<name>pdg</name>
<comment></comment>
<projects>
</projects>
Expand Down
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ProgramDependenceGraph
Bundle-SymbolicName: ProgramDependenceGraph
Bundle-SymbolicName: pdg
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.imp.pdb.values,
rascal
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#Program Dependence Graph
####UvA Software Engineering Master Project
####Lulu Zhang (10630856)
#### [UvA](http://www.uva.nl/en/home) [Software Engineering Master](http://www.software-engineering-amsterdam.nl/) Project

### Contributors:
* [Lulu Zhang](http://github.com/lulu516)
* [Vadim Zaytsev](http://github.com/grammarware)
----------

This is the PDG library in Rascal. *PDG.rsc* is the main module which combines the information of control dependences and data dependences. Here are the packages/folders in this library:
This is the PDG library in Rascal. **PDG.rsc** is the main module which combines the information of control dependences and data dependences. Here are the packages/folders in this library:

- *ControlDependence* : generates control flow of the source code and computes control dependences based on control flow and its post-dominator tree;

Expand Down
1 change: 1 addition & 0 deletions loc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find src -name '*.rsc' | xargs wc -l
91 changes: 42 additions & 49 deletions src/ControlDependence/ControlFlow.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,36 @@ public map[int, set[str]] getUses(){
return uses;
}

//analyze each statement
private CF statementCF(Statement stat){
switch(stat){
case \block(_): return blockCF(stat.statements);
case \if(_, _): return ifCF(stat);
case \if(_, _, _): return ifCF(stat);
case \for(_, _, _): return forCF(stat);
case \for(_, _, _, _): return forCF(stat);
case \while(_, _): return whileCF(stat);
case \switch(_, _): return switchCF(stat);

//firstStatement is -2: means it is a break
case \break(): return controlFlow([], -2, []);
case \break(_): return controlFlow([], -2, []);

//firstStatement is -3: means it is a break
case \continue(): return controlFlow([], -3, []);
case \continue(_): return controlFlow([], -3, []);

case \return(): return returnCF(stat);
case \return(_): return returnCF(stat);

default: {
statements += (counting: stat);
firstStatement = counting;
lastStatements = [counting];

calDefGenUse(stat, counting);

counting += 1;
return controlFlow([], firstStatement, lastStatements);
}
}
// Analyse each statement
private CF statementCF(stat:\block(_)) = blockCF(stat.statements);
private CF statementCF(stat:\if(_, _)) = ifCF(stat);
private CF statementCF(stat:\if(_, _, _)) = ifCF(stat);
private CF statementCF(stat:\for(_, _, _)) = forCF(stat);
private CF statementCF(stat:\for(_, _, _, _)) = forCF(stat);
private CF statementCF(stat:\while(_, _)) = whileCF(stat);
private CF statementCF(stat:\switch(_, _)) = switchCF(stat);

//firstStatement is -2: means it is a break
private CF statementCF(\break()) = controlFlow([], -2, []);
private CF statementCF(\break(_)) = controlFlow([], -2, []);

//firstStatement is -3: means it is a break
private CF statementCF(\continue()) = controlFlow([], -3, []);
private CF statementCF(\continue(_)) = controlFlow([], -3, []);

private CF statementCF(stat:\return()) = returnCF(stat);
private CF statementCF(stat:\return(_)) = returnCF(stat);

private default CF statementCF(Statement stat)
{
statements += (counting: stat);
firstStatement = counting;
lastStatements = [counting];

calDefGenUse(stat, counting);

counting += 1;
return controlFlow([], firstStatement, lastStatements);
}


Expand Down Expand Up @@ -360,22 +357,18 @@ private void calDefGenUse(Statement stat, int counting){
uses = dgu.uses;
}

private bool isCase(Statement stat){
if(Statement::\case(_) := stat || Statement::\defaultCase() := stat) return true;
else return false;
}
private bool isCase(\case(_)) = true;
private bool isCase(\defaultCase()) = true;
private default bool isCase(Statement stat) = false;

private bool isBreak(Statement stat){
if(Statement::\break(_) := stat || Statement::\break() := stat) return true;
else return false;
}
private bool isBreak(\break(_)) = true;
private bool isBreak(\break()) = true;
private default bool isBreak(Statement stat) = false;

private bool isContinue(Statement stat){
if(Statement::\continue(_) := stat || Statement::\continue() := stat) return true;
else return false;
}
private bool isContinue(\continue(_)) = true;
private bool isContinue(\continue()) = true;
private default bool isContinue(Statement stat) = false;

private bool isReturn(Statement stat){
if(Statement::\return(_) := stat || Statement::\return() := stat) return true;
else return false;
}
private bool isReturn(\return(_)) = true;
private bool isReturn(\return()) = true;
private default bool isReturn(Statement stat) = false;

0 comments on commit b004933

Please sign in to comment.