* [Cocci] very simple transformations
@ 2013-08-31 3:39 ron minnich
2013-08-31 6:57 ` Julia Lawall
2013-09-03 6:58 ` Julia Lawall
0 siblings, 2 replies; 3+ messages in thread
From: ron minnich @ 2013-08-31 3:39 UTC (permalink / raw)
To: cocci
I've got a file with the following sorts of things
void f(uint x)
{
uint z;
}
I'd like to transform all instances of uint to unsigned int. Doable
with coccinnelle?
Also:
IPhdr x;
needs to become
struct iphdr x;
in all parameters and declarations. Also likely trivial, I can't seem
to get anything to work.
Now a really harder one:
Plan 9 C to C
I have things like
void x(char *, int, int i)
{
...
}
The unnamed params are how we indicate in plan 9 that the parameter is
unused. But coccinnelle throws an error, as it's not really valid. Any
thoughts on this one?
Thanks in advance.
ron
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] very simple transformations
2013-08-31 3:39 [Cocci] very simple transformations ron minnich
@ 2013-08-31 6:57 ` Julia Lawall
2013-09-03 6:58 ` Julia Lawall
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2013-08-31 6:57 UTC (permalink / raw)
To: cocci
On Fri, 30 Aug 2013, ron minnich wrote:
> I've got a file with the following sorts of things
>
> void f(uint x)
> {
> uint z;
> }
>
> I'd like to transform all instances of uint to unsigned int. Doable
> with coccinnelle?
This seems straightforward:
@@
typedef uint;
@@
- uint
+ unsigned int
Perhaps you were missing the typedef.
> Also:
> IPhdr x;
> needs to become
> struct iphdr x;
> in all parameters and declarations. Also likely trivial, I can't seem
> to get anything to work.
This should be the same.
> Now a really harder one:
> Plan 9 C to C
> I have things like
> void x(char *, int, int i)
> {
> ...
> }
>
> The unnamed params are how we indicate in plan 9 that the parameter is
> unused. But coccinnelle throws an error, as it's not really valid. Any
> thoughts on this one?
At the moment, that's not possible. I don't think the C parser will
parse the code, and I'm sure that the SmPL parser won't parse the semantic
patch that you would need. But I think it would be easy to add. I can
try to do that when I finish with Nic's if problems.
julia
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Cocci] very simple transformations
2013-08-31 3:39 [Cocci] very simple transformations ron minnich
2013-08-31 6:57 ` Julia Lawall
@ 2013-09-03 6:58 ` Julia Lawall
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2013-09-03 6:58 UTC (permalink / raw)
To: cocci
> Now a really harder one:
> Plan 9 C to C
> I have things like
> void x(char *, int, int i)
> {
> ...
> }
>
> The unnamed params are how we indicate in plan 9 that the parameter is
> unused. But coccinnelle throws an error, as it's not really valid. Any
> thoughts on this one?
A patch is attached. It was just a simple design decision not to allow
it.
Here is an example use:
@@
fresh identifier i = "v";
type T;
identifier f;
@@
f(...,T
+ i
,...) {...}
----------------------------
int f(int, int, int x) {
return x;
}
julia
-------------- next part --------------
diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
index 4277fd3..785273c 100644
--- a/parsing_cocci/parse_aux.ml
+++ b/parsing_cocci/parse_aux.ml
@@ -614,33 +614,6 @@ let make_final_script_rule_name_result lang deps =
let l = id2name lang in
Ast.FinalScriptRulename(None,l,fix_dependencies deps)
-(* Allows type alone only when it is void and only when there is only one
- parameter. This avoids ambiguity problems in the parser. *)
-let verify_parameter_declarations = function
- [] -> ()
- | [x] ->
- (match Ast0.unwrap x with
- Ast0.Param(t, None) ->
- (match Ast0.unwrap t with
- Ast0.BaseType(Ast.VoidType,_) -> ()
- | _ ->
- failwith
- (Printf.sprintf
- "%d: only void can be a parameter without an identifier"
- (Ast0.get_line t)))
- | _ -> ())
- | l ->
- List.iter
- (function x ->
- match Ast0.unwrap x with
- Ast0.Param(t, None) ->
- failwith
- (Printf.sprintf
- "%d: only void alone can be a parameter without an identifier"
- (Ast0.get_line t))
- | _ -> ())
- l
-
(* ---------------------------------------------------------------------- *)
(* decide whether an init list is ordered or unordered *)
diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index fb4d481..8beef46 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -1053,8 +1053,7 @@ fundecl:
f=fninfo
TFunDecl i=fn_ident lp=TOPar d=decl_list(decl) rp=TCPar
lb=TOBrace b=fun_start rb=TCBrace
- { P.verify_parameter_declarations (Ast0.undots d);
- Ast0.wrap(Ast0.FunDecl((Ast0.default_info(),Ast0.context_befaft()),
+ { Ast0.wrap(Ast0.FunDecl((Ast0.default_info(),Ast0.context_befaft()),
f, i,
P.clt2mcode "(" lp, d,
P.clt2mcode ")" rp,
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-03 6:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-31 3:39 [Cocci] very simple transformations ron minnich
2013-08-31 6:57 ` Julia Lawall
2013-09-03 6:58 ` Julia Lawall
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.