Project

General

Profile

block_properties.patch

Dănuț Filimon, 09/19/2025 06:41 AM

Download (5.41 KB)

View differences:

new/rules/annotations/block_properties.rules 2025-07-21 10:03:56 +0000
411 411
      </function>
412 412
      
413 413
      <function name="createLabel">
414
         <parameter name="target"  type="com.goldencode.ast.Aast" />
415
         <parameter name="blk"     type="com.goldencode.ast.Aast" />
416
         <variable  name="lref"    type="com.goldencode.ast.Aast" />
417
         <variable  name="nref"    type="com.goldencode.ast.Aast" />
418
         <return    name="creat"   type="java.lang.Boolean" />
414
         <parameter name="target"     type="com.goldencode.ast.Aast" />
415
         <parameter name="blk"        type="com.goldencode.ast.Aast" />
416
         <parameter name="isCatch"    type="java.lang.Boolean" />
417
         <variable  name="lref"       type="com.goldencode.ast.Aast" />
418
         <variable  name="nref"       type="com.goldencode.ast.Aast" />
419
         <variable  name="label_text" type="java.lang.String" />
420
         <return    name="creat"      type="java.lang.Boolean" />
419 421
         
420 422
         <rule>creat = false</rule>
421 423
         
......
424 426
            <!-- only inner blocks and editing blocks can be labeled -->
425 427
            <rule>
426 428
               blk.type == prog.inner_block  or
427
               blk.type == prog.editing_block
428
         
429
               blk.type == prog.editing_block or
430
               isCatch
431
                        
429 432
               <!-- find the label definition -->
430 433
               <action>
431 434
                  lref = blk.getImmediateChild(prog.label_def, null)
432 435
               </action>
433 436
               
434
               <rule>lref != null
437
               <rule>isCatch
438
                  <action>label_text = ""</action>
439
                  <action on="false">label_text = lref.text</action>
440
               </rule>
441
               
442
               <rule>lref != null or isCatch
435 443
                  <!-- create the label reference and the cross-ref to the
436 444
                       definition -->
437 445
                  <action>
438 446
                     nref = createProgressAst(prog.label,
439
                                              lref.text,
447
                                              label_text,
440 448
                                              target,
441 449
                                              0)
442 450
                  </action>
443
                  <action>execLib("createXref", nref, lref.id)</action>
451
                  
452
                  <rule>lref != null                  
453
	                 <action>execLib("createXref", nref, lref.id)</action>
454
                  </rule>
455
                  <rule>isCatch
456
                     <action>nref.putAnnotation("localname", label_text)</action>
457
                  </rule>
444 458
                  <action>creat = true</action>
445 459
               </rule>
446 460
            </rule>
......
1156 1170
         parent.type == prog.statement  and
1157 1171
         !descendant(prog.label, 1)
1158 1172
         
1173
         <variable name="action"      type="com.goldencode.ast.Aast" />
1174
         <variable name="actionLabel" type="com.goldencode.ast.Aast" />
1175
         <variable name="copyErr"     type="com.goldencode.ast.Aast" />
1176
         <variable name="isCatch"     type="java.lang.Boolean" />
1177
         
1178
         
1179
         <action>isCatch = false</action>
1180
         <rule>upPath(parent, prog.block)          and
1181
               upPath(parent.parent, prog.kw_catch)
1182
            <action>action = copy.firstChild</action>
1183
            
1184
            <rule>action != null and action.type != prog.label
1185
               <action>isCatch = true</action>
1186
            </rule>
1187
         </rule>
1188
         
1159 1189
         <!-- errBlock should never be null here, it should always be at
1160 1190
              least set to the external procedure, if this is set to a
1161 1191
              top-level block then no label will be created since such
......
1163 1193
              will be a label created -->
1164 1194
         <action>
1165 1195
            putNote("top_level_target",
1166
                    !evalLib("createLabel", copy, errBlock))
1196
                    !evalLib("createLabel", copy, errBlock, isCatch))
1167 1197
         </action>
1198
         
1199
         <rule>isCatch
1200
            <action>errBlock = copyErr</action>
1201
         </rule>
1168 1202
      </rule>
1169 1203
           
1170 1204
      <!-- ON phrase without an explicit target (label) for the UNDO must
......
1182 1216
         
1183 1217
         <!-- make the current block label explicit -->
1184 1218
         <action>
1185
            evalLib("createLabel", copy, copy.getAncestor(3))
1219
            evalLib("createLabel", copy, copy.getAncestor(3), false)
1186 1220
         </action>
1187 1221
      </rule>
1188 1222
      
......
1416 1450
            <action>copy.type = prog.kw_return</action>
1417 1451
            
1418 1452
            <!-- found a block target, create a label targeting the block -->
1419
            <action on="false">execLib("createLabel", copy, blockRef)</action>
1453
            <action on="false">execLib("createLabel", copy, blockRef, false)</action>
1420 1454
         </rule>
1421 1455
      
1422 1456
      </rule>
......
1434 1468
         <rule>nonDoBlock != null
1435 1469
            <!-- there is a non-DO block between this node and the nearest
1436 1470
                 top level block -->
1437
            <action>execLib("createLabel", copy, nonDoBlock)</action>
1471
            <action>execLib("createLabel", copy, nonDoBlock, false)</action>
1438 1472
            
1439 1473
            <!-- convert LEAVE to RETURN -->
1440 1474
            <action on="false">copy.type = prog.kw_return</action>