Browse Source

cppparser: Add special __builtin_va_list type

rdb 1 year ago
parent
commit
e16cb8af98

+ 15 - 2
dtool/src/cppparser/cppBison.yxx

@@ -262,6 +262,7 @@ pop_struct() {
 %token KW_BEGIN_PUBLISH
 %token KW_BLOCKING
 %token KW_BOOL
+%token KW_BUILTIN_VA_LIST
 %token KW_CATCH
 %token KW_CHAR
 %token KW_CHAR8_T
@@ -2626,6 +2627,10 @@ type:
         | KW_AUTO
 {
   $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
+}
+        | KW_BUILTIN_VA_LIST
+{
+  $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_va_list));
 }
         ;
 
@@ -2745,6 +2750,10 @@ type_decl:
         | KW_AUTO
 {
   $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
+}
+        | KW_BUILTIN_VA_LIST
+{
+  $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_va_list));
 }
         ;
 
@@ -2819,6 +2828,10 @@ predefined_type:
         | KW_AUTO
 {
   $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
+}
+        | KW_BUILTIN_VA_LIST
+{
+  $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_va_list));
 }
         ;
 
@@ -3295,8 +3308,8 @@ element:
         | TIMESEQUAL | DIVIDEEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL
         | OREQUAL | ANDEQUAL | XOREQUAL | LSHIFTEQUAL | RSHIFTEQUAL
         | ATTR_LEFT | ATTR_RIGHT
-        | KW_ALIGNAS | KW_ALIGNOF | KW_AUTO | KW_BOOL | KW_CATCH
-        | KW_CHAR | KW_CHAR8_T | KW_CHAR16_T | KW_CHAR32_T | KW_CLASS
+        | KW_ALIGNAS | KW_ALIGNOF | KW_AUTO | KW_BOOL | KW_BUILTIN_VA_LIST
+        | KW_CATCH | KW_CHAR | KW_CHAR8_T | KW_CHAR16_T | KW_CHAR32_T | KW_CLASS
         | KW_CONST | KW_CONSTEVAL | KW_CONSTEXPR | KW_CONSTINIT | KW_CONST_CAST
         | KW_DECLTYPE | KW_DEFAULT | KW_DELETE | KW_DOUBLE | KW_DYNAMIC_CAST
         | KW_ELSE | KW_ENUM | KW_EXTERN | KW_EXPLICIT | KW_EXPLICIT_LPAREN

+ 1 - 0
dtool/src/cppparser/cppPreprocessor.cxx

@@ -2743,6 +2743,7 @@ check_keyword(const string &name) {
   if (name == "__begin_publish") return KW_BEGIN_PUBLISH;
   if (name == "__blocking") return KW_BLOCKING;
   if (name == "bool") return KW_BOOL;
+  if (name == "__builtin_va_list") return KW_BUILTIN_VA_LIST;
   if (name == "catch") return KW_CATCH;
   if (name == "char") return KW_CHAR;
   if (name == "char8_t") return KW_CHAR8_T;

+ 8 - 4
dtool/src/cppparser/cppSimpleType.cxx

@@ -47,7 +47,7 @@ is_arithmetic() const {
  */
 bool CPPSimpleType::
 is_fundamental() const {
-  return (_type != T_unknown && _type != T_parameter && _type != T_auto);
+  return (_type != T_unknown && _type != T_parameter && _type != T_auto && _type != T_va_list);
 }
 
 /**
@@ -55,7 +55,7 @@ is_fundamental() const {
  */
 bool CPPSimpleType::
 is_standard_layout() const {
-  return (_type != T_unknown && _type != T_parameter && _type != T_auto);
+  return (_type != T_unknown && _type != T_parameter && _type != T_auto && _type != T_va_list);
 }
 
 /**
@@ -63,7 +63,7 @@ is_standard_layout() const {
  */
 bool CPPSimpleType::
 is_trivial() const {
-  return (_type != T_unknown && _type != T_parameter && _type != T_auto);
+  return (_type != T_unknown && _type != T_parameter && _type != T_auto && _type != T_va_list);
 }
 
 /**
@@ -71,7 +71,7 @@ is_trivial() const {
  */
 bool CPPSimpleType::
 is_trivially_copyable() const {
-  return (_type != T_unknown && _type != T_parameter && _type != T_auto);
+  return (_type != T_unknown && _type != T_parameter && _type != T_auto && _type != T_va_list);
 }
 
 /**
@@ -233,6 +233,10 @@ output(std::ostream &out, int, CPPScope *, bool) const {
     out << "auto";
     break;
 
+  case T_va_list:
+    out << "__builtin_va_list";
+    break;
+
   default:
     out << "***invalid type***";
   }

+ 3 - 0
dtool/src/cppparser/cppSimpleType.h

@@ -53,6 +53,9 @@ public:
     // determined at a later stage based on the type of the expression that is
     // assigned to it.
     T_auto,
+
+    // This is also a special built-in type.
+    T_va_list,
   };
 
   enum Flags {

+ 8 - 0
dtool/src/cppparser/cppToken.cxx

@@ -288,6 +288,10 @@ output(std::ostream &out) const {
     out << "KW_BOOL";
     break;
 
+  case KW_BUILTIN_VA_LIST:
+    out << "KW_BUILTIN_VA_LIST";
+    break;
+
   case KW_CATCH:
     out << "KW_CATCH";
     break;
@@ -940,6 +944,10 @@ output_code(std::ostream &out) const {
     out << "bool";
     break;
 
+  case KW_BUILTIN_VA_LIST:
+    out << "__builtin_va_list";
+    break;
+
   case KW_CATCH:
     out << "catch";
     break;

+ 5 - 0
dtool/src/parser-inc/cstdarg

@@ -0,0 +1,5 @@
+#pragma once
+
+namespace std {
+  typedef __builtin_va_list va_list;
+};

+ 1 - 1
dtool/src/parser-inc/stdarg.h

@@ -1,6 +1,6 @@
 #ifndef STDARG_H
 #define STDARG_H
 
-typedef struct {} va_list[1];
+typedef __builtin_va_list va_list;
 
 #endif