Visitor Class (Option Processing)
All the functions will receive an options parameter which is an instance of the Option class. The properties used in the filters from this class are:
txt- This property is a string representing the entire option.args- This is a list of arguments to the option. Usually only the first item is referenced.
The filter visitors will inherit either from QAVisitor or, if they are GNU based or want to use some GNU features, from QAGNUVisitor.
Default Parser Options
In the constructor for the visitor class, some default options can be specified. For example, this class inherits from the GNU visitor and changes the list to the value correct for this compiler:
class QAWindRiverVisitor(QAGnuVisitor):
def __init__(self):
debug("QAWindRiverVisitor::__init__()")
super(QAWindRiverVisitor, self).__init__()
# Same parser_options as GNU but without -ex dollar -
self._qac_parser_options = {'bits': False, 'u': False}
Unless modified later, this CCT will have the following lines generated in the CCT:
If the default value for -u was supposed to be -u+ then False would be replaced with True:
This example only sets the list of options for a C CCT. Another member variable is _qacpp_parser_options which is used for generating a C++ CCT.
Option Processing
To add processing for an option, add a function to the visitor class with the name visit and an underscore added to the start. Replace any minus signs in the middle of the option (not leading ones) with an underscore. For example, to process the --signed-bitfields option, the GNU visitor has this code:
The call to _set_option will enable that option (if it exists in the list of options for the current language).
To set an option that does not have a default initial value, use the _set_option_always as used in this example:
Input File Name and Ignoring Files
The function visit_input_file_name is called for any input file names on the command line. It is generally used to make the CCT generator ignore assembler processing. For example:
def visit_input_file_name(self, option):
if option.txt.upper().endswith('.S'):
# armclang examples have .S files for assembler.
debug("ArmClang filter stopping for assembly file: " + option.txt)
self.visit_stop_after_preprocess(option)
else:
super(QAArmClangVisitor, self).visit_input_file_name(option)
The function visit_stop_after_preprocess will stop any further processing of the command line.
Option Aliases
When inheriting from QAVistor, a list of aliases can be set:
class _QARenesasVisitor(QAVisitor):
_aliases = {
# cc-rh uses Xpreinclude. cc-rl uses preinclude.
'preinclude': ['Xpreinclude'],
}
If the filters visitor class inherits from QAGNUVisitor, it can add to the default list with the add_alias function:
This filter will execute the visit_signed_bitfields code when the option -Xbit-fields-signed is seen. Note that, any options used must be added to the filter_init function in the non_gnu_options parameter:
filter_init(
"DIAB",
non_gnu_options={
'Xbit-fields-signed': [0],
'Xdollar-in-ident': [0],
'Xpreprocess-assembly': [0],
},
)
If the visitor class does not inherit from the GNU Visitor, the compiler_options setting can be used instead to specify the options. In this case, it will be a complete list of options available rather than appending to the default GNU options.