def test_collect_includes_with_define_function_like(self): node = pre_ast.DefineFunctionLike( name='some_name', arguments='some_arguments', replacement='some_replacement', ) actual = self.include_collector.collect_includes(node) expected = [] self.assertEqual(actual, expected)
def test_parse_define_empty_funcion_like(self): source = '#define foo()' actual = self.parser.parse(source) expected = pre_ast.CompositeBlock([ pre_ast.DefineFunctionLike( name='foo', arguments=[], replacement="", ), ]) self.assertASTEqual(actual, expected)
def test_parse_define_with_function_like_expression_and_concatenation( self): source = '#define __DECL_REG(name) uint64_t r ## name;' actual = self.parser.parse(source) expected = pre_ast.CompositeBlock([ pre_ast.DefineFunctionLike( name='__DECL_REG', arguments=["name"], replacement='uint64_t r ## name;', ), ]) self.assertASTEqual(actual, expected)
def __init__(self, config_flags=None): self.config_flags = config_flags or {} self.object_likes = {} # Macro function_likes. self.function_likes = {} # Built in functions. self.functions = {} # Defined is a built in keyword. self.symbols = set(["defined"] + EXCLUDED_FUNCTION_LIKE) # Initialize the MacroManager. self.add_object_likes(**self._get_object_like_macros()) self.add_functions(**functions.get_arithmetic_functions()) for name, args, repl in STANDARD_FUNCTION_LIKE: self.add_function_like( name, pre_ast.DefineFunctionLike(name, args, repl))
def _add_function_like(self, tok): self.current_node.content.append( pre_ast.DefineFunctionLike(name=tok.name, arguments=tok.arguments.asList(), replacement=tok.replacement.strip()))