Skip to content

Commit 8e0a01f

Browse files
committed
modified call trace
1 parent 900aa06 commit 8e0a01f

File tree

4 files changed

+80
-13
lines changed

4 files changed

+80
-13
lines changed

cwaf-ontology/src/main/java/be/uclouvain/model/Directive.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Directive implements Comparable<Directive>, Serializable {
4545
private String disabledBy;
4646
private String type;
4747
private String fileURI;
48+
private String entityURI;
4849

4950
public Directive(CompileContext ctx, Individual resource) {
5051

@@ -94,10 +95,11 @@ public Directive(CompileContext ctx, Individual resource) {
9495
}
9596
});
9697

97-
this.trace = ctx.getTraceURIs();
98+
this.trace = ctx.getCallTrace();
9899

99100
this.resource = resource;
100101
this.resourceURI = resource.getURI();
102+
this.entityURI = getURIForName(name);
101103
}
102104

103105
public static void removeById(int id, String disabledBy) {
@@ -120,6 +122,10 @@ public static void removeByTag(String tag, String disabledBy) {
120122
});
121123
}
122124

125+
public String getEntityURI() {
126+
return entityURI;
127+
}
128+
123129
public boolean isBeacon() {
124130
return resource.hasOntClass(OntCWAF.BEACON);
125131
}
@@ -160,6 +166,10 @@ public String getType() {
160166
return type;
161167
}
162168

169+
public String getFileURI() {
170+
return fileURI;
171+
}
172+
163173
@Override
164174
public boolean equals(Object obj) {
165175
if (this == obj) return true;
@@ -249,7 +259,7 @@ public void updateContext(CompileContext ctx) {
249259
}
250260

251261
public Individual toEntityIndividual(OntModel model) {
252-
Individual ind = model.createIndividual(getURIForName(name), resource.getOntClass());
262+
Individual ind = model.createIndividual(entityURI, resource.getOntClass());
253263
ind.addLiteral(OntCWAF.DIR_LINE_NUM, lineNum);
254264
ind.addLiteral(OntCWAF.PHASE, phase);
255265
if (id != null) {

cwaf-ontology/src/main/java/be/uclouvain/service/Compiler.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ private static Stream<Directive> getOrderedDirectives(CompileContext ctx, Indivi
100100
}
101101

102102
public static Stream<Directive> compileContainer(CompileContext ctx, Individual container) {
103-
ctx.push(container);
103+
ctx.stackTracePush(container);
104104
Stream<Directive> directives = getOrderedDirectives(ctx, container);
105105
CompileContext ctx_copy = new CompileContext(ctx);
106106
Stream<Directive> res = directives.flatMap( dir -> compileDirective(ctx_copy, dir));
107-
ctx.pop();
107+
ctx.stackTracePop();
108108
return res;
109109
}
110110

@@ -124,7 +124,10 @@ public static Stream<Directive> compileFile(CompileContext ctx, Individual file,
124124

125125
private static Stream<Directive> expandInclude(CompileContext ctx, Directive include) {
126126
Individual file = include.getIndividual().getProperty(OntCWAF.INCLUDE_FILE).getObject().as(Individual.class);
127-
return compileFile(ctx, file);//, include.getScope()
127+
ctx.callTracePush(include, file);
128+
Stream<Directive> res = compileFile(ctx, file);
129+
ctx.callTracePop();
130+
return res;//, include.getScope()
128131
}
129132

130133
private static Stream<Directive> expandUse(CompileContext ctx, Directive use) {
@@ -145,7 +148,11 @@ private static Stream<Directive> expandUse(CompileContext ctx, Directive use) {
145148
// }
146149
String[] args = use.getArgs();
147150
// System.err.println("Using macro: " + macro.getLocalName() + " with args " + Arrays.toString(args));
148-
return compileMacroContent(ctx, macro, args); //, use.getScope()
151+
152+
ctx.callTracePush(use, macro);
153+
Stream<Directive> res = compileMacroContent(ctx, macro, args);
154+
ctx.callTracePop();
155+
return res; //, use.getScope()
149156
}
150157

151158
private static Stream<Directive> compileMacroContent(CompileContext ctx, Individual macro, String[] args) { //, String[] use_scope
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package be.uclouvain.service.context;
2+
3+
import org.apache.jena.ontology.Individual;
4+
5+
import be.uclouvain.model.Directive;
6+
import be.uclouvain.vocabulary.OntCWAF;
7+
8+
public class CallTraceElem {
9+
10+
String callingURI;
11+
String calledURI;
12+
String fileURI;
13+
int lineNum;
14+
15+
public CallTraceElem(Directive directive, Individual called) {
16+
this.callingURI = directive.getIndividual().getURI();
17+
this.calledURI = called.getURI();
18+
this.fileURI = directive.getFileURI();
19+
this.lineNum = directive.getLineNum();
20+
}
21+
22+
public CallTraceElem(String callingURI, String calledURI, String fileURI, int lineNum) {
23+
this.callingURI = callingURI;
24+
this.calledURI = calledURI;
25+
this.fileURI = fileURI;
26+
this.lineNum = lineNum;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
String file = fileURI.replace(OntCWAF.NS, "");
32+
return calledURI + " from " + callingURI + "(" + file + ":" + lineNum + ")";
33+
}
34+
}

cwaf-ontology/src/main/java/be/uclouvain/service/context/CompileContext.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.jena.rdf.model.ModelFactory;
1010

1111
import be.uclouvain.model.Condition;
12+
import be.uclouvain.model.Directive;
1213
import be.uclouvain.model.LocalVar;
1314
import be.uclouvain.model.Scope;
1415

@@ -18,6 +19,7 @@ public class CompileContext{
1819
private OntModel schema;
1920
private OntModel infModel;
2021
private Stack<Individual> trace = new Stack<>();
22+
private Stack<CallTraceElem> callTrace = new Stack<>();
2123
private List<LocalVar> localVars = new ArrayList<>();
2224
private Stack<Condition> existance_conditions = new Stack<>();
2325
private Scope scope = new Scope();
@@ -45,6 +47,7 @@ public CompileContext(CompileContext other){
4547
definedMacros.addAll(other.definedMacros);
4648

4749
trace.addAll(other.trace);
50+
callTrace.addAll(other.callTrace);
4851
localVars.addAll(other.localVars);
4952
existance_conditions.addAll(other.existance_conditions);
5053
}
@@ -72,14 +75,27 @@ public void setSchema(OntModel schema) {
7275
this.infModel.add(schema);
7376
}
7477

75-
public void push(Individual directive) {
78+
public void stackTracePush(Individual directive) {
7679
trace.push(directive);
7780
}
7881

79-
public Individual pop() {
82+
public Individual stackTracePop() {
8083
return trace.pop();
8184
}
8285

86+
public void callTracePush(Directive directive, Individual called) {
87+
CallTraceElem elem = new CallTraceElem(directive, called);
88+
callTrace.push(elem);
89+
}
90+
91+
public void callTracePush(CallTraceElem elem) {
92+
callTrace.push(elem);
93+
}
94+
95+
public CallTraceElem callTracePop() {
96+
return callTrace.pop();
97+
}
98+
8399
public void addVar(String name, String value){
84100
if (localVars.stream().anyMatch(v -> v.name.equals(name))){
85101
localVars.removeIf(v -> v.name.equals(name));
@@ -172,12 +188,12 @@ public Stack<Individual> getTrace() {
172188
return trace;
173189
}
174190

175-
public Stack<String> getTraceURIs() {
176-
Stack<String> uris = new Stack<>();
177-
for (Individual ind : trace) {
178-
uris.push(ind.getURI());
191+
public Stack<String> getCallTrace() {
192+
Stack<String> trace = new Stack<>();
193+
for (CallTraceElem elem : callTrace) {
194+
trace.push(elem.toString());
179195
}
180-
return uris;
196+
return trace;
181197
}
182198

183199
public String getCurrentVirtualHost() {

0 commit comments

Comments
 (0)