Skip to content

Commit

Permalink
more hacking on the Rascal contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Aug 21, 2012
1 parent daf5c5f commit e03cc7c
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 48 deletions.
7 changes: 7 additions & 0 deletions hackathon/callref-rascal/.classpath
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
52 changes: 52 additions & 0 deletions hackathon/callref-rascal/.project
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>callref-rascal</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>rascal_eclipse.rascal_builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>rascal_eclipse.term_builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>rascal_eclipse.rascal_nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>rascal_eclipse.term_nature</nature>
</natures>
<linkedResources>
<link>
<name>eclipse</name>
<type>2</type>
<locationURI>rascal-library://eclipse</locationURI>
</link>
<link>
<name>std</name>
<type>2</type>
<locationURI>rascal-library://rascal</locationURI>
</link>
</linkedResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/CallRef.rsc=UTF-8
4 changes: 2 additions & 2 deletions hackathon/callref-rascal/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Project1
Bundle-SymbolicName: Project1
Bundle-Name: callref-rascal
Bundle-SymbolicName: callref_rascal
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.imp.pdb.values,
rascal
Expand Down
100 changes: 54 additions & 46 deletions hackathon/callref-rascal/src/CallRef.rsc
@@ -1,17 +1,28 @@
@contributor{Anastasia Izmaylova - SWAT, CWI}
@contributor{Jan Kurš}
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module CallRef

import lang::java::jdt::Java;
import lang::java::jdt::JavaADT;
import lang::java::jdt::JDT;

import Set;
import IO;

import PP;

public list[loc] projects = [|project://javaInheritance/|];

public rel[str, str, int, bool, bool] function1(list[loc] projects)
= { *function2(project) | loc project <- projects };
public void main()
{
iprintln(processProjects(projects));
}

public rel[str, str, int, bool, bool] processProjects (list[loc] projects)
= { *processProjectForCallRefs(project) | loc project <- projects };

public list[str] function1(loc project) {
public list[str] processProjectForNames(loc project) {
list[str] names = [];

visit(createAstsFromProject(project)) {
Expand All @@ -24,59 +35,56 @@ public list[str] function1(loc project) {

}

public rel[str, str, int, bool, bool] function2(loc project) {
public rel[str, str, int, bool, bool] processProjectForCallRefs(loc project) {
rel[str, str, int, bool, bool] nameRel = {};
visit(createAstsFromProject(project)) {
case m:methodDeclaration(list[Modifier] modifiers, list[AstNode] genericTypes, Option[AstNode] returnType, str name, list[AstNode] parameters, list[AstNode] possibleExceptions, some(AstNode implementation)):
nameRel += { <"<m@bindings["methodBinding"]>", n, c, lower, upper> | <str n, int c, bool lower, bool upper> <- function3(implementation) };
nameRel += { <toStr(m@bindings["methodBinding"]), n, c, lower, upper> | <str n, int c, bool lower, bool upper> <- processNode(implementation, {}, false, false) };
}
return nameRel;
}

//public rel[str, int, bool, bool] function3(AstNode method) {
// rel[str, int, bool, bool] names = {};
// visit(method) {
// case forStatement(list[AstNode] initializers, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body):
// {
// rel[str, int, bool, bool] r = function4(body,1,10);
// names += {<["<m@bindings["methodBinding"]>"], function4(body,1,10)[0], function4(body,1,10)[0], function4(body,1,10)[0]>};
// }
// case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement):
// names["<m@bindings["methodBinding"]>"] = function4(thenStatement,0,1);
// // for -> function4( _ , 1, 10);
// // while -> function4( _ , 0, 10);
// // if -> function4( _ , 0, 1);
// }
// return names;
//}

public rel[str, int, bool, bool] function3(AstNode method) {
rel[str, int, bool, bool] names = {};
bool lower = false;
bool upper = false;
top-down visit (method)
{
case forStatement(list[AstNode] initializers, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body):
upper = true;
case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement):
lower = true;
case switchStatement(AstNode expression, list[AstNode] statements):
lower = true;
case doStatement(AstNode body, AstNode whileExpression):
upper = true;
case whileStatement(AstNode expression, AstNode body):
upper = true;
case m:methodInvocation(Option[AstNode] optionalExpression, list[AstNode] genericTypes, str name, list[AstNode] typedArguments):
{
n = "<m@bindings["methodBinding"]>";
if(isEmpty(names[n])) names += <n, 1, lower, upper>;
else
{
public rel[str, int, bool, bool] processNode(AstNode body, rel[str, int, bool, bool] names, bool lower, bool upper) {
top-down-break visit (body) {
case forStatement(_, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body): {
upper = true;
names += (some(AstNode e) := optionalBooleanExpression) ? processNode(e, names, lower, upper) : {};
for(updater <- updaters) names += processNode(updater, names, lower, upper);
names += processNode(body, names, lower, upper);
}
case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement): {
names += processNode(booleanExpression, names, lower, upper);
lower = true;
names += processNode(thenStatement, names, lower, upper);
names += (some(AstNode e) := elseStatement) ? processNode(e, names, lower, upper) : {};
}
case switchStatement(AstNode expression, list[AstNode] statements): {
names += processNode(expression, names, lower, upper);
lower = true;
for(statement <- statements) names += processNode(statement, names, lower, upper);
}
case doStatement(AstNode body, AstNode whileExpression): {
upper = true;
names += processNode(body, names, lower, upper);
names += processNode(whileExpression, names, lower, upper);
}
case whileStatement(AstNode expression, AstNode body): {
upper = true;
names += processNode(expression, names, lower, upper);
names += processNode(body, names, lower, upper);
}
case m:methodInvocation(Option[AstNode] optionalExpression, list[AstNode] genericTypes, str name, list[AstNode] typedArguments): {
n = toStr(m@bindings["methodBinding"]);
if(isEmpty(names[n])) names += <n, ( !lower && !upper ) ? 1 : 0, lower, upper>;
else {
tuple[int,bool,bool] c = getOneFrom(names[n]);
names = names - {<n,c[0],c[1],c[2]>} + {<n,c[0],c[1]||lower,c[2]||upper>};
}
names = names - { <n, c[0], c[1], c[2]> }
+ { <n, ( !(c[1]||lower) &&!(c[2]||upper) ) ? c[0] + 1 : c[0], c[1]||lower, c[2]||upper>};
}
names += (some(AstNode e) := optionalExpression) ? processNode(e, names, lower, upper) : {};
for(arg <- typedArguments) names += processNode(arg, names, lower, upper);
}
}
return names;
}

43 changes: 43 additions & 0 deletions hackathon/callref-rascal/src/PP.rsc
@@ -0,0 +1,43 @@
@contributor{Anastasia Izmaylova - SWAT, CWI}
module PP

import lang::java::jdt::Java;

import List;

public str toStr(entity(list[Id] ids)) = "<if(!isEmpty(ids)){><for(int i <- [0..size(ids)-1]){><if(i != size(ids)-1){><if(toStr(ids[i]) != "") {><toStr(ids[i])>.<}><}else{><toStr(ids[i])><}><}><}else{>_<}>";
public str toStr(package(str name)) = name;
public str toStr(class(str name)) = name;
public str toStr(class(str name, list[Entity] params)) = "<name>\<<for(int i <- [0..size(params)-1]){><if(i != size(params)-1){><toStr(params[i])>,<}else{><toStr(params[i])><}><}>\>";
public str toStr(interface(str name)) = name;
public str toStr(interface(str name, list[Entity] params)) = "<name>\<<for(int i <- [0..size(params)-1]){><if(i != size(params)-1){><toStr(params[i])>,<}else{><toStr(params[i])><}><}>\>";
public str toStr(enum(str name)) = name;
public str toStr(method(str name, list[Entity] params, Entity returnType)) = "<toStr(returnType)> <name>(<if(size(params) != 0){><for(int i <- [0..size(params)-1]){><if(i != size(params)-1){><toStr(params[i])>,<}else{><toStr(params[i])><}><}><}else{><}>)";
public str toStr(constr(list[Entity] params)) = "(<if(size(params) != 0){><for(int i <- [0..size(params)-1]){><if(i != size(params)-1){><toStr(params[i])>,<}else{><toStr(params[i])><}><}><}else{><}>)";
public str toStr(primitive(PrimitiveType primType)) = "<toStr(primType)>";
public str toStr(array(Entity elementType)) = "<toStr(elementType)>[]";
public str toStr(wildcard()) = "!";
public str toStr(wildcard(super(Entity b))) = "! super <toStr(b)>";
public str toStr(wildcard(extends(Entity b))) = "! extends <toStr(b)>";
public str toStr(captureof(Entity wildCard)) = "captureof <toStr(wildCard)>";

public default str toStr(Id id) {
switch(id) {
case initializer(): return "initializer";
case initializer(int nr): return "initializer(<nr>)";
case typeParameter(str name): return "<name> (type parameter)";
}
throw "ups, unknown id <id>";
}


public str toStr(byte()) = "byte";
public str toStr(short()) = "short";
public str toStr(\int()) = "int";
public str toStr(long()) = "long";
public str toStr(float()) = "float";
public str toStr(double()) = "double";
public str toStr(char()) = "char";
public str toStr(boolean()) = "boolean";
public str toStr(\void()) = "void";
public str toStr(null()) = "null";
4 changes: 4 additions & 0 deletions hackathon/callref-rascal/src/Visualise.rsc
@@ -0,0 +1,4 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module Visualise

// will produce dot files

0 comments on commit e03cc7c

Please sign in to comment.