# Matching K&R style function definitions?

Suppose I have a function def like this:

double func(a, b)
int a;
float b;
{
return a * b;
}

and I would like to rewrite it as:

double func(int a, float b)
{
return a * b;
}

What’s the best way to write a matcher for the first form?

I dumped the AST for both of them, and didn’t see any obvious sign:

[ K&R ]
e[0;34m|-e[0me[0;1;32mFunctionDecle[0me[0;33m 0x7ffd5302ab10e[0m <e[0;33mkr.c:1:1e[0m, e[0;33mline:6:1e[0m> e[0;33mline:1:8e[0m usede[0;1;36m funce[0m e[0;32m'double (int, double)'e[0m
e[0;34m| |-e[0me[0;1;32mParmVarDecle[0me[0;33m 0x7ffd5302a9d0e[0m <e[0;33mline:2:1e[0m, e[0;33mcol:5e[0m> e[0;33mcol:5e[0m usede[0;1;36m ae[0m e[0;32m'int'e[0m
e[0;34m| |-e[0me[0;1;32mParmVarDecle[0me[0;33m 0x7ffd5302aa40e[0m <e[0;33mline:3:1e[0m, e[0;33mcol:7e[0m> e[0;33mcol:7e[0m usede[0;1;36m be[0m e[0;32m'float'e[0m
e[0;34m| `-e[0me[0;1;35mCompoundStmte[0me[0;33m 0x7ffd5302acb8e[0m <e[0;33mline:4:1e[0m, e[0;33mline:6:1e[0m>
e[0;34m| `-e[0me[0;1;35mReturnStmte[0me[0;33m 0x7ffd5302ac98e[0m <e[0;33mline:5:2e[0m, e[0;33mcol:13e[0m>
e[0;34m| `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ffd5302ac80e[0m <e[0;33mcol:9e[0m, e[0;33mcol:13e[0m> e[0;32m'double'e[0me[0;36me[0me[0;36me[0m <e[0;31mFloatingCaste[0m>
e[0;34m| `-e[0me[0;1;35mBinaryOperatore[0me[0;33m 0x7ffd5302ac58e[0m <e[0;33mcol:9e[0m, e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m '*'
e[0;34m| |-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ffd5302ac40e[0m <e[0;33mcol:9e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m <e[0;31mIntegralToFloatinge[0m>
e[0;34m| | `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ffd5302ac10e[0m <e[0;33mcol:9e[0m> e[0;32m'int'e[0me[0;36me[0me[0;36me[0m <e[0;31mLValueToRValuee[0m>
e[0;34m| | `-e[0me[0;1;35mDeclRefExpre[0me[0;33m 0x7ffd5302abc0e[0m <e[0;33mcol:9e[0m> e[0;32m'int'e[0me[0;36m lvaluee[0me[0;36me[0m e[0;1;32mParmVare[0me[0;33m 0x7ffd5302a9d0e[0me[0;1;36m 'a'e[0m e[0;32m'int'e[0m
e[0;34m| `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ffd5302ac28e[0m <e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m <e[0;31mLValueToRValuee[0m>
e[0;34m| `-e[0me[0;1;35mDeclRefExpre[0me[0;33m 0x7ffd5302abe8e[0m <e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36m lvaluee[0me[0;36me[0m e[0;1;32mParmVare[0me[0;33m 0x7ffd5302aa40e[0me[0;1;36m 'b'e[0m e[0;32m'float'e[0m

[ ANSI ]
e[0;34m|-e[0me[0;1;32mFunctionDecle[0me[0;33m 0x7ff6d9829110e[0m <e[0;33mkr.c:8:1e[0m, e[0;33mline:11:1e[0m> e[0;33mline:8:8e[0m usede[0;1;36m funce[0m e[0;32m'double (int, float)'e[0m
e[0;34m| |-e[0me[0;1;32mParmVarDecle[0me[0;33m 0x7ff6d9828fd0e[0m <e[0;33mcol:13e[0m, e[0;33mcol:17e[0m> e[0;33mcol:17e[0m usede[0;1;36m ae[0m e[0;32m'int'e[0m
e[0;34m| |-e[0me[0;1;32mParmVarDecle[0me[0;33m 0x7ff6d9829040e[0m <e[0;33mcol:20e[0m, e[0;33mcol:26e[0m> e[0;33mcol:26e[0m usede[0;1;36m be[0m e[0;32m'float'e[0m
e[0;34m| `-e[0me[0;1;35mCompoundStmte[0me[0;33m 0x7ff6d98292b8e[0m <e[0;33mline:9:1e[0m, e[0;33mline:11:1e[0m>
e[0;34m| `-e[0me[0;1;35mReturnStmte[0me[0;33m 0x7ff6d9829298e[0m <e[0;33mline:10:2e[0m, e[0;33mcol:13e[0m>
e[0;34m| `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ff6d9829280e[0m <e[0;33mcol:9e[0m, e[0;33mcol:13e[0m> e[0;32m'double'e[0me[0;36me[0me[0;36me[0m <e[0;31mFloatingCaste[0m>
e[0;34m| `-e[0me[0;1;35mBinaryOperatore[0me[0;33m 0x7ff6d9829258e[0m <e[0;33mcol:9e[0m, e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m '*'
e[0;34m| |-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ff6d9829240e[0m <e[0;33mcol:9e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m <e[0;31mIntegralToFloatinge[0m>
e[0;34m| | `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ff6d9829210e[0m <e[0;33mcol:9e[0m> e[0;32m'int'e[0me[0;36me[0me[0;36me[0m <e[0;31mLValueToRValuee[0m>
e[0;34m| | `-e[0me[0;1;35mDeclRefExpre[0me[0;33m 0x7ff6d98291c0e[0m <e[0;33mcol:9e[0m> e[0;32m'int'e[0me[0;36m lvaluee[0me[0;36me[0m e[0;1;32mParmVare[0me[0;33m 0x7ff6d9828fd0e[0me[0;1;36m 'a'e[0m e[0;32m'int'e[0m
e[0;34m| `-e[0me[0;1;35mImplicitCastExpre[0me[0;33m 0x7ff6d9829228e[0m <e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36me[0me[0;36me[0m <e[0;31mLValueToRValuee[0m>
e[0;34m| `-e[0me[0;1;35mDeclRefExpre[0me[0;33m 0x7ff6d98291e8e[0m <e[0;33mcol:13e[0m> e[0;32m'float'e[0me[0;36m lvaluee[0me[0;36me[0m e[0;1;32mParmVare[0me[0;33m 0x7ff6d9829040e[0me[0;1;36m 'b'e[0m e[0;32m'float'e[0m