Quellcode durchsuchen

Continued documentation of types.mli

Taddeus Kroes vor 12 Jahren
Ursprung
Commit
673ba839a3
1 geänderte Dateien mit 59 neuen und 36 gelöschten Zeilen
  1. 59 36
      types.mli

+ 59 - 36
types.mli

@@ -50,40 +50,45 @@ and annotation =
     used elsewhere. *)
     used elsewhere. *)
 and ann = annotation list
 and ann = annotation list
 
 
-(** Abstract Syntax Tree nodes. *)
+(** Abstract Syntax Tree nodes. All attributes except for [ann] (annotations)
+    are documented. *)
 and node =
 and node =
   (* Global *)
   (* Global *)
   | Program of node list * ann
   | Program of node list * ann
     (** list of declarations *)
     (** list of declarations *)
-  | FunDec of ctype * string * node list * ann
-    (** ret_type, name, params *)
-  | FunDef of bool * ctype * string * node list * node * ann
-    (** export, ret_type, name, params, body *)
   | GlobalDec of ctype * string * ann
   | GlobalDec of ctype * string * ann
-    (** type, name *)
+    (** type, name [extern <type> <name>;] *)
   | GlobalDef of bool * ctype * string * node option * ann
   | GlobalDef of bool * ctype * string * node option * ann
-    (** export, type, name, initialisation *)
+    (** export, type, name, initialisation [<type> <name>[= <initialisation>];] *)
+  | FunDec of ctype * string * node list * ann
+    (** ret_type, name, params [extern <ret_type> <name>(<params>);] *)
+  | FunDef of bool * ctype * string * node list * node * ann
+    (** export, ret_type, name, params, body
+        [[export ]<ret_type> <name>(<params>) <body>] *)
   | Param of ctype * string * ann
   | Param of ctype * string * ann
-    (** type, name *)
+    (** type, name [<type> <name>] *)
   | Dim of string * ann
   | Dim of string * ann
-    (** name *)
+    (** name [<name>] Used in [ArrayDims] for [Param] of array type. *)
 
 
-  | VarDecs of node list
-  | LocalFuns of node list
+  | VarDecs of node list    (** Holds all [VarDec] nodes in a [FunDef]. *)
+  | LocalFuns of node list  (** Holds all local [FunDef] nodes in a [FunDef]. *)
 
 
-  (* Statements *)
+  (** {4 Statements } *)
   | VarDec of ctype * string * node option * ann
   | VarDec of ctype * string * node option * ann
-    (** type, name, initialisation *)
+    (** type, name, initialisation [<type> <name>[= <initialisation>];] *)
   | Assign of string * node list option * node * ann
   | Assign of string * node list option * node * ann
-    (** name, indices, value *)
+    (** name, indices, value [<name>[<indices>] = <value>;] *)
   | For of string * node * node * node * node * ann
   | For of string * node * node * node * node * ann
-    (** counter, start, stop, step, body *)
-  | Allocate of node * node list * ann
-    (** declaration, dims *)
-  | Return of node * ann                     (** return value [return <value>;] *)
-  | Expr of node                             (** expression statement [<expr>;] *)
-  | Block of node list                       (** body [{ <body> }] *)
-  | If of node * node * ann                  (** condition, body [if (condition) { body }] *)
+    (** counter, start, stop, step, body
+        [for (int <counter> = <start>, <stop>[, <step>]) <body>] *)
+  | Return of node * ann
+    (** return value [return <value>;] *)
+  | Expr of node
+    (** expression statement [<expr>;] *)
+  | Block of node list
+    (** body [{ <body> }] *)
+  | If of node * node * ann
+    (** condition, body [if (condition) { body }] *)
   | IfElse of node * node * node * ann
   | IfElse of node * node * node * ann
     (** condition, true_body, false_body [if (<condition>) { <true_body> } else { <false_body> }] *)
     (** condition, true_body, false_body [if (<condition>) { <true_body> } else { <false_body> }] *)
   | While of node * node * ann
   | While of node * node * ann
@@ -92,24 +97,41 @@ and node =
     (** condition, body [do { <body> } whlie (<condition>)] *)
     (** condition, body [do { <body> } whlie (<condition>)] *)
 
 
   (* Expressions *)
   (* Expressions *)
-  | Const of const * ann                     (** constant [bool|int|float constant] *)
-  | ArrayConst of node list * ann            (** array initialisation [[ <expr> , ... ]] *)
-  | Var of string * node list option * ann   (** name, indices [<name> | <name>[<indices>] ] *)
-  | Monop of operator * node * ann           (** operator, operand [<operator><operand>] *)
-  | Binop of operator * node * node * ann    (** operator, left, right [<left> <operator> <right>] *)
-  | TypeCast of ctype * node * ann           (** target_type, value [(target_type)value] *)
-  | FunCall of string * node list * ann      (** name, args [<name>(<args>)] *)
-  | Arg of node                              (** function argument *)
+  | Const of const * ann
+    (** constant [bool|int|float constant] *)
+  | ArrayConst of node list * ann
+    (** array initialisation [[ <expr> , ... ]] *)
+  | Var of string * node list option * ann
+    (** name, indices [<name> | <name>[<indices>] ] *)
+  | Monop of operator * node * ann
+    (** operator, operand [<operator><operand>] *)
+  | Binop of operator * node * node * ann
+    (** operator, left, right [<left> <operator> <right>] *)
+  | TypeCast of ctype * node * ann
+    (** target_type, value [(target_type)value] *)
+  | FunCall of string * node list * ann
+    (** name, args [<name>(<args>)] *)
+  | Arg of node
+    (** Function argument wrapper. *)
 
 
   (* Additional types for convenience in traversals
   (* Additional types for convenience in traversals
    * Mostly used to annotate existing nodes with information from declarations *)
    * Mostly used to annotate existing nodes with information from declarations *)
-  | VarUse of node * node list option * ann  (* Same as Var, but with decl. *)
-  | FunUse of node * node list * ann         (* Same as FunCall, but with decl. *)
-  | VarLet of node * node list option * node * ann (* replacement for Assign *)
-  | ArrayScalar of node                      (* (Bool|Int|Float)Const *)
-  | ArrayInit of node * node list            (* Array(Scalar|Const), dimensions *)
-  | Cond of node * node * node * ann         (* cond, true_expr, false_expr *)
-  | DummyNode                                (* null node, pruned by traversals *)
+  | Allocate of node * node list * ann
+    (** declaration, dims [<declaration> = __allocate(<dims>);] *)
+  | VarUse of node * node list option * ann
+    (** Replacement for [Var] with declaration. *)
+  | FunUse of node * node list * ann
+    (** Replacement for [FunCall] with declaration. *)
+  | VarLet of node * node list option * node * ann
+    (** Replacement for [Assign] with declaration. *)
+  | ArrayScalar of node                      (* TODO: remove *)
+  | ArrayInit of node * node list
+    (** Wrapper for array initalisation with dimensions, used by {!Desug}. *)
+  | Cond of node * node * node * ann
+    (** cond, true_expr, false_expr [<cond> ? <true_expr> : <false_expr>]
+        Used for short-circuit evaluation. *)
+  | DummyNode
+    (** Null node, pruned by traversals. *)
 
 
 (** {2 Assembly instructions} *)
 (** {2 Assembly instructions} *)
 
 
@@ -191,3 +213,4 @@ exception EmptyError
 
 
 exception InvalidNode
 exception InvalidNode
 exception InvalidInput of string
 exception InvalidInput of string
+