Skip to content

Commit

Permalink
metavar as include argument
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaLawall committed Jul 4, 2018
1 parent 3372dc9 commit 6218741
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 3 deletions.
1 change: 1 addition & 0 deletions engine/check_exhaustive_pattern.ml
Expand Up @@ -52,6 +52,7 @@ let dumb_astcocci_rule_elem = function
| A.Undef _ -> ()
| A.Pragma _ -> ()
| A.Include _ -> ()
| A.MetaInclude _ -> ()
| A.Default _ -> ()
| A.Case _ -> ()
| A.AsRe _ -> ()
Expand Down
23 changes: 23 additions & 0 deletions engine/cocci_vs_c.ml
Expand Up @@ -5178,6 +5178,29 @@ let rec (rule_elem_node: (A.rule_elem, F.node) matcher) =
)))
else fail

| A.MetaInclude(incla,filea),
F.Include {B.i_include = (fileb, ii);
B.i_rel_pos = h_rel_pos;
B.i_overall_rel_pos = o_rel_pos;
B.i_is_in_ifdef = inifdef;
B.i_content = copt;
} ->
let (inclb, iifileb) = tuple_of_list2 ii in
tokenf incla inclb >>= (fun incla inclb ->
expression filea
(Ast_c.mk_e (B.Constant(B.String(B.str_of_info(iifileb),B.IsChar)))
[iifileb]) >>=
(fun filea _ (* no change allowed *) ->
return (
A.MetaInclude(incla,filea),
F.Include {B.i_include = (fileb, ii);
B.i_rel_pos = h_rel_pos;
B.i_overall_rel_pos = o_rel_pos;
B.i_is_in_ifdef = inifdef;
B.i_content = copt;
}
)))

| A.Undef(undefa,ida), F.DefineHeader ((idb, ii), B.Undef) ->
let (defineb, iidb, ieol) = tuple_of_list3 ii in
ident DontKnow ida (idb, iidb) >>= (fun ida (idb, iidb) ->
Expand Down
2 changes: 2 additions & 0 deletions ocaml/coccilib.mli
Expand Up @@ -2841,6 +2841,7 @@ module Ast_cocci :
| TopId of ident
| TopInit of initialiser
| Include of string mcode * inc_file mcode
| MetaInclude of string mcode * expression
| Undef of string mcode * ident
| DefineHeader of string mcode * ident * define_parameters
| Pragma of string mcode * ident * pragmainfo
Expand Down Expand Up @@ -3457,6 +3458,7 @@ module Ast0_cocci :
string mcode * string mcode * statement dots * string mcode *
(info * mcodekind)
| Include of string mcode * Ast_cocci.inc_file mcode
| MetaInclude of string mcode * expression
| Undef of string mcode * ident
| Define of string mcode * ident * define_parameters * statement dots
| Pragma of string mcode * ident * pragmainfo
Expand Down
2 changes: 2 additions & 0 deletions ocaml/exposed_modules.mli
Expand Up @@ -2841,6 +2841,7 @@ module Ast_cocci :
| TopId of ident
| TopInit of initialiser
| Include of string mcode * inc_file mcode
| MetaInclude of string mcode * expression
| Undef of string mcode * ident
| DefineHeader of string mcode * ident * define_parameters
| Pragma of string mcode * ident * pragmainfo
Expand Down Expand Up @@ -3457,6 +3458,7 @@ module Ast0_cocci :
string mcode * string mcode * statement dots * string mcode *
(info * mcodekind)
| Include of string mcode * Ast_cocci.inc_file mcode
| MetaInclude of string mcode * expression
| Undef of string mcode * ident
| Define of string mcode * ident * define_parameters * statement dots
| Pragma of string mcode * ident * pragmainfo
Expand Down
2 changes: 2 additions & 0 deletions parsing_c/unparse_cocci.ml
Expand Up @@ -1158,6 +1158,8 @@ and rule_elem arity re =
| Ast.TopInit(init) -> initialiser false init
| Ast.Include(inc,s) ->
mcode print_string inc; print_text " "; mcode inc_file s
| Ast.MetaInclude(inc,s) ->
mcode print_string inc; print_text " "; expression s
| Ast.Undef(def,id) ->
mcode print_string def; pr_space(); ident id
| Ast.DefineHeader(def,id,params) ->
Expand Down
2 changes: 2 additions & 0 deletions parsing_cocci/adjust_pragmas.ml
Expand Up @@ -135,6 +135,8 @@ let rec right_statement s =
| Ast0.Include(inc,name) ->
call_right right_mcode name s
(function name -> Ast0.Include(inc,name))
| Ast0.MetaInclude(inc,name) ->
None (* likely not correct, wait for pb in practice *)
| Ast0.Undef(def,id) ->
(* nothing available for ident, and not sure code can appear
here anyway *)
Expand Down
5 changes: 5 additions & 0 deletions parsing_cocci/arity.ml
Expand Up @@ -1118,6 +1118,11 @@ and statement tgt stm =
let inc = mcode inc in
let s = mcode s in
make_rule_elem stm tgt arity (Ast0.Include(inc,s))
| Ast0.MetaInclude(inc,s) ->
let arity = all_same true tgt (mcode2line inc) [mcode2arity inc] in
let inc = mcode inc in
let s = expression arity s in
make_rule_elem stm tgt arity (Ast0.MetaInclude(inc,s))
| Ast0.Undef(def,id) ->
let arity = all_same true tgt (mcode2line def) [mcode2arity def] in
let def = mcode def in
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/ast0_cocci.ml
Expand Up @@ -422,6 +422,7 @@ and base_statement =
string mcode (* } *) *
(info * mcodekind) (* after the function decl *)
| Include of string mcode (* #include *) * Ast.inc_file mcode (* file *)
| MetaInclude of string mcode (* #include *) * expression (* file *)
| Undef of string mcode (* #define *) * ident (* name *)
| Define of string mcode (* #define *) * ident (* name *) *
define_parameters (*params*) * statement dots
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/ast0_cocci.mli
Expand Up @@ -408,6 +408,7 @@ and base_statement =
string mcode (* } *) *
(info * mcodekind) (* after the function decl *)
| Include of string mcode (* #include *) * Ast_cocci.inc_file mcode(* file *)
| MetaInclude of string mcode (* #include *) * expression (* file *)
| Undef of string mcode (* #define *) * ident (* name *)
| Define of string mcode (* #define *) * ident (* name *) *
define_parameters (*params*) * statement dots
Expand Down
3 changes: 3 additions & 0 deletions parsing_cocci/ast0toast.ml
Expand Up @@ -1013,6 +1013,9 @@ and statement s =
([],[],[],convert_allminus_mcodekind allminus aft))
| Ast0.Include(inc,str) ->
Ast.Atomic(rewrap_rule_elem s (Ast.Include(mcode inc,mcode str)))
| Ast0.MetaInclude(inc,str) ->
Ast.Atomic
(rewrap_rule_elem s (Ast.MetaInclude(mcode inc,expression str)))
| Ast0.Undef(def,id) ->
Ast.Atomic(rewrap_rule_elem s (Ast.Undef(mcode def,ident id)))
| Ast0.Define(def,id,params,body) ->
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/ast_cocci.ml
Expand Up @@ -576,6 +576,7 @@ and base_rule_elem =
| TopId of ident (* only at top level *)
| TopInit of initialiser (* only at top level *)
| Include of string mcode (*#include*) * inc_file mcode (*file *)
| MetaInclude of string mcode (* #include *) * expression (* file *)
| Undef of string mcode (* #define *) * ident (* name *)
| DefineHeader of string mcode (* #define *) * ident (* name *) *
define_parameters (*params*)
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/ast_cocci.mli
Expand Up @@ -555,6 +555,7 @@ and base_rule_elem =
| TopId of ident (* only at top level *)
| TopInit of initialiser (* only at top level *)
| Include of string mcode (*#include*) * inc_file mcode (*file *)
| MetaInclude of string mcode (* #include *) * expression (* file *)
| Undef of string mcode (* #define *) * ident (* name *)
| DefineHeader of string mcode (* #define *) * ident (* name *) *
define_parameters (*params*)
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/check_meta.ml
Expand Up @@ -461,6 +461,7 @@ and statement old_metas table minus s =
parameter_list old_metas table minus params;
dots (statement old_metas table minus) body
| Ast0.Include(inc,s) -> () (* no metavariables possible *)
| Ast0.MetaInclude(inc,s) -> expression ID old_metas table minus s
| Ast0.Undef(def,id) ->
ident GLOBAL old_metas table minus id
| Ast0.Define(def,id,params,body) ->
Expand Down
5 changes: 5 additions & 0 deletions parsing_cocci/compute_lines.ml
Expand Up @@ -1248,6 +1248,11 @@ let rec statement s =
let inc = normal_mcode inc in
let stm = normal_mcode stm in
mkres s (Ast0.Include(inc,stm)) (promote_mcode inc) (promote_mcode stm)
| Ast0.MetaInclude(inc,s) ->
let inc = normal_mcode inc in
let s = expression s in
mkres s (Ast0.MetaInclude(inc,s)) (promote_mcode inc) s

| Ast0.Undef(def,id) ->
let def = normal_mcode def in
let id = ident id in
Expand Down
2 changes: 2 additions & 0 deletions parsing_cocci/context_neg.ml
Expand Up @@ -877,6 +877,8 @@ let equal_statement s1 s2 =
| (Ast0.Dots(d1,_),Ast0.Dots(d2,_)) -> equal_mcode d1 d2
| (Ast0.Include(inc1,name1),Ast0.Include(inc2,name2)) ->
equal_mcode inc1 inc2 && equal_mcode name1 name2
| (Ast0.MetaInclude(inc1,name1),Ast0.MetaInclude(inc2,name2)) ->
equal_mcode inc1 inc2
| (Ast0.Undef(def1,_),Ast0.Undef(def2,_)) ->
equal_mcode def1 def2
| (Ast0.Define(def1,_,_,_),Ast0.Define(def2,_,_,_)) ->
Expand Down
2 changes: 1 addition & 1 deletion parsing_cocci/disjdistr.ml
Expand Up @@ -434,7 +434,7 @@ let rec disj_rule_elem r k re =
| Ast.TopInit(init) ->
orify_rule_elem_ini re init
(function init -> Ast.rewrap init (Ast.TopInit(init)))
| Ast.Include(inc,s) -> re
| Ast.Include(inc,_) | Ast.MetaInclude(inc,_) -> re
| Ast.Undef(def,id) -> re
| Ast.DefineHeader(def,id,params) -> re
| Ast.Pragma(prg,id,body) ->
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/free_vars.ml
Expand Up @@ -953,6 +953,7 @@ let astfvs metavars bound =
| Ast.TopId _ -> "TopId"
| Ast.TopInit _ -> "TopInit"
| Ast.Include _ -> "Include"
| Ast.MetaInclude _ -> "MetaInclude"
| Ast.Undef _ -> "Undef"
| Ast.DefineHeader _ -> "DefineHeader"
| Ast.Pragma _ -> "Pragma"
Expand Down
3 changes: 2 additions & 1 deletion parsing_cocci/index.ml
Expand Up @@ -6,7 +6,7 @@

(* create an index for each constructor *)
(* current max is 188, also unused: 8-9, 15, 39, 40, 42, 46, 57, 65, 67, 85-86,
111, 113-115, 138-140 *)
113-115, 138-140 *)

(* doesn't really work - requires that identical terms with no token
subterms (eg dots) not appear on the same line *)
Expand Down Expand Up @@ -188,6 +188,7 @@ let statement s =
| Ast0.TopInit(init) -> [146]
| Ast0.Dots(d,whencode) -> [84]
| Ast0.Include(inc,name) -> [118]
| Ast0.MetaInclude(inc,name) -> [111]
| Ast0.Undef(def,id) -> [151]
| Ast0.Define(def,id,params,body) -> [119]
| Ast0.Pragma(prg,id,body) -> [161]
Expand Down
4 changes: 4 additions & 0 deletions parsing_cocci/lexer_cocci.mll
Expand Up @@ -832,6 +832,10 @@ rule token = parse
{ check_minus_context_linetype (tok lexbuf);
start_line true;
TIncludeAny("...",get_current_line_type lexbuf) }
| "#" [' ' '\t']* "include" (* changes not supported *)
{ check_context_linetype (tok lexbuf);
start_line true;
TInclude(get_current_line_type lexbuf) }
| "#" [' ' '\t']* "if" [^'\n']*
| "#" [' ' '\t']* "ifdef" [^'\n']*
| "#" [' ' '\t']* "ifndef" [^'\n']*
Expand Down
6 changes: 6 additions & 0 deletions parsing_cocci/parse_cocci.ml
Expand Up @@ -140,6 +140,7 @@ let token2c (tok,_) add_clt =
| PC.TIncludeL(s,clt) -> add_clt (pr "#include \"%s\"" s) clt
| PC.TIncludeNL(s,clt) -> add_clt (pr "#include <%s>" s) clt
| PC.TIncludeAny(s,clt) -> add_clt (pr "#include %s" s) clt
| PC.TInclude(clt) -> add_clt "#include" clt
| PC.TUndef(clt,_) -> add_clt "#undef" clt
| PC.TDefine(clt,_) -> add_clt "#define" clt
| PC.TDefineParam(clt,_,_,_) -> add_clt "#define_param" clt
Expand Down Expand Up @@ -330,6 +331,7 @@ let plus_attachable only_plus (tok,_) =
| PC.Textern(clt) | PC.Tconst(clt) | PC.Tvolatile(clt)

| PC.TIncludeL(_,clt) | PC.TIncludeNL(_,clt) | PC.TIncludeAny(_,clt)
| PC.TInclude(clt)
| PC.TUndef(clt,_) | PC.TDefine(clt,_) | PC.TPragma(clt)
| PC.TDefineParam(clt,_,_,_) | PC.TCppEscapedNewline(clt)
| PC.TMinusFile(_,clt) | PC.TPlusFile(_,clt)
Expand Down Expand Up @@ -415,6 +417,7 @@ let get_clt (tok,_) =
| PC.Textern(clt) | PC.Tconst(clt) | PC.Tvolatile(clt)

| PC.TIncludeL(_,clt) | PC.TIncludeNL(_,clt) | PC.TIncludeAny(_,clt)
| PC.TInclude(clt)
| PC.TUndef(clt,_) | PC.TDefine(clt,_) | PC.TPragma(clt)
| PC.TDefineParam(clt,_,_,_) | PC.TCppEscapedNewline(clt)
| PC.TMinusFile(_,clt) | PC.TPlusFile(_,clt)
Expand Down Expand Up @@ -585,6 +588,7 @@ let update_clt (tok,x) clt =
| PC.TIncludeL(s,_) -> (PC.TIncludeL(s,clt),x)
| PC.TIncludeNL(s,_) -> (PC.TIncludeNL(s,clt),x)
| PC.TIncludeAny(s,_) -> (PC.TIncludeAny(s,clt),x)
| PC.TInclude(_) -> (PC.TInclude(clt),x)
| PC.TUndef(_,a) -> (PC.TUndef(clt,a),x)
| PC.TDefine(_,a) -> (PC.TDefine(clt,a),x)
| PC.TDefineParam(_,a,b,c) -> (PC.TDefineParam(clt,a,b,c),x)
Expand Down Expand Up @@ -882,6 +886,7 @@ let split_token ((tok,_) as t) =
| PC.TPlusFile(s,clt) | PC.TMinusFile(s,clt)
| PC.TIncludeL(s,clt) | PC.TIncludeNL(s,clt) | PC.TIncludeAny(s,clt) ->
split t clt
| PC.TInclude(clt) -> split t clt
| PC.TUndef(clt,_) | PC.TDefine(clt,_) | PC.TDefineParam(clt,_,_,_)
| PC.TCppEscapedNewline(clt) | PC.TPragma(clt) ->
split t clt
Expand Down Expand Up @@ -1257,6 +1262,7 @@ let token2line (tok,_) =
| PC.TUndef(clt,_) | PC.TDefine(clt,_) | PC.TDefineParam(clt,_,_,_)
| PC.TPragma(clt) | PC.TCppEscapedNewline(clt)
| PC.TIncludeL(_,clt) | PC.TIncludeNL(_,clt) | PC.TIncludeAny(_,clt)
| PC.TInclude(clt)

| PC.TEq(clt) | PC.TOpAssign(_,clt) | PC.TDot(clt) | PC.TComma(clt)
| PC.TPArob(clt) | PC.TPtVirg(clt) ->
Expand Down
13 changes: 12 additions & 1 deletion parsing_cocci/parser_cocci_menhir.mly
Expand Up @@ -258,7 +258,7 @@ let check_constraint_allowed () =
%token <string> TPathIsoFile
%token <string * Data.clt> TIncludeL TIncludeNL TIncludeAny
%token <Data.clt * token> TDefine TUndef
%token <Data.clt> TPragma TCppEscapedNewline
%token <Data.clt> TPragma TCppEscapedNewline TInclude
%token <Data.clt * token * int * int> TDefineParam
%token <string * Data.clt> TMinusFile TPlusFile

Expand Down Expand Up @@ -1253,6 +1253,17 @@ includes:
let clt = (* default to one space whitespace *)
(arity,ln,lln,llne,offset,0,strbef,straft,pos," ") in
P.clt2mcode Ast.AnyInc (P.drop_bef clt))) }
| TInclude TMetaExp
{ Ast0.wrap
(Ast0.MetaInclude
(P.clt2mcode "#include" $1,
match $2 with
(nm,constraints,pure,ty,clt,None) ->
Ast0.wrap
(Ast0.MetaExpr(P.clt2mcode nm clt,constraints,ty,Ast.CONST,
pure,None))
| _ -> failwith "length not allowed for include arugment")) }

| TUndef TLineEnd
{ let (clt,ident) = $1 in
let aft = P.get_aft clt in (* move stuff after the define to the ident *)
Expand Down
2 changes: 2 additions & 0 deletions parsing_cocci/pretty_print_cocci.ml
Expand Up @@ -723,6 +723,8 @@ and rule_elem arity re =
| Ast.TopInit(init) -> initialiser init
| Ast.Include(inc,s) ->
mcode print_string inc; print_string " "; mcode inc_file s
| Ast.MetaInclude(inc,s) ->
mcode print_string inc; print_string " "; expression s
| Ast.Undef(def,id) ->
mcode print_string def; print_string " "; ident id
| Ast.DefineHeader(def,id,params) ->
Expand Down
3 changes: 3 additions & 0 deletions parsing_cocci/single_statement.ml
Expand Up @@ -293,6 +293,7 @@ and left_statement s =
| Ast0.TopInit(init) -> false (* can only be replaced by an init *)
| Ast0.Dots(d,whn) -> false
| Ast0.Include(inc,s) -> modif_before_mcode inc
| Ast0.MetaInclude(inc,s) -> modif_before_mcode inc
| Ast0.Undef(def,id) -> modif_before_mcode def
| Ast0.Define(def,id,params,body) -> modif_before_mcode def
| Ast0.Pragma(prg,id,body) -> modif_before_mcode prg
Expand Down Expand Up @@ -337,6 +338,7 @@ and right_statement s =
| Ast0.TopInit(init) -> false (* can only be replaced by an init *)
| Ast0.Dots(d,whn) -> false
| Ast0.Include(inc,s) -> modif_after_mcode s
| Ast0.MetaInclude(inc,s) -> false (* irrelevant, not a substatement *)
| Ast0.Undef(def,id) -> right_ident id
| Ast0.Define(def,id,params,body) -> right_dots right_statement body
| Ast0.Pragma(prg,id,body) -> right_pragma body -- not defined, b/c not used
Expand Down Expand Up @@ -669,6 +671,7 @@ let rec statement dots_before dots_after s =
| Ast0.TopInit(init) -> s
| Ast0.Dots(d,whn) -> s
| Ast0.Include(inc,string) -> s (* doesn't affect the need for braces *)
| Ast0.MetaInclude(inc,name) -> s (* doesn't affect the need for braces *)
| Ast0.Undef(def,id) -> s (* same as include *)
| Ast0.Define(def,id,params,body) -> s (* same as include *)
| Ast0.Pragma(prg,id,body) -> s (* same as include *)
Expand Down
1 change: 1 addition & 0 deletions parsing_cocci/top_level.ml
Expand Up @@ -33,6 +33,7 @@ let rec is_toplevel s =
| Ast0.Disj(_,stmts,_,_) -> isall is_toplevel stmts
| Ast0.ExprStatement(Some fc,_) -> false
| Ast0.Include(_,_) -> true
| Ast0.MetaInclude(_,_) -> true
| Ast0.Undef(_,_) -> true
| Ast0.Define(_,_,_,_) -> true
| Ast0.Pragma(_,_,_) -> true
Expand Down
2 changes: 2 additions & 0 deletions parsing_cocci/unparse_ast0.ml
Expand Up @@ -660,6 +660,8 @@ and statement arity s =
whn
| Ast0.Include(inc,s) ->
mcode print_string inc; print_string " "; mcode U.inc_file s
| Ast0.MetaInclude(inc,s) ->
mcode print_string inc; print_string " "; expression s
| Ast0.Undef(def,id) ->
mcode print_string def; print_string " "; ident id
| Ast0.Define(def,id,params,body) ->
Expand Down
8 changes: 8 additions & 0 deletions parsing_cocci/visitor_ast.ml
Expand Up @@ -677,6 +677,10 @@ let combiner bind option_default
let linc = string_mcode inc in
let lname = inc_file_mcode name in
bind linc lname
| Ast.MetaInclude(inc,name) ->
let linc = string_mcode inc in
let lname = expression name in
bind linc lname
| Ast.Undef(def,id) ->
let ldef = string_mcode def in
let lid = ident id in
Expand Down Expand Up @@ -1610,6 +1614,10 @@ let rebuilder
let linc = string_mcode inc in
let lname = inc_file_mcode name in
Ast.Include(linc, lname)
| Ast.MetaInclude(inc,name) ->
let linc = string_mcode inc in
let lname = expression name in
Ast.MetaInclude(linc, lname)
| Ast.Undef(def,id) ->
let ldef = string_mcode def in
let lid = ident id in
Expand Down
4 changes: 4 additions & 0 deletions parsing_cocci/visitor_ast0.ml
Expand Up @@ -869,6 +869,10 @@ let visitor mode bind option_default
let (inc_n,inc) = string_mcode inc in
let (name_n,name) = inc_mcode name in
(bind inc_n name_n, Ast0.Include(inc,name))
| Ast0.MetaInclude(inc,name) ->
let (inc_n,inc) = string_mcode inc in
let (name_n,name) = expression name in
(bind inc_n name_n, Ast0.MetaInclude(inc,name))
| Ast0.Undef(def,id) ->
let (def_n,def) = string_mcode def in
let (id_n,id) = ident id in
Expand Down
3 changes: 3 additions & 0 deletions tools/spgen/source/position_generator.ml
Expand Up @@ -480,6 +480,9 @@ let rec statement_pos s snp
| Ast0.Include (incmc,filemc) ->
let constructor ~mc = Ast0.Include(incmc, mc) in
mcode_wrap ~mc:filemc ~constructor snp
| Ast0.MetaInclude (incmc,filemc) ->
let constructor ~mc = Ast0.MetaInclude(mc, filemc) in
mcode_wrap ~mc:incmc ~constructor snp
| Ast0.Undef (defmc, id) ->
let constructor ~id = Ast0.Undef(defmc, id) in
id_wrap ~id ~constructor snp
Expand Down

0 comments on commit 6218741

Please sign in to comment.