@@ -26,8 +26,71 @@ module RAParser<RApredicate Predicate> {
2626 result = str .trim ( ) .regexpCapture ( "return r([0-9]+)" , 1 ) .toInt ( )
2727 }
2828
29+ bindingset [ str]
30+ private predicate parseScan ( string str , int arity , int lhs , string rhs ) {
31+ exists ( string r , string trimmed |
32+ r = "\\{(\\d+)\\}\\s+r(\\d+)\\s+=\\s+SCAN\\s+([0-9a-zA-Z:#_]+)\\s.*" and
33+ trimmed = str .trim ( )
34+ |
35+ arity = trimmed .regexpCapture ( r , 1 ) .toInt ( ) and
36+ lhs = trimmed .regexpCapture ( r , 2 ) .toInt ( ) and
37+ rhs = trimmed .regexpCapture ( r , 3 )
38+ )
39+ }
40+
41+ bindingset [ str]
42+ private predicate parseJoin ( string str , int arity , int lhs , string left , string right ) {
43+ exists ( string r , string trimmed |
44+ r =
45+ "\\{(\\d+)\\}\\s+r(\\d+)\\s+=\\s+JOIN\\s+([0-9a-zA-Z:#_]+)\\s+WITH\\s+([0-9a-zA-Z:#_]+)\\s.*" and
46+ trimmed = str .trim ( )
47+ |
48+ arity = trimmed .regexpCapture ( r , 1 ) .toInt ( ) and
49+ lhs = trimmed .regexpCapture ( r , 2 ) .toInt ( ) and
50+ left = trimmed .regexpCapture ( r , 3 ) and
51+ right = trimmed .regexpCapture ( r , 4 )
52+ )
53+ }
54+
55+ bindingset [ str]
56+ private predicate parseSelect ( string str , int arity , int lhs , string rhs ) {
57+ exists ( string r , string trimmed |
58+ r = "\\{(\\d+)\\}\\s+r(\\d+)\\s+=\\s+SELECT\\s+([0-9a-zA-Z:#_]+).*" and
59+ trimmed = str .trim ( )
60+ |
61+ arity = trimmed .regexpCapture ( r , 1 ) .toInt ( ) and
62+ lhs = trimmed .regexpCapture ( r , 2 ) .toInt ( ) and
63+ rhs = trimmed .regexpCapture ( r , 3 )
64+ )
65+ }
66+
67+ bindingset [ str]
68+ private predicate parseAntiJoin ( string str , int arity , int lhs , string left , string right ) {
69+ exists ( string r , string trimmed |
70+ r = "\\{(\\d+)\\}\\s+r(\\d+)\\s+=\\s+([0-9a-zA-Z:#_]+)\\s+AND\\s+NOT\\s+([0-9a-zA-Z:#_]+).*" and
71+ trimmed = str .trim ( )
72+ |
73+ arity = trimmed .regexpCapture ( r , 1 ) .toInt ( ) and
74+ lhs = trimmed .regexpCapture ( r , 2 ) .toInt ( ) and
75+ left = trimmed .regexpCapture ( r , 3 ) and
76+ right = trimmed .regexpCapture ( r , 4 )
77+ )
78+ }
79+
2980 private newtype TRA =
3081 TReturn ( Predicate p , int line , int v ) { v = parseReturn ( p .getLineOfRA ( line ) ) } or
82+ TScan ( Predicate p , int line , int arity , int lhs , string rhs ) {
83+ parseScan ( p .getLineOfRA ( line ) , arity , lhs , rhs )
84+ } or
85+ TJoin ( Predicate p , int line , int arity , int lhs , string left , string right ) {
86+ parseJoin ( p .getLineOfRA ( line ) , arity , lhs , left , right )
87+ } or
88+ TSelect ( Predicate p , int line , int arity , int lhs , string rhs ) {
89+ parseSelect ( p .getLineOfRA ( line ) , arity , lhs , rhs )
90+ } or
91+ TAntiJoin ( Predicate p , int line , int arity , int lhs , string left , string right ) {
92+ parseAntiJoin ( p .getLineOfRA ( line ) , arity , lhs , left , right )
93+ } or
3194 TUnknown ( Predicate p , int line , int lhs , int arity , string rhs ) {
3295 rhs = parseRaExpr ( p , line , arity , lhs )
3396 }
@@ -90,12 +153,12 @@ module RAParser<RApredicate Predicate> {
90153 }
91154
92155 class RAReturnExpr extends RAExpr , TReturn {
93- RAReturnExpr ( ) { this = TReturn ( p , line , res ) }
94-
95156 Predicate p ;
96157 int line ;
97158 int res ;
98159
160+ RAReturnExpr ( ) { this = TReturn ( p , line , res ) }
161+
99162 override Predicate getPredicate ( ) { result = p }
100163
101164 override int getLine ( ) { result = line }
@@ -108,4 +171,115 @@ module RAParser<RApredicate Predicate> {
108171
109172 override string getARhsPredicate ( ) { none ( ) }
110173 }
174+
175+ class RAScanExpr extends RAExpr , TScan {
176+ Predicate p ;
177+ int line ;
178+ int arity ;
179+ int lhs ;
180+ string rhs ;
181+
182+ RAScanExpr ( ) { this = TScan ( p , line , arity , lhs , rhs ) }
183+
184+ override Predicate getPredicate ( ) { result = p }
185+
186+ override int getLine ( ) { result = line }
187+
188+ override int getLhs ( ) { result = lhs }
189+
190+ override int getArity ( ) { result = arity }
191+
192+ override int getARhsVariable ( ) { isVariable ( rhs , result ) }
193+
194+ override string getARhsPredicate ( ) {
195+ result = rhs and
196+ not isVariable ( result , _)
197+ }
198+ }
199+
200+ bindingset [ s]
201+ private predicate isVariable ( string s , int n ) { n = s .regexpCapture ( "r(\\d+)" , 1 ) .toInt ( ) }
202+
203+ class RAJoinExpr extends RAExpr , TJoin {
204+ Predicate p ;
205+ int line ;
206+ int arity ;
207+ int lhs ;
208+ string left ;
209+ string right ;
210+
211+ RAJoinExpr ( ) { this = TJoin ( p , line , arity , lhs , left , right ) }
212+
213+ override Predicate getPredicate ( ) { result = p }
214+
215+ override int getLine ( ) { result = line }
216+
217+ override int getLhs ( ) { result = lhs }
218+
219+ override int getArity ( ) { result = arity }
220+
221+ // Note: We could return reasonable values here sometimes.
222+ override int getARhsVariable ( ) { isVariable ( [ left , right ] , result ) }
223+
224+ // Note: We could return reasonable values here sometimes.
225+ override string getARhsPredicate ( ) {
226+ result = [ left , right ] and
227+ not isVariable ( result , _)
228+ }
229+ }
230+
231+ class RaSelectExpr extends RAExpr , TSelect {
232+ Predicate p ;
233+ int line ;
234+ int arity ;
235+ int lhs ;
236+ string rhs ;
237+
238+ RaSelectExpr ( ) { this = TSelect ( p , line , arity , lhs , rhs ) }
239+
240+ override Predicate getPredicate ( ) { result = p }
241+
242+ override int getLine ( ) { result = line }
243+
244+ override int getLhs ( ) { result = lhs }
245+
246+ override int getArity ( ) { result = arity }
247+
248+ // Note: We could return reasonable values here sometimes.
249+ override int getARhsVariable ( ) { isVariable ( rhs , result ) }
250+
251+ // Note: We could return reasonable values here sometimes.
252+ override string getARhsPredicate ( ) {
253+ result = rhs and
254+ not isVariable ( result , _)
255+ }
256+ }
257+
258+ class RaAntiJoinExpr extends RAExpr , TAntiJoin {
259+ Predicate p ;
260+ int line ;
261+ int arity ;
262+ int lhs ;
263+ string left ;
264+ string right ;
265+
266+ RaAntiJoinExpr ( ) { this = TAntiJoin ( p , line , arity , lhs , left , right ) }
267+
268+ override Predicate getPredicate ( ) { result = p }
269+
270+ override int getLine ( ) { result = line }
271+
272+ override int getLhs ( ) { result = lhs }
273+
274+ override int getArity ( ) { result = arity }
275+
276+ // Note: We could return reasonable values here sometimes.
277+ override int getARhsVariable ( ) { isVariable ( [ left , right ] , result ) }
278+
279+ // Note: We could return reasonable values here sometimes.
280+ override string getARhsPredicate ( ) {
281+ result = [ left , right ] and
282+ not isVariable ( result , _)
283+ }
284+ }
111285}
0 commit comments