Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/ckit/src/ast/ast-sig.sml
ViewVC logotype

Annotation of /sml/trunk/ckit/src/ast/ast-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 975 - (view) (download)

1 : dbm 597 (* Copyright (c) 1998 by Lucent Technologies *)
2 :    
3 :     signature AST =
4 :     sig
5 :    
6 :     type pid = Pid.uid
7 :     type aid = Aid.uid
8 :     type tid = Tid.uid
9 :    
10 :     (* TYPES: preliminary definitions *)
11 :     datatype storageClass = AUTO | EXTERN | REGISTER | STATIC | DEFAULT
12 :    
13 :     datatype qualifier = CONST | VOLATILE
14 :    
15 :     datatype signedness = SIGNED | UNSIGNED
16 :    
17 :     (* signednessTag determines whether a type was declared signed or unsigned, or
18 :     * the type was assumed to be one or the other. *)
19 :     datatype signednessTag = SIGNDECLARED | SIGNASSUMED
20 :    
21 :     datatype intKind = CHAR | SHORT | INT | LONG | LONGLONG | FLOAT | DOUBLE | LONGDOUBLE
22 :    
23 :     (* BEGIN D *)
24 :     datatype fractionality = FRACTIONAL | WHOLENUM (* FRACTIONAL dominates WHOLENUM *)
25 :    
26 :     datatype saturatedness = SATURATE | NONSATURATE (* SATURATE dominates NONSATURATE *)
27 :     (* END D *)
28 :    
29 :     (* note: definition of ctype appears later, is in the mutual recursive clump. *)
30 :    
31 :     (* IDENTIFIERS: preliminary definitions *)
32 :    
33 :     (* labels *)
34 :     type label =
35 :     {name: Symbol.symbol, (* the name of the label *)
36 :     uid : Pid.uid, (* unique identifier *)
37 :     location : SourceMap.location}
38 :    
39 :     datatype declStatus
40 :     = IMPLICIT (* used, but not yet declared or defined *)
41 :     | DECLARED (* declared, but not yet defined *)
42 :     | DEFINED (* defined, i.e. there is a FunctionDef or
43 :     * initializer for this identifier *)
44 :    
45 :     (* identifiers - we call these "id"s *)
46 :     datatype idKind
47 :     = NONFUN (* is not of functional type *)
48 :     | FUNCTION of (* is of functional type *)
49 :     {hasFunctionDef: bool} (* was defined by a FunctionDef *)
50 :    
51 :     (* OPERATORS *)
52 :     datatype binop
53 :     = Plus | Minus | Times | Divide | Mod
54 :     | Gt | Lt | Gte | Lte | Eq | Neq | And | Or
55 :     | BitOr | BitAnd | BitXor | Lshift | Rshift
56 :     | PlusAssign | MinusAssign | TimesAssign | DivAssign
57 :     | ModAssign | XorAssign | OrAssign | AndAssign
58 :     | LshiftAssign | RshiftAssign | BinopExt of AstExt.binopExt
59 :    
60 :     datatype unop
61 :     = Uplus | Not | Negate | BitNot
62 :     | PreInc | PostInc | PreDec | PostDec | UnopExt of AstExt.unopExt
63 :    
64 :    
65 :     (* DECLARATIONS *)
66 :    
67 :     datatype declaration
68 :     = TypeDecl of {shadow: {strct:bool} option, tid:tid}
69 :     (* placeholder to indicate where typedefs/enums/structs should be printed *)
70 :     | VarDecl of id * initExpression option
71 :    
72 :    
73 :     (* STATEMENTS *)
74 :    
75 :     and statement = STMT of coreStatement * aid * SourceMap.location
76 :    
77 :     and coreStatement
78 :     = Expr of expression option
79 :     | Compound of declaration list * statement list
80 :     | While of expression * statement
81 :     | Do of expression * statement
82 :     | For of expression option * expression option * expression option * statement
83 :     | Labeled of label * statement
84 :     | CaseLabel of LargeInt.int * statement
85 :     | DefaultLabel of statement
86 :     | Goto of label
87 :     | Break
88 :     | Continue
89 :     | Return of expression option
90 :     | IfThen of expression * statement
91 :     | IfThenElse of expression * statement * statement
92 :     | Switch of expression * statement
93 :     | StatExt of (expression, statement, binop, unop) AstExt.statementExt
94 :     | ErrorStmt
95 :    
96 :     (* EXPRESSIONS *)
97 :    
98 :     and expression = EXPR of coreExpression * aid * SourceMap.location
99 :    
100 :     and coreExpression
101 :     = IntConst of LargeInt.int
102 :     | RealConst of real
103 :     | StringConst of string
104 :     | Call of expression * expression list
105 :     | QuestionColon of expression * expression * expression
106 :     | Assign of expression * expression
107 :     | Comma of expression * expression
108 :     | Sub of expression * expression
109 :     | Member of expression * member
110 :     | Arrow of expression * member
111 :     | Deref of expression
112 :     | AddrOf of expression
113 :     | Binop of binop * expression * expression
114 :     | Unop of unop * expression
115 :     | Cast of ctype * expression
116 :     | Id of id
117 :     | EnumId of member * LargeInt.int
118 :     | SizeOf of ctype (* not used in compiler mode; sizeof expr becomes sizeof (typeof expr) *)
119 :     | ExprExt of (expression, statement, binop, unop) AstExt.expressionExt
120 :     | ErrorExpr
121 :    
122 :     and initExpression
123 :     = Simple of expression
124 :     | Aggregate of initExpression list
125 :    
126 :     and ctype
127 :     = Void
128 :     | Ellipses
129 :     | Qual of qualifier * ctype
130 :     | Numeric of (* D *) saturatedness * (* D *) fractionality * signedness * intKind
131 :     * signednessTag
132 :     | Array of (LargeInt.int * expression) option * ctype
133 :     | Pointer of ctype
134 : blume 975 | Function of ctype * (ctype * id option) list
135 : dbm 597 | StructRef of tid (* reference to a tid bound by a struct decl *)
136 :     | UnionRef of tid (* reference to a tid bound by a union decl *)
137 :     | EnumRef of tid (* reference to a tid bound by a enumeration decl *)
138 :     | TypeRef of tid (* reference to a tid bound by a typedef decl *)
139 :     | Error
140 :    
141 :     (* INVARIANT: whenever the Error ctype is introduced, an error message will be printed.
142 :     * Thus any downstream code processing the Error value does not need to (and should not)
143 :     * generate additional error messages. *)
144 :    
145 :     (* MEMBERS AND IDENTIFIERS *)
146 :    
147 :     (* Members in structs and unions. Also used for named constants in
148 :     * enumerations; the ISO Standard calls these "members". *)
149 :     and memberKind
150 :     = STRUCTmem
151 :     | UNIONmem
152 :     | ENUMmem of LargeInt.int
153 :    
154 :     withtype member =
155 :     {name: Symbol.symbol, (* the name of the member *)
156 :     uid : Pid.uid, (* unique identifier *)
157 :     location : SourceMap.location,
158 :     ctype: ctype, (* member type *)
159 :     kind: memberKind} (* member kind: struct, union, or enum *)
160 :    
161 :     and id =
162 :     {name: Symbol.symbol,
163 :     uid: Pid.uid, (* unique identifier *)
164 :     location: SourceMap.location,
165 :     ctype: ctype, (* associated type *)
166 :     stClass: storageClass,
167 :     status: declStatus,
168 :     global: bool, (* defined at top level *)
169 :     kind: idKind}
170 :    
171 :     (* the common fields of id and member could be factored out, but
172 :     * this would increase space usage and access time, and require
173 :     * nested patterns when accessing the common fields. E.g.:
174 :    
175 :     type id =
176 :     {base : basicId,
177 :     stClass: storageClass option,
178 :     kind: idKind}
179 :     *)
180 :    
181 :    
182 :     (* top-level program elements *)
183 :     datatype coreExternalDecl
184 :     = ExternalDecl of declaration
185 :     | FunctionDef of id * id list * statement
186 :     | ExternalDeclExt of (expression, statement, binop, unop) AstExt.externalDeclExt
187 :    
188 :     (* marked and (potentially) annotated external declarations *)
189 :     datatype externalDecl = DECL of coreExternalDecl * aid * SourceMap.location
190 :    
191 :     (* PROGRAMS *)
192 :     (* abstract syntax of "programs", i.e. the result of processing a source file
193 :     * also known as a "translation unit" *)
194 :     type ast = externalDecl list
195 :    
196 :    
197 :     end (* signature AST *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0