From e03cc7c134eb83043f1d342d8bb5f755e61d631a Mon Sep 17 00:00:00 2001 From: grammarware Date: Tue, 21 Aug 2012 12:28:41 +0200 Subject: [PATCH] more hacking on the Rascal contribution --- hackathon/callref-rascal/.classpath | 7 ++ hackathon/callref-rascal/.project | 52 +++++++++ .../org.eclipse.core.resources.prefs | 2 + hackathon/callref-rascal/META-INF/MANIFEST.MF | 4 +- hackathon/callref-rascal/src/CallRef.rsc | 100 ++++++++++-------- hackathon/callref-rascal/src/PP.rsc | 43 ++++++++ hackathon/callref-rascal/src/Visualise.rsc | 4 + 7 files changed, 164 insertions(+), 48 deletions(-) create mode 100644 hackathon/callref-rascal/.classpath create mode 100644 hackathon/callref-rascal/.project create mode 100644 hackathon/callref-rascal/.settings/org.eclipse.core.resources.prefs create mode 100644 hackathon/callref-rascal/src/PP.rsc create mode 100644 hackathon/callref-rascal/src/Visualise.rsc diff --git a/hackathon/callref-rascal/.classpath b/hackathon/callref-rascal/.classpath new file mode 100644 index 0000000..1fa3e68 --- /dev/null +++ b/hackathon/callref-rascal/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/hackathon/callref-rascal/.project b/hackathon/callref-rascal/.project new file mode 100644 index 0000000..1b3418e --- /dev/null +++ b/hackathon/callref-rascal/.project @@ -0,0 +1,52 @@ + + + callref-rascal + + + + + + org.eclipse.jdt.core.javabuilder + + + + + rascal_eclipse.rascal_builder + + + + + rascal_eclipse.term_builder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + rascal_eclipse.rascal_nature + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + rascal_eclipse.term_nature + + + + eclipse + 2 + rascal-library://eclipse + + + std + 2 + rascal-library://rascal + + + diff --git a/hackathon/callref-rascal/.settings/org.eclipse.core.resources.prefs b/hackathon/callref-rascal/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..a9edec4 --- /dev/null +++ b/hackathon/callref-rascal/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/CallRef.rsc=UTF-8 diff --git a/hackathon/callref-rascal/META-INF/MANIFEST.MF b/hackathon/callref-rascal/META-INF/MANIFEST.MF index 8ffad25..65a74ae 100644 --- a/hackathon/callref-rascal/META-INF/MANIFEST.MF +++ b/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 diff --git a/hackathon/callref-rascal/src/CallRef.rsc b/hackathon/callref-rascal/src/CallRef.rsc index bc2ea52..7cf37b6 100644 --- a/hackathon/callref-rascal/src/CallRef.rsc +++ b/hackathon/callref-rascal/src/CallRef.rsc @@ -1,3 +1,6 @@ +@contributor{Anastasia Izmaylova - SWAT, CWI} +@contributor{Jan Kurš} +@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} module CallRef import lang::java::jdt::Java; @@ -5,13 +8,21 @@ 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)) { @@ -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 += { <"", n, c, lower, upper> | <- function3(implementation) }; + nameRel += { | <- 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 += {<[""], 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[""] = 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 = ""; - if(isEmpty(names[n])) names += ; - 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 += ; + else { tuple[int,bool,bool] c = getOneFrom(names[n]); - names = names - {} + {}; - } + names = names - { } + + { }; + } + names += (some(AstNode e) := optionalExpression) ? processNode(e, names, lower, upper) : {}; + for(arg <- typedArguments) names += processNode(arg, names, lower, upper); } } return names; } - diff --git a/hackathon/callref-rascal/src/PP.rsc b/hackathon/callref-rascal/src/PP.rsc new file mode 100644 index 0000000..8126290 --- /dev/null +++ b/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)) = ".<}><}else{><}><}><}else{>_<}>"; +public str toStr(package(str name)) = name; +public str toStr(class(str name)) = name; +public str toStr(class(str name, list[Entity] params)) = "\<,<}else{><}><}>\>"; +public str toStr(interface(str name)) = name; +public str toStr(interface(str name, list[Entity] params)) = "\<,<}else{><}><}>\>"; +public str toStr(enum(str name)) = name; +public str toStr(method(str name, list[Entity] params, Entity returnType)) = " (,<}else{><}><}><}else{><}>)"; +public str toStr(constr(list[Entity] params)) = "(,<}else{><}><}><}else{><}>)"; +public str toStr(primitive(PrimitiveType primType)) = ""; +public str toStr(array(Entity elementType)) = "[]"; +public str toStr(wildcard()) = "!"; +public str toStr(wildcard(super(Entity b))) = "! super "; +public str toStr(wildcard(extends(Entity b))) = "! extends "; +public str toStr(captureof(Entity wildCard)) = "captureof "; + +public default str toStr(Id id) { + switch(id) { + case initializer(): return "initializer"; + case initializer(int nr): return "initializer()"; + case typeParameter(str name): return " (type parameter)"; + } + throw "ups, unknown 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"; \ No newline at end of file diff --git a/hackathon/callref-rascal/src/Visualise.rsc b/hackathon/callref-rascal/src/Visualise.rsc new file mode 100644 index 0000000..2471e78 --- /dev/null +++ b/hackathon/callref-rascal/src/Visualise.rsc @@ -0,0 +1,4 @@ +@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} +module Visualise + +// will produce dot files \ No newline at end of file