Browse Source

Checking the presence and unicity of main

Phyks (Lucas Verney) 5 years ago
parent
commit
07dc0392f3
8 changed files with 560 additions and 294 deletions
  1. BIN
      Sujet 2.pdf
  2. BIN
      main.cmi
  3. BIN
      main.cmo
  4. BIN
      minic++
  5. 543
    292
      typer.annot
  6. BIN
      typer.cmi
  7. BIN
      typer.cmo
  8. 17
    2
      typer.ml

BIN
Sujet 2.pdf View File


BIN
main.cmi View File


BIN
main.cmo View File


BIN
minic++ View File


+ 543
- 292
typer.annot
File diff suppressed because it is too large
View File


BIN
typer.cmi View File


BIN
typer.cmo View File


+ 17
- 2
typer.ml View File

@@ -141,7 +141,6 @@ and type_bloc locals x =
141 141
 
142 142
 let type_proto_ident = function
143 143
     | Qvar (x, y) ->
144
-            if x = Int && y = Qident (Ident "main") then is_main_here := true;
145 144
             ATQvar (types_ast_to_atast x, type_qvar y)
146 145
     | _ -> assert false
147 146
     (* TODO *)
@@ -152,6 +151,17 @@ let type_args x =
152 151
 let type_proto locals x =
153 152
     List.fold_left (fun a b -> Hashtbl.add locals (type_var (snd b)) (4 * Hashtbl.length locals)) () x.args;
154 153
 
154
+    let () = 
155
+        match x.ident with
156
+        | Qvar (a, b) when a = Int && b = Qident (Ident "main") ->
157
+                if List.length x.args = 0 then
158
+                    if not !is_main_here then
159
+                        is_main_here := true
160
+                    else
161
+                        raise (Error ("Redeclaration of main function.", fst x.proto_loc))
162
+        | _ -> ()
163
+    in
164
+
155 165
     {
156 166
         at_ident = type_proto_ident x.ident;
157 167
         at_args = List.map type_args x.args;
@@ -182,4 +192,9 @@ let type_decl = function
182 192
 let rec type_ast p = 
183 193
     if p.includes then includes := true;
184 194
 
185
-    List.map type_decl p.program;
195
+    let return = List.map type_decl p.program in
196
+
197
+    if not !is_main_here then
198
+        raise (Error("No \"int main()\" function present", fst p.program_loc))
199
+    else
200
+        return