Loading files
78711c898This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/tulipcc-498083946.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
78711c898This file is pinned to the selected release. Download the original to open it in your design tool.
#-----------------------------------------------------------------
# pycparser: func_defs_add_param.py
#
# Example of rewriting AST nodes to add parameters to function
# definitions. Adds an "int _hidden" to every function.
#
# Eli Bendersky [https://eli.thegreenplace.net/]
# License: BSD
#-----------------------------------------------------------------
import sys
sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast, c_generator
text = r"""
void foo(int a, int b) {
}
void bar() {
}
"""
class ParamAdder(c_ast.NodeVisitor):
def visit_FuncDecl(self, node):
ty = c_ast.TypeDecl(declname='_hidden',
quals=[],
align=[],
type=c_ast.IdentifierType(['int']))
newdecl = c_ast.Decl(
name='_hidden',
quals=[],
align=[],
storage=[],
funcspec=[],
type=ty,
init=None,
bitsize=None,
coord=node.coord)
if node.args:
node.args.params.append(newdecl)
else:
node.args = c_ast.ParamList(params=[newdecl])
if __name__ == '__main__':
parser = c_parser.CParser()
ast = parser.parse(text)
print("AST before change:")
ast.show(offset=2)
v = ParamAdder()
v.visit(ast)
print("\nAST after change:")
ast.show(offset=2)
print("\nCode after change:")
generator = c_generator.CGenerator()
print(generator.visit(ast))