def test_cpp_value_as_str(): 'Make sure we can generate a str from a value - this will be important for errors' v1 = crep.cpp_value('dude', top_level_scope(), ctyp.terminal('int')) assert 'dude' in str(v1) v2 = crep.cpp_value('dude', top_level_scope(), None) assert 'dude' in str(v2)
def test_variable_pointer_2(): 'Make sure p_depth can deal with a non-type correctly' v1 = crep.cpp_value('dude', top_level_scope(), ctyp.terminal('int')) v2 = crep.cpp_value('dude', top_level_scope(), None) assert v1.cpp_type().type == 'int' with pytest.raises(RuntimeError): v2.cpp_type()
async def exe_from_qastle(q: str): 'Dummy executor that will return the ast properly rendered. If qastle_roundtrip is true, then we will round trip the ast via qastle first.' # Round trip qastle if requested. import qastle a = qastle.text_ast_to_python_ast(q).body[0].value # Setup the rep for this filter from func_adl import find_EventDataset file = find_EventDataset(a) iterator = cpp_variable("bogus-do-not-use", top_level_scope(), cpp_type=None) set_rep(file, cpp_sequence(iterator, iterator, top_level_scope())) # Use the dummy executor to process this, and return it. exe = atlas_xaod_dummy_executor() exe.evaluate(a) return exe
async def execute_result_async(self, a: ast.AST, title: str) -> Any: 'Dummy executor that will return the ast properly rendered. If qastle_roundtrip is true, then we will round trip the ast via qastle first.' # Round trip qastle if requested. if self._q_roundtrip: import qastle print(f'before: {ast.dump(a)}') a_text = qastle.python_ast_to_text_ast(a) a = qastle.text_ast_to_python_ast(a_text).body[0].value print(f'after: {ast.dump(a)}') # Setup the rep for this dataset from func_adl import find_EventDataset file = find_EventDataset(a) iterator = cpp_variable("bogus-do-not-use", top_level_scope(), cpp_type=None) set_rep(file, cpp_sequence(iterator, iterator, top_level_scope())) # Use the dummy executor to process this, and return it. exe = self.get_dummy_executor_obj() exe.evaluate(a) return exe
def write_cpp_files(self, ast: ast.AST, output_path: Path) -> ExecutionInfo: r""" Given the AST generate the C++ files that need to run. Return them along with the input files. """ # Find the base file dataset and mark it. from func_adl import find_EventDataset file = find_EventDataset(ast) iterator = crep.cpp_variable("bogus-do-not-use", top_level_scope(), cpp_type=None) crep.set_rep(file, crep.cpp_sequence(iterator, iterator, top_level_scope())) # Visit the AST to generate the code structure and find out what the # result is going to be. qv = self.get_visitor_obj() result_rep = qv.get_rep(ast) if _is_format_request(ast) \ else qv.get_as_ROOT(ast) # Emit the C++ code into our dictionaries to be used in template generation below. query_code = _cpp_source_emitter() qv.emit_query(query_code) book_code = _cpp_source_emitter() qv.emit_book(book_code) class_decl_code = qv.class_declaration_code() includes = qv.include_files() + self.body_include_files link_libraries = qv.link_libraries() + self.link_libraries # The replacement dict to pass to the template generator can now be filled info = {} info['query_code'] = query_code.lines_of_query_code() info['class_decl'] = class_decl_code info['book_code'] = book_code.lines_of_query_code() info['body_include_files'] = includes info['header_include_files'] = self.header_include_files info['private_members'] = self.private_members info['instance_initialization'] = self.instance_initialization info['initialize_lines'] = self.initialize_lines info['ctor_lines'] = self.ctor_lines info['link_libraries'] = link_libraries info.update(self.add_to_replacement_dict()) # We use jinja2 templates. Write out everything. template_dir = _find_dir(self._template_dir_name) j2_env = jinja2.Environment( loader=jinja2.FileSystemLoader(template_dir)) for file_name in self._file_names: self._copy_template_file(j2_env, info, file_name, output_path) (output_path / self._runner_name).chmod(0o755) # Reset our object for the next call (e.g. reset global state) self.reset() # Build the return object. return ExecutionInfo(result_rep, output_path, self._runner_name, self._file_names)
def test_expression_pointer_decl(): e2 = crep.cpp_value("dude", top_level_scope(), ctyp.terminal("int")) assert e2.p_depth == 0 e3 = crep.cpp_value("dude", top_level_scope(), ctyp.terminal("int", p_depth=1)) assert e3.p_depth == 1