Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Ignore litgen warnings

When processing code, litgen may emit some warnings when it encounters code that it cannot process. If possible, you can change the options in order to handle those warnings.

Example code with potential warnings

However, there may be some warnings that you want to ignore. See the example below, where we use the code from a file name 10_05_10_sample_code.h.

Let’s load it and display its content:

import litgen
from litgen.demo import litgen_demo

with open("10_05_10_sample_code.h") as f:
    cpp_code = f.read()

litgen_demo.show_cpp_code(cpp_code)
Loading...

Warnings emitted by litgen

Now, let’s process it with litgen, and see that we encounter many warnings:

options = litgen.LitgenOptions()
generated_code = litgen.generate_code_for_file(options, "10_05_10_sample_code.h")
Warning: (SrcmlcppIgnoreElement) A cpp element of type "function" was stored as CppUnprocessed. Details follow
Warning: (SrcmlcppIgnoreElement) Can't use a function_decl as a param.
While parsing a "function_decl", corresponding to this C++ code:
10_05_10_sample_code.h:21:19
    int CallOperation(int (*functionPtr)(int, int), int a, int b) {
                      ^

Warning: (LitgenBlockElementException) Warning: (LitgenBlockElementException) operators are supported only when implemented as a member functions
While parsing a "function_decl", corresponding to this C++ code:
10_05_10_sample_code.h:16:1
    bool operator==(const Foo& v1, const Foo& v2);
    ^

Warning: (LitgenTemplateFunctionIgnore) Ignoring template function MyOperation. You might need to set LitgenOptions.fn_template_options
While parsing a "function_decl", corresponding to this C++ code:
10_05_10_sample_code.h:7:1
    template<typename T> void MyOperation(T value);
    ^
Warning: (LitgenTemplateFunctionIgnore) Ignoring template function MyOperation. You might need to set LitgenOptions.fn_template_options
While parsing a "function_decl", corresponding to this C++ code:
10_05_10_sample_code.h:7:1
    template<typename T> void MyOperation(T value);
    ^

Suppress the warnings

Once you studied the warnings, and once you know they are harlmess, you can suppress them by filling options.srcmlcpp_options.ignored_warning_parts.

options = litgen.LitgenOptions()
options.srcmlcpp_options.ignored_warning_parts.append("Can't use a function_decl as a param")
options.srcmlcpp_options.ignored_warning_parts.append(
    "operators are supported only when implemented as a member functions"
)
options.srcmlcpp_options.ignored_warning_parts.append("Ignoring template function MyOperation")

# The next line does not emit warnings anymore
generated_code = litgen.generate_code_for_file(options, "10_05_10_sample_code.h")

# The generated code will include only what was correctly converted
litgen_demo.show_python_code(generated_code.stub_code)
Loading...