sem.ads (2093B)
with Parser; use Parser;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Hash;
package Sem is
type Type_Info;
type Function_Info;
type Type_Info_Ref is access all Type_Info;
type Function_Info_Ref is access all Function_Info;
type Symbol_Kind_Enum is (SYM_FUNC, SYM_VAR, SYM_LET);
type Type_Kind_Enum is (TY_STRING, TY_INT, TY_FLOAT, TY_BOOL, TY_VOID, TY_FUNC, TY_ERROR);
type Type_List is array (Positive range <>) of Type_Info_Ref;
type Type_List_Ref is access all Type_List;
type Function_Info is record
Params : Type_List_Ref;
Return_Type : Type_Info_Ref;
end record;
type Type_Info (Kind : Type_Kind_Enum := TY_ERROR) is record
case Kind is
when TY_FUNC =>
Func : Function_Info;
when others =>
null;
end case;
end record;
--------------------------------
-- symbol info -----------------
-- made of kind and type info --
--------------------------------
type Symbol_Info is record
Kind : Symbol_Kind_Enum;
Typ : Type_Info_Ref;
end record;
-------------------------------------
-- hashmap of String : Symbol_Info --
-------------------------------------
package Symbols_Map is new
Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => String,
Element_Type => Symbol_Info, -- symbol's info
Hash => Ada.Strings.Hash,
Equivalent_Keys => "=");
-------------
--- scope ---
-------------
type Scope;
type Scope_Ref is access Scope;
type Scope is record
Symbols : Symbols_Map.Map;
Parent : Scope_Ref;
end record;
---------
-- sem --
---------
type Sem is record
Scope : Scope_Ref;
AST : Declaration_Vectors.Vector;
end record;
----------
-- init --
----------
function Init (AST : Declaration_Vectors.Vector) return Sem;
--------------
-- analysis --
--------------
procedure Analysis (S : in out Sem);
end Sem;