This file is indexed.

/usr/share/doc/adacontrol/adacontrol_pm.html is in adacontrol-doc 1.19r10-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>AdaControl Programmer Manual V1.19r10</title>

<meta name="description" content="AdaControl Programmer Manual V1.19r10">
<meta name="keywords" content="AdaControl Programmer Manual V1.19r10">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<link href="#Top" rel="start" title="Top">
<link href="dir.html#Top" rel="up" title="(dir)">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<h1 class="settitle" align="center">AdaControl Programmer Manual V1.19r10</h1>



<a name="Top"></a>
<div class="header">
<p>
Next: <a href="#General" accesskey="n" rel="next">General</a>, Previous: <a href="dir.html#Top" accesskey="p" rel="prev">(dir)</a>, Up: <a href="dir.html#Top" accesskey="u" rel="up">(dir)</a> &nbsp; </p>
</div>
<a name="AdaControl-Programmer-Manual"></a>
<h1 class="top">AdaControl Programmer Manual</h1>

<p>This is the AdaControl Programmer Manual. It is intended for those who
want to add new rules to AdaControl, or more generally modify (and
presumably improve!) AdaControl. Reading this manual is not necessary
to use AdaControl. On the other hand, it is assumed that the reader
is familiar with how to use AdaControl.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#General" accesskey="1">General</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-framework-and-utilities-packages" accesskey="2">The framework and utilities packages</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Writing-a-new-rule" accesskey="3">Writing a new rule</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="4">Plugging-in a new rule into the framework</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Testing-and-debugging-a-rule" accesskey="5">Testing and debugging a rule</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<p>Commercial support is available for AdaControl. If you plan to use
AdaControl for industrial projects, or if you want it to be customized
or extended to match your own needs, please contact Adalog at
<a href="mailto::info@adalog.fr">info@adalog.fr</a>.
</p>
<p>AdaControl is Copyright &copy; 2005-2017 Eurocontrol/Adalog,
except for some specific modules that are &copy; 2006
Belgocontrol/Adalog, &copy; 2006 CSEE/Adalog, &copy;
2006 SAGEM/Adalog, or &copy; 2015 Alstom/Adalog. AdaControl is
free software; you can redistribute
it and/or modify it under terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version. This unit is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.  You
should have received a copy of the GNU General Public License
distributed with this program; see file COPYING.  If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
</p>
<p>As a special exception, if other files instantiate generics from this
program, or if you link units from this program with other files to
produce an executable, this does not by itself cause the resulting
executable to be covered by the GNU General Public License. This
exception does not however invalidate any other reasons why the
executable file might be covered by the GNU Public License.
</p>
<p>This document is Copyright &copy; 2005-2017
Eurocontrol/Adalog. This document may be copied, in whole or in part,
in any form or by any means, as is or with alterations, provided that
(1) alterations are clearly marked as alterations and (2) this
copyright notice is included unmodified in any copy.
</p>

<hr>
<a name="General"></a>
<div class="header">
<p>
Next: <a href="#The-framework-and-utilities-packages" accesskey="n" rel="next">The framework and utilities packages</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; </p>
</div>
<a name="General-1"></a>
<h2 class="chapter">1 General</h2>
<p>This programmer manual describes how to add new rules to
AdaControl. Since AdaControl is based on ASIS, this manual assumes
that the reader has some familiarity with ASIS programming.
</p>
<p>Modifying AdaControl needs of course a source distribution. It is OK
to work with the regular source distribution, but if you intend to
submit your patches, it is appropriate to get the latest &ldquo;bleeding
edge&rdquo; version from our GIT repository on SourceForge. Instructions on
how to get AdaControl from GIT are
<a href="http://sourceforge.net/projects/adacontrol/files/download-from-git.txt/download">here</a>
</p>
<a name="vocabulary"></a>
<h3 class="section">1.1 vocabulary</h3>
<p>Some terms have a precise definition in AdaControl, and will be used
with that signification in the rest of this manual.
</p>
<p>A <i>rule</i> is an AdaControl package whose purpose is to recognize
occurrences of certain constructs in Ada programs. All rules are
children of  the &ldquo;Rules&rdquo; package. By extension, the term rule is
also used to designate the check that is performed by the package. A
rule has a name, and may have parameters.
</p>
<p>A <i>control</i> defines a check to be performed on some Ada text. A
control is defined by a rule, and the value of the parameters given to
the rule.
</p>
<p>A <i>command</i> is a statement in the command language interpreted by
AdaControl.
</p>
<p>A <i>control command</i> is a kind of command that describes a check to
be performed. A control commmand includes a <i>kind</i> (&ldquo;check&rdquo;, &ldquo;search&rdquo;
or &ldquo;count&rdquo;, see user&rsquo;s guide), and a control (rule name and parameters).
</p>
<p>A <i>context</i> is a set of values used by a rule to keep the
characteristics associated with a control. Those values can, but need
not necessarily, be the parameters of the control.
</p>
<a name="General-organization"></a>
<h3 class="section">1.2 General organization</h3>
<p>The AdaControl tool includes several main components. Those that are
relevant for writing new rules are:
</p><ul>
<li> A general <i>framework</i> that provides services that are necessary to
write rules. This includes a special module, <code>Framework.Plugs</code>,
where rules are plugged-in;
</li><li> A set of <i>utilities</i> providing useful functionalities, but not
specific to the writing of rules. Actually, the utilities packages are
shared with other programs from Adalog&rsquo;s &ldquo;Semtools&rdquo; family of tools.
</li><li> The <i>rules</i> themselves.
</li></ul>

<p>This clear distinction makes it easy to add new rules. Actually, the
framework relieves the programmer from all the &ldquo;dirty work&rdquo;, and
adding a new rule requires nothing else than caring about the rule
itself.
</p>
<hr>
<a name="The-framework-and-utilities-packages"></a>
<div class="header">
<p>
Next: <a href="#Writing-a-new-rule" accesskey="n" rel="next">Writing a new rule</a>, Previous: <a href="#General" accesskey="p" rel="prev">General</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; </p>
</div>
<a name="The-framework-and-utilities-packages-1"></a>
<h2 class="chapter">2 The framework and utilities packages</h2>

<p>The framework includes the package <code>Framework</code> itself and its
public child packages. There are also some private child packages, but
they are of course not relevant to the users of the framework.
</p>
<p>In each package, services (declarations, subprograms) that are
relevant for writing rules appear at the beginning of the package
specification. Other services that are used by the rest of the
framework, but not intended to be called from a rule, appear below the
following comment lines:
</p><div class="example">
<pre class="example">   --
   --  Declarations below this line are for the use of the framework
   --
</pre></div>

<p>This section provides an overview of the services that are made
available by the framework and other utilities packages. It is not the
purpose of this section to describe the syntax of every service
provided : please refer to the comments in the specification of each
package. Existing rules are also typical examples of how to use these
functionnalities.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#The-package-Adactl_005fConstants" accesskey="1">The package Adactl_Constants</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework" accesskey="2">The package Framework</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002eRules_005fManager" accesskey="3">The package Framework.Rules_Manager</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002eReports" accesskey="4">The package Framework.Reports</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002eFixes" accesskey="5">The package Framework.Fixes</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002eLanguage" accesskey="6">The package Framework.Language</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002eVariables" accesskey="7">The package Framework.Variables</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Framework_002ePlugs" accesskey="8">The package Framework.Plugs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Scope_005fManager" accesskey="9">The package Scope_Manager</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Rules">The package Rules</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-Utilities">The package Utilities</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-packages-Thick_005fQueries-and-Framework_002eQueries">The packages Thick_Queries and Framework.Queries</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-packages-Linear_005fQueue-and-Binary_005fMap">The packages Linear_Queue and Binary_Map</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#The-package-A4G_005fBugs">The package A4G_Bugs</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<hr>
<a name="The-package-Adactl_005fConstants"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework" accesskey="n" rel="next">The package Framework</a>, Previous: <a href="#The-framework-and-utilities-packages" accesskey="p" rel="prev">The framework and utilities packages</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Adactl_005fConstants-1"></a>
<h3 class="section">2.1 The package Adactl_Constants</h3>
<p>AdaControl has some fixed size structures that limit the complexity of
the programs it can handle, like for example the maximum numbers of
parameters that subprograms can have, the maximum nesting of loops,
etc.
</p>
<p>These limits are set as constants in the package
<code>Adactl_Constants</code>. These values are large enough to accomodate
any reasonable program, but should you hit one of these limits, you
can safely change them here. No other change is required.
</p>
<p>If a rule needs to set a fixed dimension to some tables for example,
it should use the constants defined in this package. If no existing
constant is appropriate, add a new one to the package, don&rsquo;t define
dimensioning constants in the rule itself.
</p>
<hr>
<a name="The-package-Framework"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002eRules_005fManager" accesskey="n" rel="next">The package Framework.Rules_Manager</a>, Previous: <a href="#The-package-Adactl_005fConstants" accesskey="p" rel="prev">The package Adactl_Constants</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework-1"></a>
<h3 class="section">2.2 The package Framework</h3>
<p>The package Framework includes general services, needed by most
rules. These include:
</p>
<ul>
<li> The definition of some constants that are used to fix a bound to the
number of allowable constructs. Use these constants to dimension
tables for example.
</li><li> The notion of <i>location</i>, with associated subprograms. A location is
a place within a source file where some construct happens.
</li><li> The notion of <i>rule context</i>. A rule context is some information
that a rule associates to entities. For example, given the following
rules:
<div class="example">
<pre class="example">search Entities (Blah);
Strictly_Forbidden: check entities (Ada.Unchecked_Conversion)
</pre></div>
<p>the rule Entities must associate that <code>Blah</code> is the target of a
search, and that <code>Ada.Unchecked_Deallocation</code> is the target of a
check with label <code>Strictly_Forbidden</code>.
</p></li></ul>

<hr>
<a name="The-package-Framework_002eRules_005fManager"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002eReports" accesskey="n" rel="next">The package Framework.Reports</a>, Previous: <a href="#The-package-Framework" accesskey="p" rel="prev">The package Framework</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002eRules_005fManager-1"></a>
<h3 class="section">2.3 The package Framework.Rules_Manager</h3>
<p>The package <code>Framework.Rules_Manager</code> is used to register and
manage rules.
</p>
<p>The procedure  <code>Register</code> declares the name of the rule and the
associated <code>Help</code>, <code>Add_Control</code>, <code>Command</code>,
<code>Prepare</code>, and <code>Finalize</code> procedures.
</p>
<p>Note that there is nothing else to do to make a rule known to the
system: once it is registered, it will be recognized on the command
line, help command will work, etc.
</p>
<p>The procedure  <code>Enter</code> is used to let the system know which rule is
currently active.
</p>
<hr>
<a name="The-package-Framework_002eReports"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002eFixes" accesskey="n" rel="next">The package Framework.Fixes</a>, Previous: <a href="#The-package-Framework_002eRules_005fManager" accesskey="p" rel="prev">The package Framework.Rules_Manager</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002eReports-1"></a>
<h3 class="section">2.4 The package Framework.Reports</h3>
<p>The package <code>Framework.Reports</code> is used to report error or found
messages when a rule matches. It deals automatically with things like
rules being temporarily disabled, therefore the rule does not have to
care.
</p>
<p>The main service provided by this package is the <code>Report</code> procedure,
which comes in two flavors. This is the only allowed way for a rule to
report its findings, never use <code>Wide_Text_IO</code> or any other
mean. The specifications of the Report procedures are:
</p>
<div class="example">
<pre class="example"><b>procedure</b> Report (Rule_Id    : <b>in</b> Wide_String;
                  Rule_Label : <b>in</b> Wide_String;
                  Ctl_Type   : <b>in</b> Control_Kinds;
                  Loc        : <b>in</b> Location;
                  Msg        : <b>in</b> Wide_String);

<b>procedure</b> Report (Rule_Id    : <b>in</b> Wide_String;
                  Context    : <b>in</b> Root_Context'class;
                  Loc        : <b>in</b> Location;
                  Msg        : <b>in</b> Wide_String);
</pre></div>

<p>The first procedure expects the label and type to be given
explicitely, while the second one gets them from a <code>Context</code>
object (see comments in the package).
</p>
<p>Note that there is only one string for the message. Please do not try
to &ldquo;improve&rdquo; the presentation by introducing line breaks in the
report message: the output of AdaControl should remain parseable by
rather naive tools, therefore it is necessary to ensure that one
output line = one message.
</p>
<p>In addition, there is an <code>Uncheckable</code> procedure, with the following profile:
</p><div class="example">
<pre class="example">   <b>procedure</b> Uncheckable (Rule_Id : <b>in</b> Wide_String;
                          Risk    : <b>in</b> Uncheckable_Consequence;
                          Loc     : <b>in</b> Location;
                          Msg     : <b>in</b> Wide_String);
</pre></div>
<p>This procedure is called each time a rule encounters some dynamic
construct that prevents normal checking. The parameter <code>Risk</code> is
<code>False_Positive</code> if the consequence of not being able to analyze
the construct would result in wrong error messages, and
<code>False_Negative</code> if it would result in not detecting something
that could be an error. It is important to call this procedure for any
non-checkable construct, since it is what allows the rule
&ldquo;Uncheckable&rdquo; to work.
</p>
<hr>
<a name="The-package-Framework_002eFixes"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002eLanguage" accesskey="n" rel="next">The package Framework.Language</a>, Previous: <a href="#The-package-Framework_002eReports" accesskey="p" rel="prev">The package Framework.Reports</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002eReports_002eFixes"></a>
<h3 class="section">2.5 The package Framework.Reports.Fixes</h3>
<p>The package <code>Framework.Reports.Fixes</code> provides functionalities
for generating fixes to the source code.
</p>
<p>The functionalities provided here allow to insert, delete, or replace
elements of the source text. See the specification for details.
</p>
<p>If your rule knows how to fix a violation, just call the corresponding
subprograms from this package. Always call the fixes subprograms <i>after</i> the
corresponding report subprograms, because it&rsquo;s the report subprogram that
determines if the rule is enabled or disabled.
</p>
<p>Note that it is better to delete some text than to replace it if
possible, because the fixing tool (<code>adactl_fix</code>) handles
conflicts between deletions better than conflicts between
insertions/replacements. For example, to remove unnecessary
parentheses, the rule <code>Simplifiable_Expressions(Parentheses)</code>
removes the opening and closing parentheses, rather than replace the
<code>A_Parenthesized_Expression</code> with its content (the
<code>Expression_Parenthesized</code>).
</p>
<hr>
<a name="The-package-Framework_002eLanguage"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002eVariables" accesskey="n" rel="next">The package Framework.Variables</a>, Previous: <a href="#The-package-Framework_002eFixes" accesskey="p" rel="prev">The package Framework.Fixes</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002eLanguage-1"></a>
<h3 class="section">2.6 The package Framework.Language</h3>
<p>The package <code>Framework.Language</code> provides functionalities
for parsing parameters, as well as the rest of the command language;
but of course only the subprograms used to parse parameters are
relevant to the writing of rules.
</p>
<p>The functionalities provided here allow a good deal of freedom for
defining the syntax of a rule&rsquo;s parameters (although it is a good idea
to stay as close as possible to the syntax of other rules). Look at
the syntax of various rules to see what can be accomplished.
</p>
<p>The package provides a <code>Parameter_Exists</code> function that returns
<code>True</code> if there are parameters left to parse. The kind of the
next parameter can be checked with the <code>Is_Integer_Parameter</code>,
<code>Is_Float_Parameter</code>, or <code>Is_String_Parameter</code>
functions. The corresponding parameter value can be retrieved with the
<code>Get_Integer_Parameter</code>, <code>Get_Float_Parameter</code>,
<code>Get_Name_Parameter</code>, <code>Get_File_Parameter</code>,
<code>Get_String_Parameter</code>, or <code>Get_Entity_Parameter</code>
functions. The latter function returns an entity specification, i.e. a
descriptor for something which is expected to be a general
specification for an Ada entity (including overloading information,
for example). Such an entity can be used as a key for a context.
</p>
<p>There is a generic package <code>Flag_Utilities</code> to help manage flags
(keywords) parameters defined by an enumerated type. An instantiation
of this package provides a <code>Get_Flag_Parameter</code> procedure to
parse the flags, an <code>Image</code> function to get a string
representation of a flag, and a <code>Help_On_Flags</code> function to print
the help message that enumerates all possible flag values.
</p>
<p>There is a <code>Get_Modifier</code> to process modifiers (things like
&ldquo;not&rdquo; or &ldquo;case_sensitive&rdquo; in front of a parameter). For more
sophisticated modifiers, you can instantiate the generic package
<code>Modifier_Utilities</code>, which works like <code>Flag_Utilities</code>, but
also provides the notion of sets of modifiers.
</p>
<p>Note that if you instantiate <code>Flag_Utilities</code> or
<code>Modifier_Utilities</code> in a library package (as will be the case
most of the time), you <i>must</i> put a <code>pragma Elaborate
(Framework.Language);</code> on top of the package. Failing to do so will
result in circular elaboration problems; (<code>pragma Elaborate_All</code>,
as implicitely provided by GNAT, does <i>not</i> work).
</p>
<hr>
<a name="The-package-Framework_002eVariables"></a>
<div class="header">
<p>
Next: <a href="#The-package-Framework_002ePlugs" accesskey="n" rel="next">The package Framework.Plugs</a>, Previous: <a href="#The-package-Framework_002eLanguage" accesskey="p" rel="prev">The package Framework.Language</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002eVariables-1"></a>
<h3 class="section">2.7 The package Framework.Variables</h3>
<p>This package manages rule variables (the ones that can be set with
the <code>set</code> command of the language).
</p>
<p>A rule may use any number of rule variables for adjusting its
behaviour. A rule variable holds a value, and various subprograms are
provided for setting and getting the associated value.
</p>
<p>Rule variables are extensions of
<code>Framework.Variables.Object</code>. Typically, they extend this type
with a value that can be of any type. Abstract subprograms that need
to be overriden include <code>Set</code> and <code>Value_Image</code> for setting
and getting a value from/to a string and <code>All_Values</code> to give
possible values for help messages.
</p>
<p>Generic packages are provided to make it easier to define variable
types associated to enumerated types and integer types. In addition,
the package <code>Framework.Variables.Shared_Types</code> provides variable
types for commonly used associated types.
</p>
<p>When a rule needs a rule variable, it declares an object of the
appropriate type, and registers it to the framework by calling
<code>Framework.Variables.Register</code>, passing a pointer to the object
and the name used to refer to it. This name must be given in upper
case, and start with the rule&rsquo;s name, like
&ldquo;<code>EXPRESSIONS.CALLED_INFO</code>&rdquo; for example. Of course, it is
better to use <code>Rule_Id</code> for building the name, like in:
</p><div class="example">
<pre class="example">Framework.Variables.Register (Called_Info'Access,
                              Variable_Name=&gt; Rule_Id &amp; &quot;.CALLED_INFO&quot;);
</pre></div>
<p>This call is typically put in the initalization part of the rule&rsquo;s
package, after the registration of the rule itself.
</p>
<p>The rule <code>Expressions</code> (in file <code>rules-expressions.adb</code>
includes a typical usage of a rule variable.
</p>
<hr>
<a name="The-package-Framework_002ePlugs"></a>
<div class="header">
<p>
Next: <a href="#The-package-Scope_005fManager" accesskey="n" rel="next">The package Scope_Manager</a>, Previous: <a href="#The-package-Framework_002eVariables" accesskey="p" rel="prev">The package Framework.Variables</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Framework_002ePlugs-1"></a>
<h3 class="section">2.8 The package Framework.Plugs</h3>
<p>Procedures in the package <code>Framework.Plugs</code> are called during the
traversal of the Ada source code. Unlike the rest of the framework,
this package does not provide services to rules, but instead <i>calls</i>
processing procedures defined in the rules packages. Therefore, it is
necessary to <i>plug</i> the corresponding calls in this package. This is
described in details in <a href="#Plugging_002din-a-new-rule-into-the-framework">Plugging-in a new rule into the framework</a>.
</p>
<hr>
<a name="The-package-Scope_005fManager"></a>
<div class="header">
<p>
Next: <a href="#The-package-Rules" accesskey="n" rel="next">The package Rules</a>, Previous: <a href="#The-package-Framework_002ePlugs" accesskey="p" rel="prev">The package Framework.Plugs</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Scope_005fManager-1"></a>
<h3 class="section">2.9 The package Scope_Manager</h3>
<p>The package <code>Scope_Manager</code> provides facilities for rules that
need to follow scoping rules (i.e. which identifiers are visible at a
given place). It provides subprograms to query currently active
scopes, and a generic package that allows associating any kind of
information to a scope. Scopes are automatically managed: the
information will disappear when the corresponding scope is exited,
except for information associated to package specifications that will
be restored when the corresponding body is entered.
</p>
<p>The scope manager follows strictly the visibility rules for child
units: when entering a public child unit, the scope from the visible
part of the parent is restored, and when entering the private part of
the child, the scope of the private part of the parent is restored. In
the case of a private child, the full scope of the parent is restored
upon entering.
</p>
<p>See the package specification for more details.
</p>
<p>Note: this package used to be a child of <code>Framework</code> in previous
versions of AdaControl. This has been changed to be an autonomous
package to make it reusable by other programs.
</p>
<hr>
<a name="The-package-Rules"></a>
<div class="header">
<p>
Next: <a href="#The-package-Utilities" accesskey="n" rel="next">The package Utilities</a>, Previous: <a href="#The-package-Scope_005fManager" accesskey="p" rel="prev">The package Scope_Manager</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Rules-1"></a>
<h3 class="section">2.10 The package Rules</h3>
<p>The package <code>Rules</code> is (almost) empty. It&rsquo;s  purpose is to serve as the
parent package of all rules.
</p>
<p>It simply provides an empty state type (<code>Null_State</code>), and a null procedure that can
be used for instantiating <code>Traverse_Element</code> in simple cases.
</p>
<hr>
<a name="The-package-Utilities"></a>
<div class="header">
<p>
Next: <a href="#The-packages-Thick_005fQueries-and-Framework_002eQueries" accesskey="n" rel="next">The packages Thick_Queries and Framework.Queries</a>, Previous: <a href="#The-package-Rules" accesskey="p" rel="prev">The package Rules</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-Utilities-1"></a>
<h3 class="section">2.11 The package Utilities</h3>
<p>This package provides various general facilities that are not specific
to AdaControl. The main elements provided are:
</p>
<ul>
<li> <code>User_Message</code> and <code>User_Log</code>. Both procedures output a
message, the difference being that <code>User_Log</code> outputs its message
only in verbose mode. <code>User_Message</code> is used to print help
messages. <code>User_Log</code> could be used if some rule wanted to print
some extra information in verbose mode. Note that these procedures
should <i>not</i> be used to report the result of a check or search (use
<code>Framework.Reports.Report</code> instead).

</li><li> String handling services, see package specification

</li><li> Error management. The <code>Error</code> procedure is not to be called
directly, use <code>Framework.Language.Parameter_Error</code> instead to
report errors in user provided parameters. In most cases, parameters
are checked in the <code>Add_Control</code> procedure of the rule
(see <a href="#Writing-a-new-rule">Writing a new rule</a>), and therefore errors are reported during
the parsing of the commands. In some cases, incorrect parameters are
discovered while traversing the code. It is acceptable to call
<code>Framework.Language.Parameter_Error</code> at any time, but be aware
that this will immediately stop all analysis. See the
<code>Rules.Unsafe_Paired_Calls</code> for an example of this.

<p>The <code>Failure</code> procedure is used to report internal failures. It
is frequent in ASIS programming to have a big case statement over the
various kinds of elements, of which only a few values are interesting
or possible given the context. We strongly encourage to call
<code>Failure</code> in the <b>when others</b> part of the case statement to
trap unexpected cases. Note that the procedure is overloaded with a
version that allows to print information about the failing element.
</p>
</li><li> Debugging facilities. Several <code>Trace</code> procedures allow you to
output a message, possibly with a boolean value, or the context of an
ASIS element or element list. There is also an <code>Assert</code> procedure
that calls <code>Failure</code> if its condition is false; well placed
<code>Assert</code> calls are very helpfull in debugging. Note that traces
are output only in debug mode.

</li><li> Other facilities for managing the output that are called by the
framework, but not useful for writing rules.

</li></ul>

<hr>
<a name="The-packages-Thick_005fQueries-and-Framework_002eQueries"></a>
<div class="header">
<p>
Next: <a href="#The-packages-Linear_005fQueue-and-Binary_005fMap" accesskey="n" rel="next">The packages Linear_Queue and Binary_Map</a>, Previous: <a href="#The-package-Utilities" accesskey="p" rel="prev">The package Utilities</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-packages-Thick_005fQueries-and-Framework_002eQueries-1"></a>
<h3 class="section">2.12 The packages Thick_Queries and Framework.Queries</h3>
<p>These packages contain high level services that are built on top of
Asis queries, and can therefore be quite useful to the writing of
rules. The queries are documented in the specification of the
packages.
</p>
<p>The difference between the packages is that <code>Thick_Queries</code> does
not depend in any way on the other parts of AdaControl (and notably on
the framework); it is therefore directly reusable for any ASIS
application. On the other hand, <code>Framework.Queries</code> requires
facilities provided by the framework, and is therefore not directly
reusable outside of AdaControl.
</p>
<hr>
<a name="The-packages-Linear_005fQueue-and-Binary_005fMap"></a>
<div class="header">
<p>
Next: <a href="#The-package-A4G_005fBugs" accesskey="n" rel="next">The package A4G_Bugs</a>, Previous: <a href="#The-packages-Thick_005fQueries-and-Framework_002eQueries" accesskey="p" rel="prev">The packages Thick_Queries and Framework.Queries</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-packages-Linear_005fQueue-and-Binary_005fMap-1"></a>
<h3 class="section">2.13 The packages Linear_Queue and Binary_Map</h3>
<p>These packages provide simple generic containers that are needed by several rules.
</p>
<p>The generic package <code>Linear_Queue</code> can be instantiated with any
(non-limited) <code>Component</code> type, and provides a simple queue of
elements. Note that this queue has <i>value</i> semantics: when a queue
is assigned, its content is duplicated. Queues are controlled, and
therefore all internal storage allocations are internally managed. The
package <code>Framework.Element_Queue</code> is an instantiation of
<code>Linear_Queue</code> with the type <code>Asis.Element</code>.
</p>
<p>The generic package <code>Binary_Map</code> can be instantiated with a
<code>Key_Type</code> and a <code>Value_Type</code>, and associates values of
<code>Value_Type</code> to values of the <code>Key_Type</code>. The mapping uses a
binary tree; if you use it to keep user information, it is appropriate
to rebalance the tree before starting the actual
processing. See <a href="#Prepare">Prepare</a>.
</p>
<p>See existing rules for examples of using this package.
</p>
<hr>
<a name="The-package-A4G_005fBugs"></a>
<div class="header">
<p>
Previous: <a href="#The-packages-Linear_005fQueue-and-Binary_005fMap" accesskey="p" rel="prev">The packages Linear_Queue and Binary_Map</a>, Up: <a href="#The-framework-and-utilities-packages" accesskey="u" rel="up">The framework and utilities packages</a> &nbsp; </p>
</div>
<a name="The-package-A4G_005fBugs-1"></a>
<h3 class="section">2.14 The package A4G_Bugs</h3>
<p>AdaControl is quite demanding on the ASIS implementation, and we found
some bugs in ASIS-for-GNAT during its development. These have been
reported to ACT, and are fixed in the wavefront version of GNAT, or
should be fixed very soon.
</p>
<p>However, many people do not have access to the wavefront version, or
prefer to stay with the stable version. This package provides
replacements for some ASIS subprograms that do not behave as
expected. Subprograms in this package have specifications identical to
the corresponding ASIS subprograms, and are designed in such a way that
there is no harm in using them with a version of ASIS that does not
exhibit the bug. Therefore, it is strongly recommended to use the
subprograms in this package rather than their ASIS equivalent.
</p>
<p>Note that if you run the rules file <code>src/verif.aru</code> on your code,
it will spot any use of an ASIS function for which there is a
replacement in <code>A4G_Bugs</code>.
</p>
<hr>
<a name="Writing-a-new-rule"></a>
<div class="header">
<p>
Next: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="n" rel="next">Plugging-in a new rule into the framework</a>, Previous: <a href="#The-framework-and-utilities-packages" accesskey="p" rel="prev">The framework and utilities packages</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; </p>
</div>
<a name="Writing-a-new-rule-1"></a>
<h2 class="chapter">3 Writing a new rule</h2>
<p>There are two kinds of rules: <i>semantic</i> rules, which operate on Ada
elements, and <i>textual</i> rules, which operate on the source text. In
some rare cases, a rule can be of both kinds at the same time; see the
rule &ldquo;Style&rdquo; for an example of this. Note that a semantic rule can
still access the text of an Ada construct with the facilities provided
by the package <code>Asis.Text</code>, this does not require the rule to be
<code>Semantic_Textual</code>.
</p>
<p>All rules currently provided follow a common pattern, described below;
it is recommended that new rules do the same, in order to make
maintenance easier.
</p>
<p>The first thing to do before adding a new rule is to read the source
for existing rules, as they provide good examples of how a rule is
implemented. For an example of a simple rule, see <code>Rules.Entity</code>;
for an example of a sophisticated one, see
<code>Rules.Unnecessary_Use</code>. For an example of a textual rule, see
<code>Rules.Max_Line_Length</code>. Note that <code>Rules.Entity</code> can be
used as a template for writing new semantic rules, as most rules will
follow the same general structure, just making more elaborated
processing of relevant entities.
</p>
<a name="General-considerations"></a>
<h3 class="section">3.1 General considerations</h3>
<p>A rule is implemented as a child package of package <code>Rules</code>. The
following sections describe the structure of the specification and
body of a rule package.
</p>
<p>It is good practice to use only one string type all over a program,
and since ASIS is based on <code>Wide_String</code>, a rule should not use
the type <code>String</code>, but rather use <code>Wide_String</code> instead.
</p>
<a name="Specification"></a>
<h3 class="section">3.2 Specification</h3>
<p>The specification of a rule package must contain the following
elements:
</p>
<a name="Rule_005fID"></a>
<h4 class="subsection">3.2.1 Rule_ID</h4>
<p>Rule_ID is a constant of type <code>Wide_String</code>. It is the unique
rule identifier of a rule. It is used by the package
<code>Framework.Rules_Manager</code> as the key in the rules list to
dispatch to the corresponding registered operation, and as the rule
name used by the user on the command line to parameterize and use the
rule. The name of the rule must be given in upper-case (to allow for
case-independant recognition).
</p>
<p>Ex:
</p><div class="example">
<pre class="example">Rule_Id : <b>constant</b> Wide_String := &quot;PRAGMAS&quot;;
</pre></div>

<p>Note that from a language point of view, this declaration could be in
the body of the package; however, for identification purposes, it is
more convenient to put it in the specification.
</p>
<a name="Process-1"></a>
<h4 class="subsection">3.2.2 Process</h4>
<p>One (or more) procedure(s) may be necessary to process the rule
(collectively named the <code>Process</code> procedures in this
document). These procedures are called from <code>Framework.Plugs</code> at
appropriate places, and therefore must be declared in the
specification of the rule. See <a href="#Plugging_002din-a-new-rule-into-the-framework">Plugging-in a new rule into the framework</a>.
</p>
<p>Process procedures of a semantic rule take one parameter of type
<code>Asis.Element</code>. Although all element kinds are equivalent from
the point of view of Ada&rsquo;s type checking, it is recommended to follow
general ASIS practice, and to define the parameter with the ASIS
element kind expected by the procedure.
</p>
<p>Process procedures of a textual rule take two parameters: an input
line, and the corresponding location.
</p>
<p>Ex:
</p><div class="example">
<pre class="example">-- Semantic rule:
<b>procedure</b> Process_Pragma (Pragma_Element : <b>in</b> Asis.Pragma_Element);

-- Textual rule:
<b>procedure</b> Process_Line (Line : <b>in</b> Asis.Program_Text;
                        Loc  : <b>in</b> Framework.Location);
</pre></div>

<a name="Body"></a>
<h3 class="section">3.3 Body</h3>
<p>It is a good habit to start the body of a rule by giving a comment
explaining the general principles of the algorithm used, especially if
the algorithm is not trivial. To be honest, not all current rules do
provide this information, and some crucial information may be missing
in the rules that do... You are more than welcome to improve these
comments, especially if you think that some fundamental information
should have been provided here.
</p>
<p>The body must contain a <code>Help</code>, an <code>Add_Control</code>, and a
<code>Command</code> procedure. It may also optionnally contain a
<code>Prepare</code> and a <code>Finalize</code> procedure. These procedures are
call-backs that are registered to the framework by calling
<code>Framework.Rules_Manager.Register</code> in the statements part of the
body. Note that there is a parameter to this procedure that tells
whether the rule is semantic, textual, or both.  This procedure has
<b><code>null</code></b> defaults for the optional subprograms.
</p>
<a name="Help"></a>
<h4 class="subsection">3.3.1 Help</h4>
<p>Help is a procedure that displays a short help message to the standard
output for the rule. It takes no parameter.
</p>
<p>The procedure <code>Help</code> is called when the user specifies a &ldquo;-h&rdquo; option
for the rule. It must display a useful message by calling
<code>Utilities.User_Message</code>. In order to have a uniform presentation
for all rules, the message must be structured as follows:
</p>
<ul>
<li> The word &ldquo;Rule:&rdquo; followed by the rule ID.
</li><li> A short description of the purpose of the rule. This description can span
several lines, but don&rsquo;t make it too long.
</li><li> A blank line (call <code>Utilities.User_Message</code> without parameter).
</li><li> The word &ldquo;Parameter(s):&rdquo; followed by a description of parameters. Note that if
you have a parameter of an enumerated type, the package <code>Flag_Utilities</code>
features a <code>Help_On_Flag</code> procedure that formats automatically the values.

<p>If the different parameters have different meanings, you can use the
form  &ldquo;Parameter(1):&rdquo;, &ldquo;Parameter(2):&rdquo; etc. instead. If the rule
has no parameters, just say &ldquo;Parameters: none&rdquo;.
</p>
</li></ul>
<p>Note that the command:
</p><div class="example">
<pre class="example">adactl -h all
</pre></div>
<p>outputs the help messages for all rules, providing examples of how you
should write your own help messages.
</p>
<p>Ex:
</p><div class="example">
<pre class="example"><b>procedure</b> Help <b>is</b>
  <b>use</b> Utilities;
<b>begin</b>
  User_Message (&quot;Rule: &quot; &amp; Rule_Id);
  User_Message (&quot;Control usage of specific pragmas&quot;);
  User_Message;
  User_Message (&quot;Parameter(s): [multiple] all | nonstandard | &lt;pragma&gt;&quot;);
<b>end</b> Help;
</pre></div>

<a name="Add_005fControl"></a>
<h4 class="subsection">3.3.2 Add_Control</h4>
<p><code>Add_Control</code> is a procedure which is called by the rules parser
when it finds a control command that refers to the corresponding
rule. It is passed the corresponding label (an empty string if there
is no label), and the control&rsquo;s kind (<code>Check</code>, <code>Search</code> or
<code>Count</code>). It will typically loop over the parameters with the
various <code>Get_XXX_Parameters</code> from package <code>Rules.Language</code>
to process the parameters.
</p>
<p>If for some reason a parameter is not appropriate to the rule, the
rule should call <code>Rules.Language.Parameter_Error</code> with an
appropriate message. This procedure will raise the exception
<code>User_Error</code>, and the <code>Add_Control</code> procedure should not handle
it; the exception will be processed by the framework.
</p>
<p>Note that <code>Add_Control</code> may be called several times if the same rule
is activated with different parameters in a rules file. If a rule can
be specified only once, it is up to the rule to check this and call
<code>Parameter_Error</code> in case it is given more than once.
</p>
<p>Ex:
</p><div class="example">
<pre class="example"><b>procedure</b> Add_Control (Label    : <b>in</b> Label;
                   Ctl_Type : <b>in</b> Control_Kinds) <b>is</b>
<b>begin</b>
   <b>while</b> Parameter_Exists <b>loop</b>
      -- process parameter
   <b>end</b> <b>loop</b>;
<b>end</b> Add_Control;
</pre></div>
<p>There is no special requirement on the implementation of the <code>Add</code>
procedure. The programmer is free to interpret the parameters as
necessary and do whatever initialisation processing they
imply. Typically, for a rule that searches for the occurrence of an
identifier, this procedure would add the identifier to some internal
context table.
</p>
<a name="Command"></a>
<h4 class="subsection">3.3.3 Command</h4>
<p><code>Command</code> is a procedure used by the framework to send
&ldquo;commands&rdquo; to the rule in order to change its state. It has a
parameter of an enumeration type that can take the values
<code>Clear</code>, <code>Suspend</code>, and <code>Resume</code>.
</p>
<ul>
<li> <code>Clear</code>: <code>Command</code> is called with this value whenever a
&ldquo;clear&rdquo; command is given. The rule must reset the rule to the &ldquo;not
used&rdquo; state, and free any allocated data structure.
</li><li> <code>Suspend</code>: <code>Command</code> is called with this value whenever the
rule is inhibited. The rule must preserve its current &ldquo;used&rdquo; state,
and enter the &ldquo;not used&rdquo; state.
</li><li> <code>Resume</code>: <code>Command</code> is called with this value whenever the
rule is no more inhibited. The rule must restore its state from the
copy saved by the previous <code>Suspend</code>
</li></ul>

<p>This procedure is required, since it must at least deal with the
<code>Rule_Used</code> flag (see <a href="#Process">Process</a>). Note that it is guaranteed
that <code>Suspend</code>/<code>Resume</code> are properly paired, and that
<code>Suspend</code> is not called on an already suspended rule. Therefore,
a simple variable can be used to save the current state.
</p>
<p>Ex:
</p><div class="example">
<pre class="example"><b>procedure</b> Command (Action : Framework.Rules_Manager.Rule_Action) <b>is</b>
   <b>use</b> Framework.Rules_Manager;
<b>begin</b>
   <b>case</b> Action <b>is</b>
      <b>when</b> Clear =&gt;
         Rule_Used := False;
         -- Free internal data structures if necessary
      <b>when</b> Suspend =&gt;
         Save_Used := Rule_Used;
         Rule_Used := False;
      <b>when</b> Resume =&gt;
         Rule_Used := Save_Used;
   <b>end</b> <b>case</b>;
<b>end</b> Command;
</pre></div>

<a name="Prepare"></a><a name="Prepare-1"></a>
<h4 class="subsection">3.3.4 Prepare</h4>
<p><code>Prepare</code> is a procedure that performs some initialisations that
must be done after all controls refering to the rule have been parsed,
and before processing the units. It is optional (i.e. a
<code><b>null</b></code> pointer can be passed for it to the <code>Register</code>
procedure, or simply not mentionned since <code><b>null</b></code> is the
default).
</p>
<p>A typical use of <code>Prepare</code> is to balance the tree from a binary
map to improve efficiency.
</p>
<a name="Process"></a><a name="Process-2"></a>
<h4 class="subsection">3.3.5 Process</h4>
<p>There is no special requirement on the implementation of the
<code>Process</code> procedure(s). The programmer is free to do whatever is
necessary to the rule. It is possible to use ASIS query functions, or
any other service deemed appropriate.
</p>
<p>It is also possible to have several <code>Process</code> procedures (e.g. if
the programmer wants to do some processing when going down the ASIS
tree, and some other processing when going up).
</p>
<p>A <code>Process</code> procedure should return immediately if no
corresponding <code>Add_Control</code> has ever been called. In most cases, this
is conveniently done by having a <code>Rule_Used</code> global boolean
variable which is set to <code>True</code> in <code>Add_Control</code>, and checked at
the beginning of <code>Process</code>. For efficiency reasons, avoid doing
any call to the ASIS library before this check. This means that if you
need objects initialized with such calls, they should be declared in a
block <i>after</i> the test, rather than in the declarative part of the
<code>Process</code> procedure.
</p>
<p>After this test, the rule should immediately call
<code>Rules_Manager.Enter</code> (with the rule name as the parameter). In
case of a problem, this allows the system to report which rule failed.
</p>
<p>A special case arises for rules that follow the call graph. Such rules
may traverse elements outside the current unit, but should avoid
analyzing units to which an <code>inhibit all</code> applies (so-called
<i>banned</i> units). The framework features an <code>Is_Banned</code> function
that tells if an element should not be traversed due to it being
declared in a banned unit. See <code>Rules.Global_References</code> for an
example of this.
</p>
<a name="Finalize"></a>
<h4 class="subsection">3.3.6 Finalize</h4>
<p><code>Finalize</code> is called at the end of a &quot;Go&quot; command, after all
units have been processed. It is useful for rules that report on
global usage of entities, and therefore can report findings only at
the end. It is optionnal (i.e. a <code><b>null</b></code> pointer can be passed
for it to the <code>Register</code> procedure, or simply not mentionned
since <code><b>null</b></code> is the default).
</p>
<p>Ex:
</p><div class="example">
<pre class="example"><b>procedure</b> Finalize <b>is</b>
<b>begin</b>
   -- Report findings
<b>end</b> Finalize;
</pre></div>

<a name="Package-statements"></a>
<h4 class="subsection">3.3.7 Package statements</h4>
<p>The package body statements part should include a call to
<code>Framework.Rules_Manager.Register</code> in order to register
the rule and its associated <code>Help</code>, <code>Add_Control</code>,
<code>Command</code>, and optionally <code>Prepare</code> and <code>Finalize</code>,
procedures. Note that the second parameter of <code>Register</code> tells
whether it is a semantic, textual, or semantic_textual rule.
</p>
<p>Ex:
</p><div class="example">
<pre class="example"><b>begin</b>
   Framework.Rules_Manager.Register (Rule_Id,
                                     Rules_Manager.Semantic,
                                     Help        =&gt; Help'Access,
                                     Add_Control =&gt; Add_Control'Access,
                                     Command     =&gt; Command'Access,
                                     Prepare     =&gt; Prepare'Access);
<b>end</b> Rules.Pragmas;
</pre></div>

<a name="Programming-rules-and-tips"></a>
<h3 class="section">3.4 Programming rules and tips</h3>
<a name="style"></a>
<h4 class="subsection">3.4.1 style</h4>
<p>We try to maintain a consistent style in AdaControl, therefore the code you write should
match the style of the rest of the program. Have a look at other rules, and run <code>src/verif.aru</code>
on your code. In addition, please note the following:
</p><ul>
<li> The <code><b>use</b></code> clause is allowed, but its scope should be
restricted to the innermost declarative region where it is useful. Use
a <code><b>use</b></code> clause for ASIS units, and another one for other
units.  Sort units alphabetically in the clause.
</li><li> The only output of a rule should be by calling
<code>Report</code>. Especially, no rule should use <code>Wide_Text_IO</code>
directly.
</li><li> If your rule encounters a dynamic construct that prevents normal checking,
call <code>Framework.Reports.Uncheckable</code> to warn the user.
</li><li> The framework should be sufficient for all your needs. If you have a
special need that you think cannot be satisfied by the current
framework, get in touch with us and we&rsquo;ll discuss it.
</li></ul>

<a name="Things-to-care-about"></a>
<h4 class="subsection">3.4.2 Things to care about</h4>
<p>Each time you want the name of something, remember that the name may
be given in selected notation. In most cases, you should call
<code>Thick_Queries.Simple_Name</code> on the result of any query that
returns a name to get rid of the possible selectors. Otherwise, you
should inspect the returned expression to see if its
<code>Expression_Kind</code> is <code>A_Selected_Component</code>, and take the
<code>Selector</code> if it is.
</p>
<p>When designing a rule, consider the implications of renamings and
generics.
</p>
<p>If you want to output the Element_Image of some element, beware that
it will be preceded by spaces. Do not use
<code>Ada.Strings.Wide_Fixed.Trim</code> to eliminate them, since it
wont remove tab characters. Use <code>Utilities.trim_all</code>, which will
do the right thing.
</p>
<a name="Using-ASIS-efficiently_002e"></a>
<h4 class="subsection">3.4.3 Using ASIS efficiently.</h4>
<p>Remember that ASIS queries can be costly. Declare local variables (or
constants) rather than evaluating several times the same query.
</p>
<p>There are issues with some ASIS queries. The rule whose label is
&ldquo;Avoid_Query&rdquo; in <code>verif.aru</code> will remind you if you use one of
these queries.
</p><dl compact="compact">
<dt>Asis.Definitions.Subtype_Mark</dt>
<dd><p>There might be confusion with <code>Asis.Subtype_Mark</code>; moreover, you
normally want to get rid of selected components (see above).  Use
<code>Thick_Queries.Subtype_Simple_Name</code> instead.
</p>
</dd>
<dt>Asis.Definitions.Corresponding_Root_Type</dt>
<dd><p>This query return a <code>Nil_Element</code> if any type in the derivation
chain is a <code>'Base</code> attribute (to be honnest, versions of ASIS
before the latest 5.05 will loop indefinitely in this case). Use
<code>Thick_Queries.Corresponding_Root_Type_Name</code> instead, and consider what
you want to do if there is a <code>'Base</code> in the derivation chain.
</p>
</dd>
<dt>Asis.Definitions.Corresponding_Parent_Subtype</dt>
<dd><p>This query suffers from the same problem as
<code>Corresponding_Root_Type</code>. Don&rsquo;t use it, rather take
the <code>Subtype_Simple_name</code> of the <code>Parent_Subtype_Indication</code>,
and do your own analysis, depending on whether the returned
<code>Expression_Kind</code> is <code>An_Attribute_Reference</code> or not.
</p></dd>
</dl>

<hr>
<a name="Plugging_002din-a-new-rule-into-the-framework"></a>
<div class="header">
<p>
Next: <a href="#Testing-and-debugging-a-rule" accesskey="n" rel="next">Testing and debugging a rule</a>, Previous: <a href="#Writing-a-new-rule" accesskey="p" rel="prev">Writing a new rule</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; </p>
</div>
<a name="Plugging_002din-a-new-rule-into-the-framework-1"></a>
<h2 class="chapter">4 Plugging-in a new rule into the framework</h2>

<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Normal-case" accesskey="1">Normal case</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Specific-rules" accesskey="2">Specific rules</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#User-documentation" accesskey="3">User documentation</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<hr>
<a name="Normal-case"></a>
<div class="header">
<p>
Next: <a href="#Specific-rules" accesskey="n" rel="next">Specific rules</a>, Previous: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="p" rel="prev">Plugging-in a new rule into the framework</a>, Up: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="u" rel="up">Plugging-in a new rule into the framework</a> &nbsp; </p>
</div>
<a name="Normal-case-1"></a>
<h3 class="section">4.1 Normal case</h3>
<p>Adding a new rule to the tool requires only simple modifications to
the package <code>Framework.Plugs</code>.
</p>
<p>The package <code>Framework.Plugs</code> contains several procedures that
are called during the traversal of the code under the following
circumstances:
</p><ul>
<li> <code>Enter_Unit</code>: Called when entering a compilation unit, before any
other processing.
</li><li> <code>Exit_Unit</code>: Called when leaving a compilation unit, after any
other processing.
</li><li> <code>Enter_Scope</code>: Called when entering a new scope (i.e. a construct
that can contain declarations).
</li><li> <code>Exit_Scope</code>: Called when leaving a scope.
</li><li> <code>Pre_Procedure</code>: Called when entering a syntax node (this is like
the usual <code>Pre_Procedure</code> used in the instantiation of
<code>ASIS.Iterator.Traverse_Element</code>, except that there is no
<code>State_Information</code> and no <code>Control</code>).
</li><li> <code>Post_Procedure</code>: Called when leaving a syntax node.
</li><li> <code>True_Identifier</code>: Called when entering an <code>An_Identifier</code>,
<code>An_Operator_Symbol</code>, or <code>An_Enumeration_Literal</code> node that
corresponds to a real identifier, i.e. not to a pragma name or other
forms of irrelevant names. This avoids special cases in rules dealing
with identifiers.
</li><li> <code>Text_Analysis</code>: Called on every source line of the code.
</li></ul>

<p>These procedures have the usual &quot;big case&quot; structure of an ASIS
application (i.e. a first level case statement on <code>Element_Kind</code>,
with each case alternative containing other case statements to further
refine the kind of node that is being dealt with).
</p>
<p>The following modifications must be done to the body of this package:
</p>
<ol>
<li> Add a with clause naming the rule package:

<p>Ex:
</p><div class="example">
<pre class="example"><b>with</b> Rules.Pragmas;
</pre></div>

</li><li> Add calls to the rule&rsquo;s <code>Process</code> procedure(s) at the appropriate
place(s) in the body of the provided procedures. For textual rules,
<code>Text_Analysis</code> is the only appropriate place.

<p>Ex:
</p><div class="example">
<pre class="example"><b>procedure</b> Pre_Procedure (Element : <b>in</b> Asis.Element) is
   <b>use</b> Asis;
   <b>use</b> Asis.Elements;
<b>begin</b>
   <b>case</b> Element_Kind (Element) <b>is</b>
      <b>when</b> A_Pragma =&gt;
         Rules.Pragmas.Process_Pragma (Element);
       ...
<b>end</b> Pre_Procedure;
</pre></div>
</li></ol>

<p>Many alternatives of the big case statement cover a number of
values. It may happen that a new rule requires calling its
<code>Process</code> procedure for some, but not all of these values. In
this case, the case alternative must be split. This is not a problem,
but do not forget to duplicate the statements from the original
alternative before adding the new calls, to make sure that the split
does not break existing rules.
</p>
<p>It is always possible to plug a <code>Process</code> procedure in
<code>Pre_Procedure</code> or in <code>Post_Procedure</code>. However, some
&ldquo;natural&rdquo; places for plugging rules correspond to many branches of
the big case statement. For example, there are many places where you
enter a scope. That&rsquo;s why the package <code>Framework.Plugs</code> includes
other procedures that are called in &ldquo;interesting&rdquo; contexts. If
appropriate, it is better practice to plug calls to <code>Process</code>
procedures here, rather than all over the place in various
alternatives of the big case statement.
</p>
<hr>
<a name="Specific-rules"></a>
<div class="header">
<p>
Next: <a href="#User-documentation" accesskey="n" rel="next">User documentation</a>, Previous: <a href="#Normal-case" accesskey="p" rel="prev">Normal case</a>, Up: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="u" rel="up">Plugging-in a new rule into the framework</a> &nbsp; </p>
</div>
<a name="Specific-rules-1"></a>
<h3 class="section">4.2 Specific rules</h3>
<p>In some cases, you may want to keep your rules separate from the
general purpose ones. This may happen if you have developped some very
specific rules that take the structure of your project into account,
and hence would not be of interest to anybody else. Or it may be that
your local lawyer does not allow you to publish your rules as free
software.
</p>
<p>This should not prevent you from using AdaControl. Just write the
rules as usual, but instead of plugging them in
<code>Framework.Plugs</code>, use the package
<code>Framework.Specific_Plugs</code> instead. This package has subprograms
identical to those described above for plugging-in rules, and they are
called in the same contexts. But it is guaranteed that no rule from
the public release of AdaControl will ever be plugged-in into this
package. This way, you can keep your rules separate from the public
ones, and you can upgrade to a new version of AdaControl without
needing to merge the modifications for your rules.
</p>
<p>If you have specific rules plugged into
<code>Framework.Specific_Plugs</code>, change the constant
<code>Specific_Version</code> in the specification of the package to
something that identifies the specific version (like your company&rsquo;s
name for example). This way, the version number of AdaControl will
show that it is a specific version.
</p>
<hr>
<a name="User-documentation"></a>
<div class="header">
<p>
Previous: <a href="#Specific-rules" accesskey="p" rel="prev">Specific rules</a>, Up: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="u" rel="up">Plugging-in a new rule into the framework</a> &nbsp; </p>
</div>
<a name="User-documentation-1"></a>
<h3 class="section">4.3 User documentation</h3>
<p>Of course, you should update the user&rsquo;s guide with the information
about your rules.  This guide is written in Texinfo, see
<a href="http://www.gnu.org/software/texinfo/">http://www.gnu.org/software/texinfo/</a>. Note however that you
don&rsquo;t need to understand all the possibilities of Texinfo to update
the manual; look at the description of other rules, the few commands
you need will be quite straightforward to understand.
</p>
<hr>
<a name="Testing-and-debugging-a-rule"></a>
<div class="header">
<p>
Previous: <a href="#Plugging_002din-a-new-rule-into-the-framework" accesskey="p" rel="prev">Plugging-in a new rule into the framework</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; </p>
</div>
<a name="Testing-and-debugging-a-rule-1"></a>
<h2 class="chapter">5 Testing and debugging a rule</h2>

<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">&bull; <a href="#Testing" accesskey="1">Testing</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Debugging-aids" accesskey="2">Debugging aids</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">&bull; <a href="#Integrating-the-test-in-the-test-suite" accesskey="3">Integrating the test in the test suite</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<hr>
<a name="Testing"></a>
<div class="header">
<p>
Next: <a href="#Debugging-aids" accesskey="n" rel="next">Debugging aids</a>, Previous: <a href="#Testing-and-debugging-a-rule" accesskey="p" rel="prev">Testing and debugging a rule</a>, Up: <a href="#Testing-and-debugging-a-rule" accesskey="u" rel="up">Testing and debugging a rule</a> &nbsp; </p>
</div>
<a name="Testing-1"></a>
<h3 class="section">5.1 Testing</h3>
<p>Once the rule is written, you will test it. Of course, you&rsquo;ll first
write a small test case to make sure that it works as expected. But
that&rsquo;s not enough.
</p>
<p>Our experience with existing rules has shown that getting the rule 90%
right is quite easy, but the last 10% can be tricky. Ada offers
constructs that you often didn&rsquo;t think about when writing the rule;
for example, if you are expecting a name at some place, did you take
care of selected names (we got trapped by this one several times)?
Therefore, it is extremely important that you check your rule against
as much code as you can, the minimum being the code of AdaControl itself.
</p>
<p>Note that if your rule encountered some uncheckable cases, you should
add a child for your rule to the test <code>t_uncheckable</code>, and also
modify the <code>t_uncheckable.aru</code> file accordingly. Look at how it
is done currently, and do the same.
</p>
<hr>
<a name="Debugging-aids"></a>
<div class="header">
<p>
Next: <a href="#Integrating-the-test-in-the-test-suite" accesskey="n" rel="next">Integrating the test in the test suite</a>, Previous: <a href="#Testing" accesskey="p" rel="prev">Testing</a>, Up: <a href="#Testing-and-debugging-a-rule" accesskey="u" rel="up">Testing and debugging a rule</a> &nbsp; </p>
</div>
<a name="Debugging-aids-1"></a>
<h3 class="section">5.2 Debugging aids</h3>
<p>As mentionned above, it is often the case when writing a new rule, as
well as with any kind of ASIS programming, that one comes across
unexpected contexts. This is due to the rich features of Ada, but it
is sometimes difficult to understand what is happenning.
</p>
<p>The framework provides some facilities that help in debugging. Don&rsquo;t
hesitate to use the <code>Trace</code> and <code>Assert</code>
utilities. See <a href="#The-package-Utilities">The package Utilities</a>. Note that the <code>Trace</code>
procedures may be given an element (or an element list) whose basic
characteritics are printed. If the <code>With_Source</code> parameter is
<code>True</code>, the source correponding to the element is also printed.
</p>
<p>In the case where AdaControls enters an endless loop, the first thing
to do is to determine the place where the loop is happening. To ease
this, AdaControl may be compiled in &ldquo;interruptible&rdquo; mode. In normal
mode, the package <code>Framework.Interrupt</code> is a renaming of
<code>Framework.Interrupt_Std</code>, a dummy package that does
nothing. Edit  <code>Framework.Interrupt</code> to make it a renaming of
<code>Framework.Interrupt_Dbg</code> (instructions provided in the package)
and recompile.
</p>
<p>Now, when you hit Ctrl-C while AdaControl is running with the &ldquo;-d&rdquo;
option, execution of the current &ldquo;go&rdquo; command is interrupted with a
message telling which rule is active, and on which compilation
unit. If the &ldquo;-x&rdquo; option is also given, the whole execution is
stopped.
</p>
<p>Of course, when you are done, reestablish the normal package by doing the
inverse manipulation. The reason we didn&rsquo;t put the debug version in the
regular version is that it drags in the whole tasking run-time, with a
measurable impact on efficiency (we measured 18% extra time for
running AdaControl on the ACATS).
</p>
<p>In addition, a small stand-alone utility called <code>ptree</code> is
provided. It prints the logical nesting of ASIS elements for a
unit. The syntax of Ptree is:
</p><div class="example">
<pre class="example">ptree [-sS] [-p &lt;project_file&gt;] &lt;unit&gt;[:&lt;span&gt;] -- &lt;ASIS_Options&gt;
&lt;span&gt; ::=   &lt;line_number&gt;
           | [&lt;first_line&gt;]-[&lt;last_line&gt;]
           | &lt;line_number&gt;:&lt;column_number&gt;
</pre></div>
<p>If the &ldquo;-s&rdquo; option is given, <code>ptree</code> processes the
specification of the unit, otherwise it processes the body. If the
&ldquo;-S&rdquo; option is given, the span of each element is also printed. The
&ldquo;-p&rdquo; option has the same meaning as in AdaControl itself. ASIS
options can be passed, like for AdaControl, after a &ldquo;-<!-- /@w -->-&rdquo; (but
-FS is the default).
</p>
<p>The &lt;unit&gt; is given either as an Ada unit, or as a file name, provided
the extension is &ldquo;.ads&rdquo; or &ldquo;.adb&rdquo; (as in AdaControl). If a span is
mentionned behind the unit name, only the constructs that cover the
indicated span are output. The syntax of the span is the same used
by pfni. This is useful if you are interested in just one particular
structure in a big unit.
</p>
<p>If you come across a situation where you don&rsquo;t understand the logical
nesting of elements, try to reduce it to a very simple example, then
run <code>ptree</code> on it. It can be quite instructive!
</p>
<p>Of course, a more elaborated, but less convenient solution is to use
Asistant. Please refer to your ASIS documentation to learn how to use
Asistant.
</p>
<p>Finally, if you come to suspect that you get a strange result from an
ASIS provided operation, check whether there is an equivalent
operation in the package <code>A4G_Bugs</code>, and if yes, use it
instead. See <a href="#The-package-A4G_005fBugs">The package A4G_Bugs</a>.
</p>
<hr>
<a name="Integrating-the-test-in-the-test-suite"></a>
<div class="header">
<p>
Previous: <a href="#Debugging-aids" accesskey="p" rel="prev">Debugging aids</a>, Up: <a href="#Testing-and-debugging-a-rule" accesskey="u" rel="up">Testing and debugging a rule</a> &nbsp; </p>
</div>
<a name="Integrating-the-test-in-the-test-suite-1"></a>
<h3 class="section">5.3 Integrating the test in the test suite</h3>
<p>When your rule has been carefully tested and is ready for integration,
run the rule file <code>src/verif.aru</code> on every unit that you have
written or changed. This will control that you match the programming
rules for AdaControl. There can be some &ldquo;found&rdquo; messages (try to
minimize them if possible), but there should be no &ldquo;Error&rdquo;
message. Then, the last thing you have to do is to write a test for
non-regression verification purpose. Don&rsquo;t forget to include examples
of the tricky cases in the test.
</p>
<p>Go to the <code>test</code> directory. You&rsquo;ll notice that all test programs
have a name of the form <code>t_name.adb</code> (or in some rare cases,
<code>ts_name.adb</code>). The <code>name</code> is the rule name. You&rsquo;ll notice
also that some units have a name like <code>tfw_name.adb</code>; these are
tests for the framework, you should normally ignore them. Name your
test file according to this convention, normally using <code>t_</code>,
unless the test requires some weird parameters that prevent it from
being run normally, in which case it should use <code>ts_</code> (&ldquo;s&rdquo;
stands for special). It is OK for your test to have child units (whose
names will be dictated by the Gnat naming convention). If your test
requires other units, name them like <code>x_name</code> or
<code>x_name_complement</code>. Then, go to the <code>test/conf</code> directory,
and put your rule file under the name <code>t_name.aru</code> (with the same
<code>name</code> of course).
</p>
<p>Go back to the <code>test</code> directory, and run <code>test.sh</code>. All
tests should report PASSED, except the <code>tfw_help</code> and
<code>tfw_check</code> tests. Your test will not be reported, because its
expected output is not yet in the directory <code>test/ref</code>; test
<code>tfw_help</code> will report FAILED because this test prints all help
messages, and that the help message for your rule has been added; test
<code>tfw_check</code> will report FAILED because there is now one extra
message (from the extra rule file) saying &ldquo;No error found&rdquo;.
</p>
<p>Check that the result of your test is OK (in the file
<code>test/res/t_name.txt</code>), and copy this file to the directory
<code>test/ref/</code>. Do the following command:
</p><div class="example">
<pre class="example">diff test/ref/tfw_help.txt test/res/tfw_help.txt
</pre></div>
<p>and check that the only difference is the addition of the help message
from your rule.
</p>
<p>Do the following command:
</p><div class="example">
<pre class="example">diff test/ref/tfw_check.txt test/res/tfw_check.txt
</pre></div>
<p>and check that the only difference is the addition of one &ldquo;No error
found&rdquo; message.
</p>
<p>Then copy <code>test/res/tfw_help.txt</code> and
<code>test/res/tfw_check.txt</code> to the directory <code>test/ref/</code>. Run
<code>test.sh</code> again: it should print PASSED for all tests, including
yours. Pay special attention to the last test, called
<code>tfw_stress</code>. This test runs all rules against all test units. If
it fails, the file <code>res/tfw_stress.txt</code> contains the whole
listing of the run (with <code>-dv</code> options), so you&rsquo;ll find all the
context of the problem.
</p>
<p>In case of problems, note that options can be passed to
<code>test.sh</code>; check the comments at the top of the file for details.
</p>
<p>When everything is OK, all you have to do is send your modifications
(including the tests) to
<a href="mailto::rosen@adalog.fr">rosen@adalog.fr</a>, for inclusion in
the next release of AdaControl!
</p><hr>



</body>
</html>