1
------------------------------------------------------------------------------
3
-- ASIS TUTORIAL COMPONENTS --
5
-- A C T U A L S _ F O R _ T R A V E R S I N G . P R E _ O P --
9
-- Copyright (c) 2000, Free Software Foundation, Inc. --
11
-- ASIS Application Templates are free software; you can redistribute it --
12
-- and/or modify it under terms of the GNU General Public License as --
13
-- published by the Free Software Foundation; either version 2, or (at your --
14
-- option) any later version. ASIS Application Templates are distributed in --
15
-- the hope that they will be useful, but WITHOUT ANY WARRANTY; without --
16
-- even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR --
17
-- PURPOSE. See the GNU General Public License for more details. You should --
18
-- have received a copy of the GNU General Public License distributed with --
19
-- distributed with GNAT; see file COPYING. If not, write to the Free --
20
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, --
23
-- ASIS Tutorial was developed and are now maintained by Ada Core --
24
-- Technologies Inc (http://www.gnat.com). --
26
------------------------------------------------------------------------------
28
-- This is the body of Pre_Op to be used as an example of the style
29
-- checker solution (Task 2) built on top of the ASIS Application Templates
30
-- provided in ASIS-for-GNAT. This file is supposed to replace the file with
31
-- the same name which is a part of the ASIS Application Templates
33
-- This Ada unit is obtained as an "extension" of the code which is the
34
-- solution for Task 1
36
with Ada.Wide_Text_IO;
37
with Ada.Characters.Handling;
42
with Asis.Implementation;
44
with Asis.Declarations;
45
with Asis.Expressions;
47
with Style_Checker_Utilities;
49
separate (Actuals_For_Traversing)
51
(Element : Asis.Element;
52
Control : in out Asis.Traverse_Control;
53
State : in out Traversal_State)
55
Argument_Kind : Asis.Element_Kinds;
56
Argument_Declaration_Kind : Asis.Declaration_Kinds;
58
Argument_Association_Kind : Asis.Association_Kinds;
62
-- Note, that the code below may be rewritten in more compact way (with
63
-- the same functionality). But we prefer to go step-by-step,
64
-- demonstrating the important ASIS queries
66
Argument_Kind := Asis.Elements.Element_Kind (Element);
70
when Asis.An_Association =>
71
-- The first rule added by Task 1 is about generic associations,
72
-- so we have to add one more alternative to the external case
73
-- statement - for An_Association Element_Kinds value.
75
-- Inside this alternative you first have to define the exact
78
Argument_Association_Kind := Asis.Elements.Association_Kind (Element);
80
-- and for A_Generic_Association Element:
82
case Argument_Association_Kind is
84
when Asis.A_Generic_Association =>
85
-- you have to check that they are in named form.
86
-- In ASIS terms this means, that the result of
87
-- Asis.Expressions.Formal_Parameter query applied
88
-- to the association Element is not Nil
90
if Asis.Elements.Is_Nil
91
(Asis.Expressions.Formal_Parameter (Element))
93
Style_Checker_Utilities.Report_Style_Violation
94
(The_Element => Element,
95
Diagnosis => "Positional generic association");
99
-- Nothing to do with other association kinds, so
103
when Asis.A_Declaration =>
105
-- The second rule added by Task 2 is about declarations in general.
106
-- Actually, it have to be checked only for declarations which can
107
-- define more then one entity (such as object declarations and
108
-- parameter declarations), and this rule is always true for other
109
-- declarations (such as package declarations, type declarations
110
-- etc.) But to simplify the code needed to check this rule, we may
111
-- check it for all declaration kinds. The check itself is very
112
-- simple - we have to get the list of the names defined by a
113
-- given declaration (see the query Asis.Declarations.Names) and
114
-- check how many they are.
116
if Asis.Declarations.Names (Element)'Length >= 2 then
117
Style_Checker_Utilities.Report_Style_Violation
118
(The_Element => Element,
119
Diagnosis => "Declaration with more then one name");
122
-- The following check came from Task 1
123
-- The rule to check is about a specific kinds of declarations
124
-- only - we have to check that each subprogram body has a separate
125
-- spec. So we have first to define a more specific declaration
126
-- kind of the argument Element and then we have to check our rule
127
-- for subprogram bodies only
129
Argument_Declaration_Kind := Asis.Elements.Declaration_Kind (Element);
131
case Argument_Declaration_Kind is
133
when Asis.A_Procedure_Body_Declaration |
134
Asis.A_Function_Body_Declaration =>
136
if Asis.Elements.Is_Nil
137
(Asis.Declarations.Corresponding_Declaration (Element))
139
Style_Checker_Utilities.Report_Style_Violation
140
(The_Element => Element,
141
Diagnosis => "Subprogram body with no explicit spec");
145
-- For the other declaration kinds we have nothing to check,
151
-- Our the only rule for Task 1 is about declarations, so if
152
-- we have something which is not A_Declaration, we have nothing
159
when Ex : Asis.Exceptions.ASIS_Inappropriate_Context |
160
Asis.Exceptions.ASIS_Inappropriate_Container |
161
Asis.Exceptions.ASIS_Inappropriate_Compilation_Unit |
162
Asis.Exceptions.ASIS_Inappropriate_Element |
163
Asis.Exceptions.ASIS_Inappropriate_Line |
164
Asis.Exceptions.ASIS_Inappropriate_Line_Number |
165
Asis.Exceptions.ASIS_Failed =>
167
Ada.Wide_Text_IO.Put ("Pre_Op : ASIS exception (");
169
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
170
Ada.Exceptions.Exception_Name (Ex)));
172
Ada.Wide_Text_IO.Put (") is raised");
173
Ada.Wide_Text_IO.New_Line;
175
Ada.Wide_Text_IO.Put ("ASIS Error Status is ");
178
(Asis.Errors.Error_Kinds'Wide_Image (Asis.Implementation.Status));
180
Ada.Wide_Text_IO.New_Line;
182
Ada.Wide_Text_IO.Put ("ASIS Diagnosis is ");
183
Ada.Wide_Text_IO.New_Line;
184
Ada.Wide_Text_IO.Put (Asis.Implementation.Diagnosis);
185
Ada.Wide_Text_IO.New_Line;
187
Asis.Implementation.Set_Status;
191
Ada.Wide_Text_IO.Put ("Pre_Op : ");
193
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
194
Ada.Exceptions.Exception_Name (Ex)));
196
Ada.Wide_Text_IO.Put (" is raised (");
198
Ada.Wide_Text_IO.Put (Ada.Characters.Handling.To_Wide_String (
199
Ada.Exceptions.Exception_Information (Ex)));
201
Ada.Wide_Text_IO.Put (")");
202
Ada.Wide_Text_IO.New_Line;
b'\\ No newline at end of file'