This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 36fde7cf3 chore(c++): remove unique token from FORY_FIELD_CONFIG 
(#3228)
36fde7cf3 is described below

commit 36fde7cf3b47626d6f1c54c07527553806a2581c
Author: Shawn Yang <[email protected]>
AuthorDate: Tue Jan 27 22:31:41 2026 +0800

    chore(c++): remove unique token from FORY_FIELD_CONFIG (#3228)
    
    ## Why?
    
    
    
    ## What does this PR do?
    
    
    
    ## Related issues
    
    
    
    ## Does this PR introduce any user-facing change?
    
    
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
---
 compiler/fory_compiler/generators/cpp.py       | 21 +++++++-----------
 cpp/fory/meta/field.h                          | 24 +++++++++++----------
 cpp/fory/serialization/namespace_macro_test.cc |  4 ++--
 cpp/fory/serialization/xlang_test_main.cc      | 30 +++++++++++++-------------
 4 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/compiler/fory_compiler/generators/cpp.py 
b/compiler/fory_compiler/generators/cpp.py
index 5bc4ab8fc..89ee65b8e 100644
--- a/compiler/fory_compiler/generators/cpp.py
+++ b/compiler/fory_compiler/generators/cpp.py
@@ -17,7 +17,7 @@
 
 """C++ code generator."""
 
-from typing import Dict, List, Optional, Set, Tuple
+from typing import Dict, List, Optional, Set
 import typing
 
 from fory_compiler.generators.base import BaseGenerator, GeneratedFile
@@ -120,15 +120,13 @@ class CppGenerator(BaseGenerator):
             return f"{namespace}::{qualified_name}"
         return qualified_name
 
-    def get_field_config_type_and_alias(
+    def get_field_config_type(
         self,
         type_name: str,
         parent_stack: List[Message],
-    ) -> Tuple[str, str]:
-        """Get type name and token-safe alias for FORY_FIELD_CONFIG."""
-        qualified_name = self.get_namespaced_type_name(type_name, parent_stack)
-        alias = f"ForyType_{qualified_name.replace('::', '_')}"
-        return qualified_name, alias
+    ) -> str:
+        """Get type name for FORY_FIELD_CONFIG."""
+        return self.get_namespaced_type_name(type_name, parent_stack)
 
     def generate_header(self) -> GeneratedFile:
         """Generate a C++ header file with all types."""
@@ -784,13 +782,11 @@ class CppGenerator(BaseGenerator):
             field_members = ", ".join(
                 self.get_field_member_name(f) for f in message.fields
             )
-            field_config_type_name = self.get_field_config_type_and_alias(
+            field_config_type_name = self.get_field_config_type(
                 message.name, parent_stack
             )
             field_config_macros.append(
-                self.generate_field_config_macro(
-                    message, field_config_type_name[0], 
field_config_type_name[1]
-                )
+                self.generate_field_config_macro(message, 
field_config_type_name)
             )
             lines.append(
                 f"{body_indent}FORY_STRUCT({struct_type_name}, 
{field_members});"
@@ -1348,7 +1344,6 @@ class CppGenerator(BaseGenerator):
         self,
         message: Message,
         qualified_name: str,
-        alias_name: str,
     ) -> str:
         """Generate FORY_FIELD_CONFIG macro for a message."""
         entries = []
@@ -1357,7 +1352,7 @@ class CppGenerator(BaseGenerator):
             meta = self.get_field_meta(field)
             entries.append(f"({field_name}, {meta})")
         joined = ", ".join(entries)
-        return f"FORY_FIELD_CONFIG({qualified_name}, {alias_name}, {joined});"
+        return f"FORY_FIELD_CONFIG({qualified_name}, {joined});"
 
     def get_field_meta(self, field: Field) -> str:
         """Build FieldMeta expression for a field."""
diff --git a/cpp/fory/meta/field.h b/cpp/fory/meta/field.h
index 43b91dd99..374855e8c 100644
--- a/cpp/fory/meta/field.h
+++ b/cpp/fory/meta/field.h
@@ -1389,11 +1389,11 @@ public:
 // ============================================================================
 //
 // Usage:
-//   FORY_FIELD_CONFIG(MyStruct, MyStruct,
-//       (field1, F(0)),                        // Simple: just ID
-//       (field2, F(1).nullable()),             // With nullable
-//       (field3, F(2).varint()),               // With encoding
-//       (field4, F(3).nullable().ref()),       // Multiple options
+//   FORY_FIELD_CONFIG(MyStruct,
+//       (field1, fory::F(0)),                  // Simple: just ID
+//       (field2, fory::F(1).nullable()),       // With nullable
+//       (field3, fory::F(2).varint()),         // With encoding
+//       (field4, fory::F(3).nullable().ref()), // Multiple options
 //       (field5, 4)                            // Backward compatible: integer
 //       ID
 //   );
@@ -1908,11 +1908,13 @@ public:
 
 // Main FORY_FIELD_CONFIG macro
 // Creates a constexpr tuple of FieldEntry objects with member pointer
-// verification. Alias is a token-safe name without '::'.
-#define FORY_FC_DESCRIPTOR_NAME(Alias)                                         
\
-  FORY_PP_CONCAT(ForyFieldConfigDescriptor_, Alias)
-#define FORY_FIELD_CONFIG(Type, Alias, ...)                                    
\
-  struct FORY_FC_DESCRIPTOR_NAME(Alias) {                                      
\
+// verification. Descriptor name uses a unique line-based token.
+#define FORY_FC_DESCRIPTOR_NAME(line)                                          
\
+  FORY_PP_CONCAT(ForyFieldConfigDescriptor_, line)
+#define FORY_FIELD_CONFIG(Type, ...)                                           
\
+  FORY_FIELD_CONFIG_IMPL(__LINE__, Type, __VA_ARGS__)
+#define FORY_FIELD_CONFIG_IMPL(line, Type, ...)                                
\
+  struct FORY_FC_DESCRIPTOR_NAME(line) {                                       
\
     static constexpr bool has_config = true;                                   
\
     static inline constexpr auto entries =                                     
\
         std::make_tuple(FORY_FC_ENTRIES(Type, __VA_ARGS__));                   
\
@@ -1920,6 +1922,6 @@ public:
         std::tuple_size_v<std::decay_t<decltype(entries)>>;                    
\
   };                                                                           
\
   constexpr auto ForyFieldConfig(::fory::meta::Identity<Type>) {               
\
-    return FORY_FC_DESCRIPTOR_NAME(Alias){};                                   
\
+    return FORY_FC_DESCRIPTOR_NAME(line){};                                    
\
   }                                                                            
\
   static_assert(true)
diff --git a/cpp/fory/serialization/namespace_macro_test.cc 
b/cpp/fory/serialization/namespace_macro_test.cc
index 1676e83a0..a508f57c6 100644
--- a/cpp/fory/serialization/namespace_macro_test.cc
+++ b/cpp/fory/serialization/namespace_macro_test.cc
@@ -125,9 +125,9 @@ public:
 
 FORY_ENUM(EnumContainer::Kind, Alpha, Beta);
 
-FORY_FIELD_CONFIG(Configured, Configured, (id_, fory::F().id(1).varint()));
+FORY_FIELD_CONFIG(Configured, (id_, fory::F().id(1).varint()));
 FORY_FIELD_TAGS(OptionalHolder, (name_, 1));
-FORY_FIELD_CONFIG(Partial, Partial, (count_, fory::F().id(7).varint()));
+FORY_FIELD_CONFIG(Partial, (count_, fory::F().id(7).varint()));
 FORY_FIELD_TAGS(Partial, (id_, 5));
 
 FORY_UNION(Choice, (std::string, text, fory::F(1)),
diff --git a/cpp/fory/serialization/xlang_test_main.cc 
b/cpp/fory/serialization/xlang_test_main.cc
index 3a05997d8..a2d954f28 100644
--- a/cpp/fory/serialization/xlang_test_main.cc
+++ b/cpp/fory/serialization/xlang_test_main.cc
@@ -600,7 +600,6 @@ struct UnsignedSchemaConsistentSimple {
   FORY_STRUCT(UnsignedSchemaConsistentSimple, u64Tagged, u64TaggedNullable);
 };
 FORY_FIELD_CONFIG(UnsignedSchemaConsistentSimple,
-                  UnsignedSchemaConsistentSimple,
                   (u64Tagged, fory::F().tagged()),
                   (u64TaggedNullable, fory::F().nullable().tagged()));
 
@@ -649,9 +648,8 @@ struct UnsignedSchemaConsistent {
               u64TaggedNullableField);
 };
 // Use new FORY_FIELD_CONFIG with builder pattern for encoding specification
-FORY_FIELD_CONFIG(UnsignedSchemaConsistent, UnsignedSchemaConsistent,
-                  (u8Field, fory::F()), (u16Field, fory::F()),
-                  (u32VarField, fory::F().varint()),
+FORY_FIELD_CONFIG(UnsignedSchemaConsistent, (u8Field, fory::F()),
+                  (u16Field, fory::F()), (u32VarField, fory::F().varint()),
                   (u32FixedField, fory::F().fixed()),
                   (u64VarField, fory::F().varint()),
                   (u64FixedField, fory::F().fixed()),
@@ -710,17 +708,19 @@ struct UnsignedSchemaCompatible {
 // Use new FORY_FIELD_CONFIG with builder pattern for encoding specification
 // Group 1: nullable in C++ (std::optional), non-nullable in Java
 // Group 2: non-nullable in C++, nullable in Java
-FORY_FIELD_CONFIG(
-    UnsignedSchemaCompatible, UnsignedSchemaCompatible,
-    (u8Field1, fory::F().nullable()), (u16Field1, fory::F().nullable()),
-    (u32VarField1, fory::F().nullable().varint()),
-    (u32FixedField1, fory::F().nullable().fixed()),
-    (u64VarField1, fory::F().nullable().varint()),
-    (u64FixedField1, fory::F().nullable().fixed()),
-    (u64TaggedField1, fory::F().nullable().tagged()), (u8Field2, fory::F()),
-    (u16Field2, fory::F()), (u32VarField2, fory::F().varint()),
-    (u32FixedField2, fory::F().fixed()), (u64VarField2, fory::F().varint()),
-    (u64FixedField2, fory::F().fixed()), (u64TaggedField2, 
fory::F().tagged()));
+FORY_FIELD_CONFIG(UnsignedSchemaCompatible, (u8Field1, fory::F().nullable()),
+                  (u16Field1, fory::F().nullable()),
+                  (u32VarField1, fory::F().nullable().varint()),
+                  (u32FixedField1, fory::F().nullable().fixed()),
+                  (u64VarField1, fory::F().nullable().varint()),
+                  (u64FixedField1, fory::F().nullable().fixed()),
+                  (u64TaggedField1, fory::F().nullable().tagged()),
+                  (u8Field2, fory::F()), (u16Field2, fory::F()),
+                  (u32VarField2, fory::F().varint()),
+                  (u32FixedField2, fory::F().fixed()),
+                  (u64VarField2, fory::F().varint()),
+                  (u64FixedField2, fory::F().fixed()),
+                  (u64TaggedField2, fory::F().tagged()));
 
 namespace fory {
 namespace serialization {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to