Skip to content

Commit 619fbe2

Browse files
author
Fabrice Le Fessant
committed
Display missing import files
1 parent e6576b4 commit 619fbe2

File tree

9 files changed

+35
-14
lines changed

9 files changed

+35
-14
lines changed

src/solidity-common/solidity_ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and source_unit =
3939
| ContractDefinition of contract_definition
4040

4141
and import_directive = {
42+
import_pos : Solidity_common.pos ;
4243
import_from : string;
4344
import_symbols : import_symbols;
4445
}

src/solidity-common/solidity_ast.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ and source_unit =
5656
(** Definition of a contract *)
5757

5858
and import_directive = {
59+
import_pos : Solidity_common.pos ;
5960
import_from : string;
6061
import_symbols : import_symbols;
6162
}

src/solidity-common/solidity_printer.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,18 @@ and bprint_source_unit b ~freeton indent su =
133133
| Pragma (id, s) ->
134134
if not freeton then
135135
bprint b indent (Format.asprintf "pragma %a %s;" Ident.printf id s)
136-
| Import { import_from; import_symbols = ImportAll (None) } ->
136+
| Import { import_from; import_symbols = ImportAll (None) ;
137+
import_pos = _ } ->
137138
if not freeton then
138139
bprint b indent
139140
(Format.sprintf "import %S;" import_from)
140-
| Import { import_from; import_symbols = ImportAll (Some id) } ->
141+
| Import { import_from; import_symbols = ImportAll (Some id) ;
142+
import_pos = _ } ->
141143
bprint b indent
142144
(Format.sprintf "import * as %s from %s;"
143145
(string_of_ident id) import_from)
144-
| Import { import_from; import_symbols = ImportIdents import_list } ->
146+
| Import { import_from; import_symbols = ImportIdents import_list ;
147+
import_pos = _ } ->
145148
bprint b indent
146149
(Format.sprintf "import { %s } from %s;"
147150
(String.concat ", "

src/solidity-common/solidity_visitor.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ and visitSourceUnit (v : #ast_visitor) (su : source_unit) : unit =
511511
handleAction v#visitSourceUnit continueVisit su
512512

513513
and visitImportDirective (v : #ast_visitor) (id : import_directive) : unit =
514-
let continueVisit ({import_from; import_symbols} : import_directive) : unit =
514+
let continueVisit ({import_from; import_symbols; import_pos=_} : import_directive) : unit =
515515
visitString v import_from;
516516
visitImportSymbols v import_symbols in
517517
handleAction v#visitImportDirective continueVisit id

src/solidity-parser/solidity_lexer.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ val init : freeton:bool -> unit
1515
val reset : unit -> unit
1616

1717
val token : Lexing.lexbuf -> Solidity_raw_parser.token
18+
19+
val recursive_comments : bool ref

src/solidity-parser/solidity_lexer.mll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
pos_bol = pos.pos_cnum - chars;
6161
}
6262

63+
let recursive_comments = ref false
64+
6365
}
6466

6567
let eol_comment =
@@ -105,7 +107,7 @@ rule token = parse
105107
{ update_loc lexbuf name (int_of_string num) true 0;
106108
token lexbuf }
107109

108-
| "/*" { multiline_comment lexbuf }
110+
| "/*" { multiline_comment lexbuf ; token lexbuf }
109111
| "pragma" { Buffer.clear buf; begin_pragma lexbuf }
110112

111113
| "[" { LBRACKET }
@@ -204,8 +206,15 @@ rule token = parse
204206
{ error lexbuf "Unrecognized lexeme: \"%s\"" (Lexing.lexeme lexbuf) }
205207

206208
and multiline_comment = parse
207-
| "*/" { token lexbuf }
209+
| "*/" { () }
208210
| newline_char { newline lexbuf; multiline_comment lexbuf }
211+
| "hex"? '\'' ([^ '\'' '\r' '\n' '\\'] | "\\" _)* '\''
212+
| "hex"? '"' ([^ '"' '\r' '\n' '\\'] | "\\" _)* '"'
213+
{ multiline_comment lexbuf }
214+
| "/*" {
215+
if !recursive_comments then
216+
multiline_comment lexbuf;
217+
multiline_comment lexbuf }
209218
| eof { failwith "unexpected end of file in comment" }
210219
| _ { multiline_comment lexbuf }
211220

src/solidity-parser/solidity_parser.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ let get_imported_files m =
1717
let base = Filename.dirname m.module_file in
1818
List.fold_left (fun fileset unit_node ->
1919
match strip unit_node with
20-
| Import { import_from; _ } ->
20+
| Import { import_from; import_pos ; _ } ->
2121
let file = make_absolute_path base import_from in
22+
if not ( Sys.file_exists file ) then
23+
raise (
24+
Solidity_exceptions.SyntaxError
25+
("File does not exist", import_pos ) );
2226
StringSet.add file fileset
2327
| _ -> fileset
2428
) StringSet.empty m.module_units

src/solidity-parser/solidity_raw_parser.mly

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@
216216
| AmbiguousArray (a, expo) ->
217217
Array (type_name_of_ambiguity a, expo)
218218

219-
let import import_from import_symbols =
220-
{ import_from; import_symbols }
219+
let import import_pos import_from import_symbols =
220+
let import_pos = to_pos import_pos in
221+
{ import_pos; import_from; import_symbols }
221222

222223
let rec put_in_none_list l n =
223224
if n <= 0 then l
@@ -468,11 +469,11 @@ source_unit:
468469

469470
import_directive:
470471
| STRINGLITERAL as_identifier?
471-
{ import $1 (ImportAll ($2)) }
472+
{ import $loc $1 (ImportAll ($2)) }
472473
| STAR as_identifier FROM STRINGLITERAL
473-
{ import $4 (ImportAll (Some $2)) }
474+
{ import $loc $4 (ImportAll (Some $2)) }
474475
| LBRACE import_declarations RBRACE FROM STRINGLITERAL
475-
{ import $5 (ImportIdents $2) }
476+
{ import $loc $5 (ImportIdents $2) }
476477
;;
477478

478479
import_declarations:

src/solidity-typechecker/solidity_typechecker.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ let preprocess_module p menvs m =
19341934
match strip unit_node with
19351935
| Pragma (_) ->
19361936
()
1937-
| Import { import_from; import_symbols } ->
1937+
| Import { import_from; import_symbols ; import_pos=_ } ->
19381938
let file = make_absolute_path base import_from in
19391939
let im = StringMap.find file p.program_modules_by_file in
19401940
let imenv = IdentMap.find im.module_id menvs in
@@ -2000,7 +2000,7 @@ let rec resolve_imports_internal ~only_anonymous
20002000
let seen, ordered =
20012001
List.fold_left (fun (seen, ordered) unit_node ->
20022002
match strip unit_node with
2003-
| Import { import_from; import_symbols } ->
2003+
| Import { import_from; import_symbols; import_pos=_ } ->
20042004
let do_imports =
20052005
match import_symbols with
20062006
| ImportAll (None) -> true

0 commit comments

Comments
 (0)