mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-11-03 23:36:12 -08:00 
			
		
		
		
	Unreal parsing support: Added MF_Allow_As_Attribute & MF_Allow_As_Definition
This commit is contained in:
		@@ -204,6 +204,7 @@ internal CodeBody           parse_global_nspace                ( CodeType which
 | 
			
		||||
internal Code               parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers );
 | 
			
		||||
internal Token              parse_identifier                   ( bool* possible_member_function );
 | 
			
		||||
internal CodeInclude        parse_include                      ();
 | 
			
		||||
internal Code               parse_macro_as_definiton           ( CodeAttributes attributes, CodeSpecifiers specifiers );
 | 
			
		||||
internal CodeOperator       parse_operator_after_ret_type      ( ModuleFlag mflags, CodeAttributes attributes, CodeSpecifiers specifiers, CodeTypename ret_type );
 | 
			
		||||
internal Code               parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers );
 | 
			
		||||
internal CodePragma         parse_pragma                       ();
 | 
			
		||||
@@ -578,7 +579,7 @@ CodeAttributes parse_attributes()
 | 
			
		||||
	s32   len   = 0;
 | 
			
		||||
 | 
			
		||||
	// There can be more than one attribute. If there is flatten them to a single string.
 | 
			
		||||
	// TODO(Ed): Support keeping an linked list of attributes similar to parameters
 | 
			
		||||
	// TODO(Ed): Support chaining attributes (Use parameter linkage pattern)
 | 
			
		||||
	while ( left && tok_is_attribute(currtok) )
 | 
			
		||||
	{
 | 
			
		||||
		if ( check( Tok_Attribute_Open ) )
 | 
			
		||||
@@ -2434,6 +2435,12 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
 | 
			
		||||
 | 
			
		||||
	Code result = InvalidCode;
 | 
			
		||||
 | 
			
		||||
	Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
 | 
			
		||||
	if (macro_stmt) {
 | 
			
		||||
		parser_pop(& _ctx->parser);
 | 
			
		||||
		return macro_stmt;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	CodeTypename type = parser_parse_type( parser_not_from_template, nullptr );
 | 
			
		||||
	// <Attributes> <Specifiers> <ReturnType/ValueType>
 | 
			
		||||
 | 
			
		||||
@@ -2506,6 +2513,36 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal
 | 
			
		||||
Code parse_macro_as_definiton( CodeAttributes attributes, CodeSpecifiers specifiers )
 | 
			
		||||
{
 | 
			
		||||
	push_scope();
 | 
			
		||||
 | 
			
		||||
	if (currtok.Type != Tok_Preprocess_Macro_Stmt ) {
 | 
			
		||||
		parser_pop(& _ctx->parser);
 | 
			
		||||
		return NullCode;
 | 
			
		||||
	}
 | 
			
		||||
	Macro* macro                     = lookup_macro(currtok.Text);
 | 
			
		||||
	b32    can_resolve_to_definition = macro && bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Definition);
 | 
			
		||||
	if ( ! can_resolve_to_definition) {
 | 
			
		||||
		parser_pop(& _ctx->parser);
 | 
			
		||||
		return NullCode;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TODO(Ed): When AST_Macro is made, have it support attributs and specifiers for when its behaving as a declaration/definition.
 | 
			
		||||
	Code code = parse_simple_preprocess( Tok_Preprocess_Macro_Stmt );
 | 
			
		||||
 | 
			
		||||
	// Attributes and sepcifiers will be collapsed into the macro's serialization.
 | 
			
		||||
	StrBuilder resolved_definition = strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S %S %S"
 | 
			
		||||
		, attributes ? strbuilder_to_str( attributes_to_strbuilder(attributes)) : txt("")
 | 
			
		||||
		, specifiers ? strbuilder_to_str( specifiers_to_strbuilder(specifiers)) : txt("")
 | 
			
		||||
		, code->Content
 | 
			
		||||
	);
 | 
			
		||||
	Code result = untyped_str( strbuilder_to_str(resolved_definition) );
 | 
			
		||||
	parser_pop(& _ctx->parser);
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal
 | 
			
		||||
CodePragma parse_pragma()
 | 
			
		||||
{
 | 
			
		||||
@@ -3761,8 +3798,11 @@ CodeEnum parser_parse_enum( bool inplace_def )
 | 
			
		||||
 | 
			
		||||
					// Unreal UMETA macro support
 | 
			
		||||
					if ( currtok.Type == Tok_Preprocess_Macro_Expr ) {
 | 
			
		||||
						eat( Tok_Preprocess_Macro_Expr );
 | 
			
		||||
						Code macro = parse_simple_preprocess( Tok_Preprocess_Macro_Expr );
 | 
			
		||||
						// <Name> = <Expression> <Macro>
 | 
			
		||||
 | 
			
		||||
						// We're intentially ignoring this code as its going to be serialized as an untyped string with the rest of the enum "entry".
 | 
			
		||||
						// TODO(Ed): We need a CodeEnumEntry, AST_EnumEntry types
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					if ( currtok.Type == Tok_Comma )
 | 
			
		||||
@@ -4060,6 +4100,13 @@ CodeFn parser_parse_function()
 | 
			
		||||
	}
 | 
			
		||||
	// <export> <Attributes> <Specifiers>
 | 
			
		||||
 | 
			
		||||
	// Note(Ed): We're enforcing that using this codepath requires non-macro jank.
 | 
			
		||||
	// Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
 | 
			
		||||
	// if (macro_stmt) {
 | 
			
		||||
	// 	parser_pop(& _ctx->parser);
 | 
			
		||||
	// 	return macro_stmt;
 | 
			
		||||
	// }
 | 
			
		||||
 | 
			
		||||
	CodeTypename ret_type = parser_parse_type(parser_not_from_template, nullptr);
 | 
			
		||||
	if ( cast(Code, ret_type) == Code_Invalid ) {
 | 
			
		||||
		parser_pop(& _ctx->parser);
 | 
			
		||||
@@ -5448,6 +5495,13 @@ CodeVar parser_parse_variable()
 | 
			
		||||
	}
 | 
			
		||||
	// <ModuleFlags> <Attributes> <Specifiers>
 | 
			
		||||
 | 
			
		||||
	// Note(Ed): We're enforcing that using this codepath requires non-macro jank.
 | 
			
		||||
	// Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
 | 
			
		||||
	// if (macro_stmt) {
 | 
			
		||||
	// 	parser_pop(& _ctx->parser);
 | 
			
		||||
	// 	return macro_stmt;
 | 
			
		||||
	// }
 | 
			
		||||
 | 
			
		||||
	CodeTypename type = parser_parse_type(parser_not_from_template, nullptr);
 | 
			
		||||
	// <ModuleFlags> <Attributes> <Specifiers> <ValueType>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user