source: trunk/ada-2012/src/semantic/gela-plain_environments.ads@ 318

Last change on this file since 318 was 318, checked in by Maxim Reznik, 6 years ago

Move Ada 2012 code to trunk

File size: 6.0 KB
Line 
1-- This package provides Environment_Set.
2with Gela.Contexts;
3with Gela.Defining_Name_Cursors;
4with Gela.Elements.Defining_Names;
5with Gela.Environments;
6with Gela.Lexical_Types;
7with Gela.Semantic_Types;
8with Gela.Library_Environments;
9
10with Ada.Containers.Hashed_Maps;
11with Ada.Containers.Vectors;
12with Gela.Peristent_Lists;
13with Gela.Name_List_Managers;
14
15package Gela.Plain_Environments is
16 pragma Preelaborate;
17
18 type Environment_Set (Context : access Gela.Contexts.Context'Class) is
19 new Gela.Environments.Environment_Set with private;
20 type Plain_Environment_Set_Access is access all Environment_Set;
21
22private
23
24 package Defining_Name_Lists is new Gela.Peristent_Lists
25 (Element_Type => Gela.Elements.Defining_Names.Defining_Name_Access);
26
27 subtype Defining_Name_Item_Count is Defining_Name_Lists.Count_Type;
28 subtype Defining_Name_Item_Index is Defining_Name_Lists.Index_Type;
29
30 -- Region_Item --
31
32 type Region_Item is record
33 Name : Gela.Elements.Defining_Names.Defining_Name_Access;
34 -- Defining name corresponding to given region, if any
35 Local : Gela.Name_List_Managers.List;
36 -- List of Direct_Visible_Item.
37 Use_Package : Defining_Name_Item_Count;
38 -- List of use_package_clauses in the region
39 end record;
40
41 package Region_Item_Lists is new Gela.Peristent_Lists
42 (Element_Type => Region_Item);
43
44 subtype Region_Item_Count is Region_Item_Lists.Count_Type;
45 subtype Region_Item_Index is Region_Item_Lists.Index_Type;
46
47 -- Env_Item --
48
49 type Region_Enum is (Nested, Other, Withed);
50 -- Nested - List of nested regions, current - first
51 -- Other - List of all visible regions except Nested_Region_List
52 -- Withed - List of regions available over with clauses
53
54 type Region_List_Array is array (Region_Enum) of Region_Item_Count;
55 type Env_Item is record
56 Region_List : Region_List_Array;
57 end record;
58
59 use type Gela.Semantic_Types.Env_Index;
60
61 subtype Env_Item_Index is Gela.Semantic_Types.Env_Index
62 range 1 .. Gela.Semantic_Types.Env_Index'Last - 1;
63 -- Reserve last for Library_Level_Environment index
64
65 package Env_Item_Vectors is new Ada.Containers.Vectors
66 (Index_Type => Env_Item_Index,
67 Element_Type => Env_Item);
68
69 function Hash
70 (X : Gela.Lexical_Types.Symbol) return Ada.Containers.Hash_Type;
71
72 function Hash
73 (X : Gela.Semantic_Types.Env_Index) return Ada.Containers.Hash_Type;
74
75 package Symbol_Maps is new Ada.Containers.Hashed_Maps
76 (Key_Type => Gela.Lexical_Types.Symbol,
77 Element_Type => Gela.Semantic_Types.Env_Index,
78 Hash => Hash,
79 Equivalent_Keys => Gela.Lexical_Types."=",
80 "=" => Gela.Semantic_Types."=");
81
82 package Env_Maps is new Ada.Containers.Hashed_Maps
83 (Key_Type => Gela.Semantic_Types.Env_Index,
84 Element_Type => Gela.Lexical_Types.Symbol,
85 Hash => Hash,
86 Equivalent_Keys => Gela.Semantic_Types."=",
87 "=" => Gela.Lexical_Types."=");
88
89 type Environment_Set (Context : access Gela.Contexts.Context'Class) is
90 new Gela.Environments.Environment_Set with
91 record
92 Names : aliased Gela.Name_List_Managers.Name_List_Manager;
93 Lib : aliased Gela.Library_Environments.Environment_Set (Context);
94 Env : Env_Item_Vectors.Vector;
95 Region : Region_Item_Lists.Container;
96 Use_Package : Defining_Name_Lists.Container;
97 Units_Env : Symbol_Maps.Map;
98 -- Map of library level regions
99 Lib_Env : Env_Maps.Map;
100 -- Reverse mapping for Units_Env
101 end record;
102
103 overriding function Empty_Environment
104 (Self : Environment_Set)
105 return Gela.Semantic_Types.Env_Index;
106
107 overriding function Add_With_Clause
108 (Self : in out Environment_Set;
109 Index : Gela.Semantic_Types.Env_Index;
110 Symbol : Gela.Lexical_Types.Symbol)
111 return Gela.Semantic_Types.Env_Index;
112
113 overriding function Add_Defining_Name
114 (Self : in out Environment_Set;
115 Index : Gela.Semantic_Types.Env_Index;
116 Symbol : Gela.Lexical_Types.Symbol;
117 Name : Gela.Elements.Defining_Names.Defining_Name_Access)
118 return Gela.Semantic_Types.Env_Index;
119
120 overriding function Add_Use_Package
121 (Self : in out Environment_Set;
122 Index : Gela.Semantic_Types.Env_Index;
123 Name : Gela.Elements.Defining_Names.Defining_Name_Access)
124 return Gela.Semantic_Types.Env_Index;
125
126 overriding function Direct_Visible
127 (Self : access Environment_Set;
128 Index : Gela.Semantic_Types.Env_Index;
129 Symbol : Gela.Lexical_Types.Symbol)
130 return Gela.Defining_Name_Cursors.Defining_Name_Cursor'Class;
131
132 overriding function Enter_Declarative_Region
133 (Self : access Environment_Set;
134 Index : Gela.Semantic_Types.Env_Index;
135 Region : Gela.Elements.Defining_Names.Defining_Name_Access)
136 return Gela.Semantic_Types.Env_Index;
137
138 overriding function Leave_Declarative_Region
139 (Self : access Environment_Set;
140 Index : Gela.Semantic_Types.Env_Index)
141 return Gela.Semantic_Types.Env_Index;
142
143 overriding function Library_Level_Environment
144 (Self : Environment_Set)
145 return Gela.Semantic_Types.Env_Index;
146
147 overriding function Library_Unit_Environment
148 (Self : access Environment_Set;
149 Symbol : Gela.Lexical_Types.Symbol)
150 return Gela.Semantic_Types.Env_Index;
151
152 overriding procedure Set_Library_Unit_Environment
153 (Self : access Environment_Set;
154 Symbol : Gela.Lexical_Types.Symbol;
155 Value : Gela.Semantic_Types.Env_Index);
156
157 overriding function Use_Visible
158 (Self : access Environment_Set;
159 Index : Gela.Semantic_Types.Env_Index;
160 Symbol : Gela.Lexical_Types.Symbol)
161 return Gela.Defining_Name_Cursors.Defining_Name_Cursor'Class;
162
163 overriding function Visible
164 (Self : access Environment_Set;
165 Index : Gela.Semantic_Types.Env_Index;
166 Region : Gela.Elements.Defining_Names.Defining_Name_Access;
167 Symbol : Gela.Lexical_Types.Symbol;
168 Found : access Boolean)
169 return Gela.Defining_Name_Cursors.Defining_Name_Cursor'Class;
170
171end Gela.Plain_Environments;
Note: See TracBrowser for help on using the repository browser.