|
1 |
<?xml version="1.0"?>
|
|
2 |
|
|
3 |
<!--
|
|
4 |
/*
|
|
5 |
** Module : nested_find.rules
|
|
6 |
** Abstract : annotation for nested find in for each
|
|
7 |
**
|
|
8 |
** Copyright (c) 2022, Golden Code Development Corporation.
|
|
9 |
**
|
|
10 |
** _#_ _I_ __Date__ __JPRM__ __________________________________Description___________________________________
|
|
11 |
** 001 DDF 20221123 Created initial version. Creates annotation
|
|
12 |
** for nested FIND in FOR EACH.
|
|
13 |
** 002 DDF 20221125 Track nested FIND that reference the same buffer.
|
|
14 |
** 003 DDF 20221202 Improved nested find tracking.
|
|
15 |
**
|
|
16 |
*/
|
|
17 |
-->
|
|
18 |
|
|
19 |
<!--
|
|
20 |
** This program is free software: you can redistribute it and/or modify
|
|
21 |
** it under the terms of the GNU Affero General Public License as
|
|
22 |
** published by the Free Software Foundation, either version 3 of the
|
|
23 |
** License, or (at your option) any later version.
|
|
24 |
**
|
|
25 |
** This program is distributed in the hope that it will be useful,
|
|
26 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28 |
** GNU Affero General Public License for more details.
|
|
29 |
**
|
|
30 |
** You may find a copy of the GNU Affero GPL version 3 at the following
|
|
31 |
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
32 |
**
|
|
33 |
** Additional terms under GNU Affero GPL version 3 section 7:
|
|
34 |
**
|
|
35 |
** Under Section 7 of the GNU Affero GPL version 3, the following additional
|
|
36 |
** terms apply to the works covered under the License. These additional terms
|
|
37 |
** are non-permissive additional terms allowed under Section 7 of the GNU
|
|
38 |
** Affero GPL version 3 and may not be removed by you.
|
|
39 |
**
|
|
40 |
** 0. Attribution Requirement.
|
|
41 |
**
|
|
42 |
** You must preserve all legal notices or author attributions in the covered
|
|
43 |
** work or Appropriate Legal Notices displayed by works containing the covered
|
|
44 |
** work. You may not remove from the covered work any author or developer
|
|
45 |
** credit already included within the covered work.
|
|
46 |
**
|
|
47 |
** 1. No License To Use Trademarks.
|
|
48 |
**
|
|
49 |
** This license does not grant any license or rights to use the trademarks
|
|
50 |
** Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
|
|
51 |
** of Golden Code Development Corporation. You are not authorized to use the
|
|
52 |
** name Golden Code, FWD, or the names of any author or contributor, for
|
|
53 |
** publicity purposes without written authorization.
|
|
54 |
**
|
|
55 |
** 2. No Misrepresentation of Affiliation.
|
|
56 |
**
|
|
57 |
** You may not represent yourself as Golden Code Development Corporation or FWD.
|
|
58 |
**
|
|
59 |
** You may not represent yourself for publicity purposes as associated with
|
|
60 |
** Golden Code Development Corporation, FWD, or any author or contributor to
|
|
61 |
** the covered work, without written authorization.
|
|
62 |
**
|
|
63 |
** 3. No Misrepresentation of Source or Origin.
|
|
64 |
**
|
|
65 |
** You may not represent the covered work as solely your work. All modified
|
|
66 |
** versions of the covered work must be marked in a reasonable way to make it
|
|
67 |
** clear that the modified work is not originating from Golden Code Development
|
|
68 |
** Corporation or FWD. All modified versions must contain the notices of
|
|
69 |
** attribution required in this license.
|
|
70 |
-->
|
|
71 |
|
|
72 |
<rule-set input="tree">
|
|
73 |
|
|
74 |
<worker class="com.goldencode.p2j.uast.ProgressPatternWorker" namespace="prog" />
|
|
75 |
|
|
76 |
<variable name="scopedDict" type="com.goldencode.p2j.util.ScopedSymbolDictionary" />
|
|
77 |
<variable name="tempTableAst" type="com.goldencode.ast.Aast" />
|
|
78 |
<variable name="currentFindAst" type="com.goldencode.ast.Aast" />
|
|
79 |
<variable name="inWhere" type="java.lang.Boolean" />
|
|
80 |
<variable name="schemaName" type="java.lang.String" />
|
|
81 |
<variable name="annotationValue" type="java.lang.String" />
|
|
82 |
<variable name="annotationObject" type="java.lang.Object" />
|
|
83 |
|
|
84 |
<init-rules>
|
|
85 |
<rule>scopedDict = create("com.goldencode.p2j.util.ScopedSymbolDictionary")</rule>
|
|
86 |
<rule>inWhere = false</rule>
|
|
87 |
</init-rules>
|
|
88 |
|
|
89 |
<walk-rules>
|
|
90 |
<!-- crete a scope using the FOR EACH ast -->
|
|
91 |
<rule>type == prog.KW_FOR and
|
|
92 |
this.descendant(1, prog.KW_EACH)
|
|
93 |
<action>scopedDict.addScope(this)</action>
|
|
94 |
</rule>
|
|
95 |
|
|
96 |
<!-- add for each temp-table/buffer as symbols in the current scope -->
|
|
97 |
<rule>relativePath("KW_FOR/RECORD_PHRASE")
|
|
98 |
<action>tempTableAst = null</action>
|
|
99 |
<rule>this.getImmediateChild(prog.TEMP_TABLE, null) != null
|
|
100 |
<action>tempTableAst = this.getImmediateChild(prog.TEMP_TABLE, null)</action>
|
|
101 |
</rule>
|
|
102 |
<rule>this.getImmediateChild(prog.BUFFER, null) != null
|
|
103 |
<action>tempTableAst = this.getImmediateChild(prog.BUFFER, null)</action>
|
|
104 |
</rule>
|
|
105 |
<rule>tempTableAst != null
|
|
106 |
<action>annotationValue = #(java.lang.String) tempTableAst.getAnnotation("schemaname")</action>
|
|
107 |
<action>annotationObject = tempTableAst.getAnnotation("schemaname")</action>
|
|
108 |
<action>scopedDict.addSymbol(false, annotationValue, annotationObject)</action>
|
|
109 |
</rule>
|
|
110 |
</rule>
|
|
111 |
|
|
112 |
<!-- save current AST of a FIND with a WHERE clause -->
|
|
113 |
<rule>type == prog.KW_FIND and this.downPath("RECORD_PHRASE/KW_WHERE") and scopedDict.size() > 0
|
|
114 |
<action>currentFindAst = this</action>
|
|
115 |
</rule>
|
|
116 |
|
|
117 |
<!-- toggle flag when the finding the AST of the WHERE clause -->
|
|
118 |
<rule>type == prog.KW_WHERE and currentFindAst != null and scopedDict.size() > 0
|
|
119 |
<action>inWhere = true</action>
|
|
120 |
</rule>
|
|
121 |
|
|
122 |
<!-- if schemaname annotation is present, search it among the symbols
|
|
123 |
from all the scopes and annotate the find AST saved
|
|
124 |
previously -->
|
|
125 |
<rule>inWhere and scopedDict.size() > 0 and this.isAnnotation("schemaname")
|
|
126 |
<action>schemaName = #(java.lang.String) this.getAnnotation("schemaname")</action>
|
|
127 |
<rule>schemaName.contains(".")
|
|
128 |
<!-- get the buffer name if the schemaname specifies a field -->
|
|
129 |
<action>schemaName = splitToList(schemaName, "\.").get(0)</action>
|
|
130 |
</rule>
|
|
131 |
<rule>scopedDict.lookupSymbol(schemaName) != null
|
|
132 |
<action>putReferenceNote(currentFindAst.getId(), "nested_find", true)</action>
|
|
133 |
</rule>
|
|
134 |
</rule>
|
|
135 |
</walk-rules>
|
|
136 |
|
|
137 |
<ascent-rules>
|
|
138 |
<!-- pop the scope when exiting the FOR EACH statement -->
|
|
139 |
<rule>type == prog.BLOCK and
|
|
140 |
this.prevSibling != null and
|
|
141 |
this.prevSibling.type == prog.KW_FOR and
|
|
142 |
this.prevSibling.descendant(1, prog.KW_EACH)
|
|
143 |
<action>scopedDict.deleteScope()</action>
|
|
144 |
</rule>
|
|
145 |
|
|
146 |
<!-- toggle flag when exiting the FIND statement -->
|
|
147 |
<rule>inWhere and type == prog.KW_FIND
|
|
148 |
<action>inWhere = false</action>
|
|
149 |
</rule>
|
|
150 |
</ascent-rules>
|
|
151 |
|
|
152 |
</rule-set>
|