-
Notifications
You must be signed in to change notification settings - Fork 82
Added visualization of calculator/requirement dependencies and added dependencies #2762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PaulKlint
wants to merge
11
commits into
main
Choose a base branch
from
fix/visualize-and-add-missing-dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
72df8b4
Added visualization of calculator/requirement dependencies and added …
PaulKlint 263f25c
Fixed error in addReturnTypeDependency; added dependencies
PaulKlint 727f880
Added dependencies
PaulKlint 8d82e83
Added dependencies
PaulKlint 0fecd2d
Commented out viewDependencies
PaulKlint b2c5afd
Commented out viewDependencies
PaulKlint 96b2ac0
Tests
PaulKlint bf59178
Removed dependencies
PaulKlint 05703d5
Fixed type error
PaulKlint 7908765
Added missing import
PaulKlint 2c6ca40
Fixed test to the breaking case
DavyLandman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
208 changes: 208 additions & 0 deletions
208
src/org/rascalmpl/compiler/lang/rascalcore/check/DependencyViewer.rsc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| module lang::rascalcore::check::DependencyViewer | ||
|
|
||
| import analysis::typepal::TModel; | ||
| import analysis::typepal::Collector; | ||
| import vis::Graphs; | ||
| import IO; | ||
| import util::IDEServices; | ||
| import ListRelation; | ||
| import Map; | ||
| import Relation; | ||
| import Set; | ||
|
|
||
| // Management of node identities | ||
| alias NodeId = str; | ||
| int nodeCounter = 0; | ||
|
|
||
| map[NodeId, value] id2node = (); | ||
| map[value, NodeId] node2id = (); | ||
|
|
||
| map[NodeId,loc] node2src = (); | ||
| map[NodeId,str] node2label = (); | ||
| map[loc,NodeId] src2calc = (); | ||
|
|
||
| void initNodes(){ | ||
| nodeCounter = 0; | ||
| id2node = (); | ||
| node2id = (); | ||
| node2src = (); | ||
| node2label = (); | ||
| src2calc = (); | ||
| } | ||
|
|
||
| NodeId getNodeId(value v){ | ||
| assert Calculator _ := v || Requirement _ := v || loc _ := v: "Illegal <v>"; | ||
| if(v notin node2id) { | ||
| node2id[v] = "<nodeCounter>"; | ||
| id2node["<nodeCounter>"] = v; | ||
| nodeCounter += 1; | ||
| } | ||
| return node2id[v]; | ||
| } | ||
|
|
||
| NodeId getNodeIdViaCalculator(loc l){ | ||
| if(l in src2calc){ | ||
| return src2calc[l]; | ||
| } | ||
| return getNodeId(l); | ||
| } | ||
|
|
||
| loc getNodeSource(NodeId id) { | ||
| if(id in node2src) return node2src[id]; | ||
| v = id2node[id]; | ||
| if(loc l := v) return l; | ||
| return |unknown:///|; | ||
| } | ||
|
|
||
| str getNodeLabel(NodeId id) { | ||
| if(id in node2label) return node2label[id]; | ||
| v = id2node[id]; | ||
| if(loc l := v) return "<id>: <getText(l)>"; | ||
| return "<id>: ???:<v>"; | ||
| } | ||
|
|
||
| str getText(loc l) { | ||
| try return readFile(l); | ||
| catch _: return "???<l>"; | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] srcDependsOn(NodeId src, list[loc] dependsOn) | ||
| = [<src, getNodeIdViaCalculator(d)> | d <- dependsOn]; | ||
|
|
||
| lrel[NodeId,NodeId] srcDependsOn(NodeId l, NodeId r, list[loc] dependsOn) | ||
| = srcDependsOn(l, dependsOn) + srcDependsOn(r, dependsOn); | ||
|
|
||
| lrel[NodeId,NodeId] calcEdges(c:calcType(loc src, AType atype)) { | ||
| id = getNodeId(c); | ||
| node2src[id] = src; | ||
| node2label[id] = "<id>: <getText(src)>"; | ||
| src2calc[src] = id; | ||
| return [<id, getNodeId(|nothing:///|)>]; | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] calcEdges(c:calcLoc(loc src, list[loc] dependsOn)){ | ||
| NodeId id = getNodeId(c); | ||
| node2src[id] = src; | ||
| node2label[id] = "<id>: <getText(src)>"; | ||
| src2calc[src] = id; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] calcEdges(c:calc(str cname, loc src, list[loc] dependsOn, AType(Solver s) getAType)){ | ||
| NodeId id = getNodeId(c); | ||
| node2src[id] = src; | ||
| node2label[id] = "C <id>, <cname>: <getText(src)>"; | ||
| src2calc[src] = id; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] calcEdges(c:calcLub(str cname, list[loc] srcs, list[loc] dependsOn, list[AType(Solver s)] getATypes)){ | ||
| NodeId id = getNodeId(c); | ||
| node2label[id] = "C <id>, <cname>: <for(src<-srcs){><getText(src)>/<}>"; | ||
| for(src <- srcs) src2calc[src] = id; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:req(str rname, loc src, list[loc] dependsOn, void(Solver s) preds)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2src[id] = src; | ||
| node2label[id] = "R <rname>: <getText(src)>"; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqEqual(str rname, value l, value r, list[loc] dependsOn, FailMessage fm)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2label[id] = "R <rname>"; | ||
| return srcDependsOn(getNodeId(l), getNodeId(r), dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqComparable(str rname, value l, value r, list[loc] dependsOn, FailMessage fm)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2label[id] = "R <rname>"; | ||
| return srcDependsOn(getNodeId(l), getNodeId(r), dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqSubtype(str rname, value l, value r, list[loc] dependsOn, FailMessage fm)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2label[id] = "R <rname>"; | ||
| return srcDependsOn(getNodeId(l), getNodeId(r), dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqUnify(str rname, value l, value r, list[loc] dependsOn, FailMessage fm)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2label[id] = "R <rname>"; | ||
| return srcDependsOn(getNodeId(l), getNodeId(r), dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqError (loc src, list[loc] dependsOn, FailMessage fm)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2src[id] = src; | ||
| node2label[id] = "R error: <getText(src)>"; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| lrel[NodeId,NodeId] reqEdges(rq:reqErrors(loc src, list[loc] dependsOn, list[FailMessage] fms)){ | ||
| NodeId id = getNodeId(rq); | ||
| node2src[id] = src; | ||
| node2label[id] = "R errors: <getText(src)>"; | ||
| return srcDependsOn(id, dependsOn); | ||
| } | ||
|
|
||
| NodeId replaceByCalc(NodeId id){ | ||
| if(id in node2src){ | ||
| src = node2src[id]; | ||
| if(src in src2calc) return src2calc[src]; | ||
| } | ||
| return id; | ||
| } | ||
|
|
||
| void viewDependencies(TModel tm){ | ||
| initNodes(); | ||
| for(Calculator c <- tm.calculators){ | ||
| NodeId id = getNodeId(c); | ||
| if(c has src){ | ||
| src2calc[c.src] = id; | ||
| } else if(c has srsc){ | ||
| for(src <- c.srcs){ | ||
| src2calc[src] = id; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| cedges = {*calcEdges(c) | Calculator c <- tm.calculators}; | ||
| redges = {*reqEdges(r) | Requirement r <- tm.requirements}; | ||
| edges = toList(cedges + redges); | ||
| println("edges: <edges>"); | ||
| for(NodeId id <- sort(domain(id2node))) { println("<id>"); iprintln(id2node[id]); } | ||
|
|
||
| list[str] nodeClassifier(NodeId id){ | ||
| res = []; | ||
| switch(id2node[id]){ | ||
| case Calculator _: res = ["calc"]; | ||
| case Requirement _: res = ["req"]; | ||
| case loc _: res = ["text"]; | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| styles = [ | ||
| cytoStyleOf( | ||
| selector=\node(className("text")), | ||
| style=defaultNodeStyle()[shape=CytoNodeShape::rectangle()][\background-color="grey"]), | ||
| cytoStyleOf( | ||
| selector=\node(className("calc")), | ||
| style=defaultNodeStyle()[shape=CytoNodeShape::ellipse()][\background-color="green"]), | ||
| cytoStyleOf( | ||
| selector=\node(className("req")), | ||
| style=defaultNodeStyle()[shape=CytoNodeShape::diamond()][\background-color="blue"]) | ||
| ]; | ||
| cfg = cytoGraphConfig( | ||
| title="Graph: <tm.modelName>", | ||
| nodeClassifier=nodeClassifier, | ||
| nodeLinker=getNodeSource, | ||
| nodeLabeler=getNodeLabel, | ||
| styles=styles, | ||
| \layout=defaultDagreLayout()[ranker=\tight-tree()]); | ||
|
|
||
| showInteractiveContent(graph(edges, cfg=cfg)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.