Skip to content

Support defining macro categories for parsing. #64

@Ed94

Description

@Ed94

Determining what type a preprocessor macro is from parsing alone is non-trivial.

Macros can either be used as typenames, statements, attributes, etc.

Right now the library supports the user defining custom keywords/macros as specifiers or attributes, however macros beyond that are just distinguished if they are functional or not (take arguments).

This is problematic for macros that behave as statements but do not have an end statement token ;.

clang-format lets the user specify these distinctions in their specification file:

AttributeMacros: [
  GEN_API
]
StatementMacros: [
  GEN_NS_BEGIN, 
  GEN_NS_END, 
  GEN_NS_PARSER_BEGIN, 
  GEN_NS_PARSER_END, 
  GEN_API_C_BEGIN, 
  GEN_API_C_END,
  GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT
]
Macros:
- enum_underlying(type)=type
- gen_enum_underlying(type)=type
# WhitespaceSensitiveMacros: [
# ]

TypenameMacros: [Array, Hashtable]

gencpp should support in PreprocessorDefines indicating whether a macro should be considered a statement macro by expanding the Array type form a Str to a struct:

enum MacroType : u32
{
	// We cannot add specifiers or attributes here as they are handled by their respective enums, parsing, etc
	...
	Block_Start, // Indicating the start of a scope
	Block_End, // Indicating the end of a scope
	Statement, // Behaves a statement (may or may not have ; )
	Statement_With_Body, // Behaves a statement that expects a braced body after.
	Typename, // Macro that may be used as a typename
};

struct PreprocessorMacros
{
	MacroType  Type;
	b32        IsFunctional;
	StrCached  Name;
};

// and in context...
struct Context
{
	...
	// Rename: PreprocessorDefines -> PreprocessorMacros
	Array(PreprocessorMacro)	PreprocessorMacros;
	...
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions