Class FunctionSignatureParser


  • public class FunctionSignatureParser
    extends java.lang.Object
    Class for parsing function signatures. This class attempts to be much more flexible than a full parser that requires correct C or C++ syntax. To achieve this, it scans the original function signature (if present) for names that would cause parse problems (parens, brackets, asterisk, commas, and spaces). If it finds any problem names, it looks for those strings in the text to be parsed and if it finds them, it replaces them with substitutes that parse easily. Then, after parsing, those replacement strings are then restored to their original values.

    Some examples of valid c++ that would fail due to the current limitations:

    void foo(myclass x) - fails due to comma in x's data type name int operator()(int x) - fails due to parens in function name unsigned int bar(float y) - fails due to space in return type name

    Note: you can edit signatures that already have these features as long as your modifications don't affect the pieces containing parens, commas or spaces in their name.

    • Constructor Detail

      • FunctionSignatureParser

        public FunctionSignatureParser​(DataTypeManager destDataTypeManager,
                                       DataTypeQueryService service)
        Constructs a SignatureParser for a program. The destDataTypeManager and/or service must be specified.
        Parameters:
        destDataTypeManager - the destination datatype maanger.
        service - the DataTypeManagerService to use for resolving datatypes that can't be found in the given program. Can be null to utilize program based types only.
    • Method Detail

      • parse

        public FunctionDefinitionDataType parse​(FunctionSignature originalSignature,
                                                java.lang.String signatureText)
                                         throws ghidra.app.util.cparser.C.ParseException,
                                                CancelledException
        Parse the given function signature text into a FunctionDefinitionDataType.
        Parameters:
        originalSignature - the function signature before editing. This may be null if the user is entering a new signature instead of editing an existing one.
        signatureText - the text to be parsed into a function signature.
        Returns:
        the FunctionDefinitionDataType resulting from parsing.
        Throws:
        ghidra.app.util.cparser.C.ParseException - if the text could not be parsed.
        CancelledException - if parse cancelled by user