summaryrefslogtreecommitdiff
path: root/cparser/Env.ml
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-12-18 07:54:35 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2012-12-18 07:54:35 +0000
commit712f3cbae6bfd3c6f6cc40d44f438aa0affcd371 (patch)
tree913762a241b5f97b3ef4df086ba6adaeb2ff45c4 /cparser/Env.ml
parentc629161139899e43a2fe7c5af59ca926cdab370e (diff)
Support for inline assembly (asm statements).
cparser: add primitive support for enum types. bitfield emulation: for bitfields with enum type, choose signed/unsigned as appropriate git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2074 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Env.ml')
-rw-r--r--cparser/Env.ml38
1 files changed, 35 insertions, 3 deletions
diff --git a/cparser/Env.ml b/cparser/Env.ml
index 164fe59..355a996 100644
--- a/cparser/Env.ml
+++ b/cparser/Env.ml
@@ -72,26 +72,35 @@ type composite_info = {
type ident_info =
| II_ident of storage * typ
- | II_enum of int64 (* value of the enum *)
+ | II_enum of int64 (* value of enumerator *)
(* Infos associated with a typedef *)
type typedef_info = typ
+(* Infos associated with an enum *)
+
+type enum_info = {
+ ei_members: enumerator list; (* list of all members *)
+ ei_attr: attributes (* attributes, if any *)
+}
+
(* Environments *)
type t = {
env_scope: int;
env_ident: ident_info IdentMap.t;
env_tag: composite_info IdentMap.t;
- env_typedef: typedef_info IdentMap.t
+ env_typedef: typedef_info IdentMap.t;
+ env_enum: enum_info IdentMap.t
}
let empty = {
env_scope = 0;
env_ident = IdentMap.empty;
env_tag = IdentMap.empty;
- env_typedef = IdentMap.empty
+ env_typedef = IdentMap.empty;
+ env_enum = IdentMap.empty
}
(* Enter a new scope. *)
@@ -143,6 +152,12 @@ let lookup_typedef env s =
with Not_found ->
raise(Error(Unbound_typedef s))
+let lookup_enum env s =
+ try
+ IdentMap.lookup s env.env_enum
+ with Not_found ->
+ raise(Error(Unbound_tag(s, "enum")))
+
(* Checking if a source name is bound *)
let ident_is_bound env s = StringMap.mem s env.env_ident
@@ -200,6 +215,12 @@ let find_typedef env id =
with Not_found ->
raise(Error(Unbound_typedef(id.name)))
+let find_enum env id =
+ try
+ IdentMap.find id env.env_enum
+ with Not_found ->
+ raise(Error(Unbound_tag(id.name, "enum")))
+
(* Inserting things by source name, with generation of a translated name *)
let enter_ident env s sto ty =
@@ -219,6 +240,10 @@ let enter_typedef env s info =
let id = fresh_ident s in
(id, { env with env_typedef = IdentMap.add id info env.env_typedef })
+let enter_enum env s info =
+ let id = fresh_ident s in
+ (id, { env with env_enum = IdentMap.add id info env.env_enum })
+
(* Inserting things by translated name *)
let add_ident env id sto ty =
@@ -230,6 +255,13 @@ let add_composite env id ci =
let add_typedef env id info =
{ env with env_typedef = IdentMap.add id info env.env_typedef }
+let add_enum env id info =
+ let add_enum_item env (id, v, exp) =
+ { env with env_ident = IdentMap.add id (II_enum v) env.env_ident } in
+ List.fold_left add_enum_item
+ { env with env_enum = IdentMap.add id info env.env_enum }
+ info.ei_members
+
(* Error reporting *)
open Printf