ocarina-me_real-tokens.adb 11.2 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--               O C A R I N A . M E _ R E A L . T O K E N S                --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
jhugues's avatar
jhugues committed
9
--       Copyright (C) 2009 Telecom ParisTech, 2010-2012 ESA & ISAE.        --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--                                                                          --
-- Ocarina  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. Ocarina 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 Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  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.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29
30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
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
--                                                                          --
------------------------------------------------------------------------------

with Namet;
with Utils;

package body Ocarina.ME_REAL.Tokens is
   use Namet;

   procedure New_Token
     (Token : Token_Type;
      Image : String);
   --  Compute token image and store it in Token_Image table. When
   --  Token is a graphical character, embrace its image between
   --  single quotes ('<<' and '>>' are considered as graphical
   --  characters). When Token is a keyword, embrace its image between
   --  double quotes. Enter the lower-case form of a keyword image
   --  into the name table and set name table byte to its token
   --  position in order to resolve it easily.

   -----------------
   -- Init_Tokens --
   -----------------

   procedure Init_Tokens is
   begin
      --  Enter all the alphabetic keywords in the name table

      New_Token (T_Check, "check");
      New_Token (T_End, "end");
      New_Token (T_Foreach, "foreach");
      New_Token (T_In, "in");
      New_Token (T_Theorem, "theorem");
      New_Token (T_Sothat, "|");
      New_Token (T_Return, "return");
      New_Token (T_Var, "var");
      New_Token (T_If, "if");
      New_Token (T_Then, "then");
      New_Token (T_Else, "else");
      New_Token (T_Global, "global");
      New_Token (T_Compute, "compute");
      New_Token (T_Requires, "requires");
      New_Token (T_Do, "do");

      New_Token (T_Error, "<error>");
      New_Token (T_Affect, ":=");
      New_Token (T_And, "and");
      New_Token (T_Or, "or");
      New_Token (T_Not, "not");
      New_Token (T_False, "FALSE");
      New_Token (T_True, "TRUE");
      New_Token (T_Wstring, "wstring");
      New_Token (T_Semi_Colon, ";");
      New_Token (T_Left_Brace, "{");
      New_Token (T_Right_Brace, "}");
      New_Token (T_Colon, ":");
      New_Token (T_Comma, ",");
      New_Token (T_Colon_Colon, "'::'");
      New_Token (T_Left_Paren, "(");
      New_Token (T_Right_Paren, ")");
      New_Token (T_Equal, "=");
      New_Token (T_Plus, "+");
      New_Token (T_Modulo, "mod");
      New_Token (T_Star, "*");
      New_Token (T_Slash, "/");
      New_Token (T_Power, "**");
      New_Token (T_Minus, "-");
      New_Token (T_Less_Equal, "<=");
      New_Token (T_Greater_Equal, ">=");
      New_Token (T_Less, "<");
      New_Token (T_Different, "<>");
      New_Token (T_Greater, ">");
      New_Token (T_Left_Bracket, "[");
      New_Token (T_Right_Bracket, "]");
      New_Token (T_Anonymous_Set, "Anonymous_Set");

      New_Token (T_Integer_Literal, "<int literal>");
      New_Token (T_Fixed_Point_Literal, "<fixed point literal>");
      New_Token (T_Floating_Point_Literal, "<floating point literal>");
      New_Token (T_Character_Literal, "<character literal>");
      New_Token (T_Wide_Character_Literal, "<wide character literal>");
      New_Token (T_String_Literal, "<string literal>");
      New_Token (T_Wide_String_Literal, "<wide string literal>");
      New_Token (T_Identifier, "<identifier>");
      New_Token (T_Pragma, "<pragma>");

      New_Token (T_Processor_Set, "Processor_Set");
      New_Token (T_Virtual_Processor_Set, "Virtual_Processor_Set");
      New_Token (T_Process_Set, "Process_Set");
      New_Token (T_Thread_Set, "Thread_Set");
      New_Token (T_Threadgroup_Set, "Threadgroup_Set");
      New_Token (T_Subprogram_Call_Set, "Subprogram_Call_Set");
      New_Token (T_Sequence_Call_Set, "Sequence_Call_Set");
      New_Token (T_Subprogram_Set, "Subprogram_Set");
      New_Token (T_Data_Set, "Data_Set");
      New_Token (T_Memory_Set, "Memory_Set");
      New_Token (T_Bus_Set, "Bus_Set");
      New_Token (T_Virtual_Bus_Set, "Virtual_Bus_Set");
      New_Token (T_End_To_End_Flows_Set, "End_To_End_Flows_Set");
      New_Token (T_Connection_Set, "Connection_Set");
      New_Token (T_Device_Set, "Device_Set");
      New_Token (T_System_Set, "System_Set");
133
      New_Token (T_Abstract_Set, "Abstract_Set");
134
      New_Token (T_Root_System_Set, "Root_System_Set");
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
      New_Token (T_Unknown_Set, "Unknown_Set");
      New_Token (T_Local_Set, "Local");

      New_Token (T_Is_Subcomponent_Of, "Is_Subcomponent_Of");
      New_Token (T_Is_Bound_To, "Is_Bound_To");
      New_Token (T_Is_Connected_To, "Is_Connected_To");
      New_Token (T_Is_Called_By, "Is_Called_By");
      New_Token (T_Is_Calling, "Is_Calling");
      New_Token (T_Is_Accessed_By, "Is_Accessed_By");
      New_Token (T_Is_Accessing_To, "Is_Accessing_To");
      New_Token (T_Is_Passing_Through, "Is_Passing_Through");
      New_Token (T_Is_Predecessor_Of, "Is_Predecessor_Of");
      New_Token (T_Is_Provided_Class, "Is_Provided_Class");
      New_Token (T_Is_Connecting_To, "Is_Connecting_To");

      New_Token (T_Get_Property_Value, "Get_Property_Value");
      New_Token (T_Get_Property_Value, "Property");
      New_Token (T_Get_System_Property_Value, "Get_System_Property_Value");
      New_Token (T_Get_System_Property_Value, "System_Property");
      New_Token (T_Cardinal, "Cardinal");
      New_Token (T_First, "First");
      New_Token (T_Last, "Last");
      New_Token (T_Head, "Head");
      New_Token (T_Queue, "Queue");
      New_Token (T_Property_Exists, "Property_Exists");
      New_Token (T_Property_Exists, "Exists");
      New_Token (T_Expr, "Expr");
      New_Token (T_Size, "Size");
      New_Token (T_Integer, "Integer");
      New_Token (T_Integer, "Int");
      New_Token (T_List, "List");
      New_Token (T_Float, "Float");
      New_Token (T_Max, "Max");
168
169
      New_Token (T_Ceil, "ceil");
      New_Token (T_Floor, "floor");
170
171
172
173
174
175
176
177
178
179
      New_Token (T_Cos, "cos");
      New_Token (T_Sin, "sin");
      New_Token (T_Tan, "tan");
      New_Token (T_Cosh, "cosh");
      New_Token (T_Sinh, "sinh");
      New_Token (T_Tanh, "tanh");
      New_Token (T_Ln, "ln");
      New_Token (T_Exp, "exp");
      New_Token (T_Sqrt, "sqrt");

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
      New_Token (T_LCM, "LCM");
      New_Token (T_GCD, "GCD");
      New_Token (T_Non_Null, "Non_Null");
      New_Token (T_Is_In, "Is_In");
      New_Token (T_Min, "Min");
      New_Token (T_All_Equals, "All_Equals");
      New_Token (T_Product, "Product");
      New_Token (T_Sum, "Sum");

      New_Token (T_MMax, "MMax");
      New_Token (T_MProduct, "MProduct");
      New_Token (T_MMin, "MMin");
      New_Token (T_MAll_Equals, "MAll_Equals");
      New_Token (T_MSum, "MSum");

      New_Token (T_EOF, "**}");

   end Init_Tokens;

   -----------
   -- Image --
   -----------

   function Image (T : Token_Type) return String is
      S : constant String := Get_Name_String (Token_Image (T));
   begin
      return S (S'First + Prefix'Length .. S'Last);
   end Image;

   ------------------
   -- Quoted_Image --
   ------------------

   function Quoted_Image (T : Token_Type) return String is
   begin
      case T is
         when T_Identifier
           | T_Integer_Literal | T_String_Literal |
           T_Fixed_Point_Literal | T_Floating_Point_Literal =>
            return Image (T);

         when others =>
            return "'" & Image (T) & "'";
      end case;
   end Quoted_Image;

   ----------------
   -- Is_Literal --
   ----------------

   function Is_Literal (T : Token_Type) return Boolean is
   begin
      return T in Literal_Type;
   end Is_Literal;

   -----------------
   -- Is_Operator --
   -----------------

   function Is_Operator (T : Token_Type) return Boolean is
   begin
      return T in Operator_Type;
   end Is_Operator;

   -----------------------
   -- Is_Predefined_Set --
   -----------------------

   function Is_Predefined_Set (T : Token_Type) return Boolean is
   begin
      return T in Predefined_Sets;
   end Is_Predefined_Set;

   ---------------------
   -- Is_Set_Operator --
   ---------------------

   function Is_Set_Operator (T : Token_Type) return Boolean is
   begin

      return (T = T_Plus or else T = T_Star or else T = T_Minus);
   end Is_Set_Operator;

   -------------------------
   -- Is_Boolean_Operator --
   -------------------------

   function Is_Boolean_Operator (T : Token_Type) return Boolean is
   begin
      return T in Boolean_Operator_Type or else
        T = T_Not;
   end Is_Boolean_Operator;

   --------------------
   -- Is_Scoped_Name --
   --------------------

   function Is_Scoped_Name (T : Token_Type) return Boolean is
   begin
      return T = T_Identifier or else T = T_Colon_Colon;
   end Is_Scoped_Name;

   ---------------
   -- New_Token --
   ---------------

   procedure New_Token
     (Token : Token_Type;
      Image : String)
   is
      use Utils;

      N : Name_Id;
   begin
      Set_Str_To_Name_Buffer (Prefix & Image);
      Token_Image (Token) := Name_Find;

      if Token in Keyword_Type or else
        Token in Predefined_Sets or else
        Token in Selection_Function_Type or else
        Token in Verification_Function_Type or else
        Token in Higher_Level_Function_Type or else
        Token in T_Equal .. T_Affect
      then
         N := To_Lower (Name_Find);
         Set_Name_Table_Byte (N, Byte (Token_Type'Pos (Token)));
      end if;
   end New_Token;

end Ocarina.ME_REAL.Tokens;