diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-05-05 08:15:46 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-05-05 08:15:46 +0000 |
commit | f3a4e6b8796f8358ff85a7a50d1a14fe0e5642b1 (patch) | |
tree | e276e4ec4cfea846de0153bd339774262f17fb79 /cparser/Lexer.mll | |
parent | 7a93de2caaa6e1adca77b1d33d1e97f5d30e52ae (diff) | |
download | compcert-f3a4e6b8796f8358ff85a7a50d1a14fe0e5642b1.tar.gz compcert-f3a4e6b8796f8358ff85a7a50d1a14fe0e5642b1.zip |
Treat all identifiers as VAR_NAME by default (i.e. if not bound by a typedef). This produces better error messages for unbound variable names (proper error message in Elab rather than cryptic syntax error in pre_parser).
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2477 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Lexer.mll')
-rw-r--r-- | cparser/Lexer.mll | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/cparser/Lexer.mll b/cparser/Lexer.mll index e0f36f4f..059c5684 100644 --- a/cparser/Lexer.mll +++ b/cparser/Lexer.mll @@ -87,10 +87,12 @@ let init filename channel : Lexing.lexbuf = end; declare_varname := begin fun id -> - Hashtbl.add lexicon id (fun loc -> VAR_NAME (id, ref VarId, loc)); - match !contexts with - | [] -> () - | t::q -> contexts := (id::t)::q + if Hashtbl.mem lexicon id then begin + Hashtbl.add lexicon id (fun loc -> VAR_NAME (id, ref VarId, loc)); + match !contexts with + | [] -> () + | t::q -> contexts := (id::t)::q + end end; declare_typename := begin fun id -> @@ -302,13 +304,7 @@ rule initial = parse | "." { DOT(currentLoc lexbuf) } | identifier as id { try Hashtbl.find lexicon id (currentLoc lexbuf) - with Not_found -> - let pref = "__builtin_" in - if String.length id > String.length pref && - String.sub id 0 (String.length pref) = pref then - VAR_NAME (id, ref VarId, currentLoc lexbuf) - else - UNKNOWN_NAME(id, ref OtherId, currentLoc lexbuf) } + with Not_found -> VAR_NAME (id, ref VarId, currentLoc lexbuf) } | eof { EOF } | _ as c { Cerrors.fatal_error "%s:%d Error:@ invalid symbol %C" @@ -478,7 +474,6 @@ and hash = parse | TILDE loc -> loop TILDE't loc | TYPEDEF loc -> loop TYPEDEF't loc | TYPEDEF_NAME (id, typ, loc) - | UNKNOWN_NAME (id, typ, loc) | VAR_NAME (id, typ, loc) -> let terminal = match !typ with | VarId -> VAR_NAME't |