compiler: Fixes to improve compatibility with MinGW/GCC 5 headers
[sdk] / compiler / libec / src / type.y
index 955fa61..5a50590 100644 (file)
@@ -2,6 +2,7 @@
 
 import "ecdefs"
 
+#define YYSIZE_T size_t
 #define YYLTYPE Location
 #include "grammar.h"
 
@@ -144,7 +145,7 @@ default:
 %token XOR_ASSIGN OR_ASSIGN TYPE_NAME
 
 %token TYPEDEF EXTERN STATIC AUTO REGISTER
-%token CHAR SHORT INT UINT INT64 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
+%token CHAR SHORT INT UINT INT64 INT128 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
 %token STRUCT UNION ENUM ELLIPSIS
 
 %token CASE DEFAULT IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
@@ -161,6 +162,8 @@ default:
 %token DBTABLE DBFIELD DBINDEX DATABASE_OPEN
 %token ALIGNOF ATTRIB_DEP __ATTRIB
 %token BOOL _BOOL _COMPLEX _IMAGINARY RESTRICT THREAD
+%token WIDE_STRING_LITERAL
+%token BUILTIN_OFFSETOF
 
 %destructor { FreeIdentifier($$); } identifier
 %destructor { FreePointer($$); } pointer
@@ -228,7 +231,7 @@ guess_type:
    identifier '*'
    {
       $$ = null;
-      DeclClass(0, $1.string);
+      DeclClass($1._class, $1.string);
       fileInput.Seek(@1.start.pos, start);
       resetScannerPos(&@1.start);
       yyclearin;
@@ -247,17 +250,7 @@ guess_type:
    {
       $$ = null;
    #ifdef PRECOMPILER
-      // if($1._class && !$1._class.name)
-      if($1._class)
-      {
-         char name[1024];
-         strcpy(name,  $1._class.name ? $1._class.name : "");
-         strcat(name, "::");
-         strcat(name, $1.string);
-         _DeclClass(0, name);
-      }
-      else
-         _DeclClass(0, $1.string);
+      _DeclClass($1._class, $1.string);
 
       FreeIdentifier($1);
 
@@ -279,7 +272,7 @@ guess_type:
 real_guess_type:
    identifier error
    {
-      DeclClass(0, $1.string);
+      DeclClass($1._class, $1.string);
       fileInput.Seek(@1.start.pos, start);
       parseTypeError = 0;
       resetScannerPos(&@1.start);
@@ -297,17 +290,7 @@ real_guess_type:
 /*   | identifier '<'
    {
    #ifdef PRECOMPILER
-      // if($1._class && !$1._class.name)
-      if($1._class)
-      {
-         char name[1024];
-         strcpy(name,  $1._class.name ? $1._class.name : "");
-         strcat(name, "::");
-         strcat(name, $1.string);
-         _DeclClass(0, name);
-      }
-      else
-         _DeclClass(0, $1.string);
+      _DeclClass($1._class, $1.string);
 
       FreeIdentifier($1);
 
@@ -331,7 +314,7 @@ type:
    | identifier identifier
    {
    #ifdef PRECOMPILER
-      DeclClass(0, $1.string);
+      DeclClass($1._class, $1.string);
       fileInput.Seek(@1.start.pos, start);
       resetScannerPos(&@1.start);
       yyclearin;
@@ -379,26 +362,26 @@ strict_type:
 
 class_function_definition_start:
      guess_declaration_specifiers declarator_function
-      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
    | declarator_function
-      { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; }
    ;
 
 constructor_function_definition_start:
    guess_declaration_specifiers '(' ')'
-      { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList /*FreeSpecifier*/($1, FreeSpecifier); }
+      { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($1, FreeSpecifier); }
    ;
 
 destructor_function_definition_start:
    '~' guess_declaration_specifiers '(' ')'
-      { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList /*FreeSpecifier*/($2, FreeSpecifier); }
+      { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($2, FreeSpecifier); }
    ;
 
 virtual_class_function_definition_start:
      VIRTUAL guess_declaration_specifiers declarator_function
-      { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; }
    | VIRTUAL declarator_function
-      { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; }
       ;
 
 identifier:
@@ -419,6 +402,7 @@ simple_primary_expression:
       { $$ = MkExpInstance($1); $$.loc = @$; }
        | CONSTANT
       { $$ = MkExpConstant(yytext); $$.loc = @$; }
+   | WIDE_STRING_LITERAL { $$ = MkExpWideString(yytext); $$.loc = @$; }
        | string_literal
       { $$ = MkExpString($1); delete $1; $$.loc = @$; }
    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
@@ -709,17 +693,7 @@ property_specifiers:
    | property_specifiers identifier          { ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2); }
    | identifier '<' template_arguments_list '>'
       {
-         // if($1._class && !$1._class.name)
-         if($1._class)
-         {
-            char name[1024];
-            strcpy(name,  $1._class.name ? $1._class.name : "");
-            strcat(name, "::");
-            strcat(name, $1.string);
-            _DeclClass(0, name);
-         }
-         else
-            _DeclClass(0, $1.string);
+         _DeclClass($1._class, $1.string);
 
          $$ = MkList();
          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
@@ -727,15 +701,7 @@ property_specifiers:
       }
    | property_specifiers identifier '<' template_arguments_list '>'
       {
-         if($2._class && !$2._class.name)
-         {
-            char name[1024];
-            strcpy(name, "::");
-            strcat(name, $2.string);
-            _DeclClass(0, name);
-         }
-         else
-            _DeclClass(0, $2.string);
+         _DeclClass($2._class, $2.string);
          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
          FreeIdentifier($2);
       }
@@ -756,17 +722,7 @@ renew_specifiers:
    | renew_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
    | identifier '<' template_arguments_list '>'
       {
-         // if($1._class && !$1._class.name)
-         if($1._class)
-         {
-            char name[1024];
-            strcpy(name,  $1._class.name ? $1._class.name : "");
-            strcat(name, "::");
-            strcat(name, $1.string);
-            _DeclClass(0, name);
-         }
-         else
-            _DeclClass(0, $1.string);
+         _DeclClass($1._class, $1.string);
 
          $$ = MkList();
          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
@@ -774,15 +730,7 @@ renew_specifiers:
       }
    | renew_specifiers identifier '<' template_arguments_list '>'
       {
-         if($2._class && !$2._class.name)
-         {
-            char name[1024];
-            strcpy(name, "::");
-            strcat(name, $2.string);
-            _DeclClass(0, name);
-         }
-         else
-            _DeclClass(0, $2.string);
+         _DeclClass($2._class, $2.string);
          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
          FreeIdentifier($2);
       }
@@ -862,6 +810,7 @@ type_specifier:
        | INT             { $$ = MkSpecifier(INT); }
    | UINT            { $$ = MkSpecifier(UINT); }
    | INT64           { $$ = MkSpecifier(INT64); }
+   | INT128          { $$ = MkSpecifier(INT128); }
    | VALIST          { $$ = MkSpecifier(VALIST); }
        | LONG            { $$ = MkSpecifier(LONG); }
        | FLOAT           { $$ = MkSpecifier(FLOAT); }
@@ -876,7 +825,7 @@ type_specifier:
        | type
    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
-   | SUBCLASS '(' identifier ')'          { _DeclClass(0, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
+   | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
    | TYPED_OBJECT    { $$ = MkSpecifier(TYPED_OBJECT); }
    | ANY_OBJECT      { $$ = MkSpecifier(ANY_OBJECT); }
@@ -889,6 +838,7 @@ strict_type_specifier:
        | INT             { $$ = MkSpecifier(INT); }
    | UINT            { $$ = MkSpecifier(UINT); }
    | INT64           { $$ = MkSpecifier(INT64); }
+   | INT128          { $$ = MkSpecifier(INT128); }
    | VALIST          { $$ = MkSpecifier(VALIST); }
        | LONG            { $$ = MkSpecifier(LONG); }
        | FLOAT           { $$ = MkSpecifier(FLOAT); }
@@ -903,36 +853,36 @@ strict_type_specifier:
        | strict_type
    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
-   | SUBCLASS '(' identifier ')'          { _DeclClass(0, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
+   | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
        ;
 
 
 struct_or_union_specifier_compound:
-         struct_or_union identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $2, $4); if(declMode) DeclClass(globalContext.nextID++, $2.string); }
+         struct_or_union identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $2, $4); if(declMode) DeclClass($2._class, $2.string); }
        | struct_or_union '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $3); }
-   | struct_or_union identifier '{' '}'   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass(globalContext.nextID++, $2.string); }
+   | struct_or_union identifier '{' '}'   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
    | struct_or_union '{' '}'              { $$ = MkStructOrUnion($1, null, null); }
        | struct_or_union base_strict_type '{' struct_declaration_list '}'
-      { $$ = MkStructOrUnion($1, MkIdentifier($2.name), $4); if(declMode) DeclClass(globalContext.nextID++, $2.name); FreeSpecifier($2); }
+      { $$ = MkStructOrUnion($1, MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
 
-       | struct_or_union ext_decl identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $3, $5); $$.extDeclStruct = $2; if(declMode) DeclClass(globalContext.nextID++, $3.string); }
+       | struct_or_union ext_decl identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $3, $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
        | struct_or_union ext_decl '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; }
-   | struct_or_union ext_decl identifier '{' '}'   { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2; if(declMode) DeclClass(globalContext.nextID++, $3.string); }
+   | struct_or_union ext_decl identifier '{' '}'   { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
    | struct_or_union ext_decl '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; }
        | struct_or_union ext_decl strict_type '{' struct_declaration_list '}'
-      { $$ = MkStructOrUnion($1, MkIdentifier($3.name), $5); $$.extDeclStruct = $2; if(declMode) DeclClass(globalContext.nextID++, $3.name); FreeSpecifier($3); }
+      { $$ = MkStructOrUnion($1, MkIdentifier($3.name), $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
        ;
 
 struct_or_union_specifier_nocompound:
-         struct_or_union identifier                                   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass(0, $2.string); }
+         struct_or_union identifier                                   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
        | struct_or_union strict_type
-      { $$ = MkStructOrUnion($1, MkIdentifier($2.name), null); if(declMode) DeclClass(0, $2.name); FreeSpecifier($2); }
+      { $$ = MkStructOrUnion($1, MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
 
        | struct_or_union ext_decl identifier
-      { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2;if(declMode) DeclClass(0, $3.string); }
+      { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2;if(declMode) DeclClass($3._class, $3.string); }
        | struct_or_union ext_decl strict_type
-      { $$ = MkStructOrUnion($1, MkIdentifier($3.name), null); $$.extDeclStruct = $2; if(declMode) DeclClass(0, $3.name); FreeSpecifier($3); }
+      { $$ = MkStructOrUnion($1, MkIdentifier($3.name), null); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
        ;
 
 template_datatype:
@@ -1079,7 +1029,7 @@ struct_declaration:
    | guess_instantiation_named ';'                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; }
    | class_function_definition                                       { $$ = MkClassDefFunction($1); $$.loc = @$; }
    | default_property_list ';' { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @2.start; $$.loc = @$; }
-   | property { $$ = MkClassDefProperty($1); $$.loc = @$; globalContext.nextID++; }
+   | property { $$ = MkClassDefProperty($1); $$.loc = @$; }
    | ';' { $$ = null; }
        ;
 
@@ -1104,17 +1054,17 @@ struct_declarator:
        ;
 
 enum_specifier_nocompound:
-     ENUM identifier                            { $$ = MkEnum($2, null); if(declMode) DeclClass(0, $2.string); }
-   | ENUM strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); if(declMode) DeclClass(0, $2.name); FreeSpecifier($2); }
+     ENUM identifier                            { $$ = MkEnum($2, null); if(declMode) DeclClass($2._class, $2.string); }
+   | ENUM strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
    ;
 
 enum_specifier_compound:
          ENUM '{' enumerator_list '}'
       { $$ = MkEnum(null, $3); }
-       | ENUM identifier '{' enumerator_list '}'    { $$ = MkEnum($2, $4); if(declMode) DeclClass(globalContext.nextID++, $2.string); }
-   | ENUM identifier '{' enumerator_list ';' struct_declaration_list '}'    { $$ = MkEnum($2, $4); $$.definitions = $6; if(declMode) DeclClass(globalContext.nextID++, $2.string); }
-       | ENUM strict_type '{' enumerator_list ';' struct_declaration_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.definitions = $6; if(declMode) DeclClass(globalContext.nextID++, $2.name); FreeSpecifier($2); }
-   | ENUM strict_type '{' enumerator_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); if(declMode) DeclClass(globalContext.nextID++, $2.name); FreeSpecifier($2); }
+       | ENUM identifier '{' enumerator_list '}'    { $$ = MkEnum($2, $4); if(declMode) DeclClass($2._class, $2.string); }
+   | ENUM identifier '{' enumerator_list ';' struct_declaration_list '}'    { $$ = MkEnum($2, $4); $$.definitions = $6; if(declMode) DeclClass($2._class, $2.string); }
+       | ENUM strict_type '{' enumerator_list ';' struct_declaration_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.definitions = $6; if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
+   | ENUM strict_type '{' enumerator_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
        ;
 
 enumerator_list:
@@ -1580,9 +1530,9 @@ class_function_definition:
 instance_class_function_definition_start:
    // Guess here conflicts with an expression...
      declaration_specifiers declarator_function
-      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
     | declaration_specifiers declarator_nofunction
-      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
+      { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
       ;
 
 instance_class_function_definition: