changeset 254:ec0379c33f9e

[project @ 2003-04-26 21:28:09 by bellard] added __builtin_constant_p() and __builtin_types_compatible_p() support
author bellard
date Sat, 26 Apr 2003 21:28:09 +0000
parents f9674d902bbf
children e02822de9d86
files tcc.c tcctok.h
diffstat 2 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Sat Apr 26 20:52:38 2003 +0000
+++ b/tcc.c	Sat Apr 26 21:28:09 2003 +0000
@@ -6593,6 +6593,17 @@
     skip(')');
 }
 
+static void parse_type(CType *type)
+{
+    AttributeDef ad;
+    int n;
+
+    if (!parse_btype(type, &ad)) {
+        expect("type");
+    }
+    type_decl(type, &ad, &n, TYPE_ABSTRACT);
+}
+
 static void vpush_tokc(int t)
 {
     CType type;
@@ -6777,7 +6788,36 @@
             vpushi(align);
         }
         break;
-        
+
+    case TOK_builtin_types_compatible_p:
+        {
+            CType type1, type2;
+            next();
+            skip('(');
+            parse_type(&type1);
+            skip(',');
+            parse_type(&type2);
+            skip(')');
+            type1.t &= ~(VT_CONSTANT | VT_VOLATILE);
+            type2.t &= ~(VT_CONSTANT | VT_VOLATILE);
+            vpushi(is_compatible_types(&type1, &type2));
+        }
+        break;
+    case TOK_builtin_constant_p:
+        {
+            int saved_nocode_wanted, res;
+            next();
+            skip('(');
+            saved_nocode_wanted = nocode_wanted;
+            nocode_wanted = 1;
+            gexpr();
+            res = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
+            vpop();
+            nocode_wanted = saved_nocode_wanted;
+            skip(')');
+            vpushi(res);
+        }
+        break;
     case TOK_INC:
     case TOK_DEC:
         t = tok;
@@ -7274,14 +7314,14 @@
 /* parse an expression and return its type without any side effect. */
 static void expr_type(CType *type)
 {
-    int a;
-
-    a = nocode_wanted;
+    int saved_nocode_wanted;
+
+    saved_nocode_wanted = nocode_wanted;
     nocode_wanted = 1;
     gexpr();
     *type = vtop->type;
     vpop();
-    nocode_wanted = a;
+    nocode_wanted = saved_nocode_wanted;
 }
 
 /* parse a unary expression and return its type without any side
--- a/tcctok.h	Sat Apr 26 20:52:38 2003 +0000
+++ b/tcctok.h	Sat Apr 26 21:28:09 2003 +0000
@@ -100,6 +100,8 @@
      DEF(TOK_STDCALL3, "__stdcall__")
      DEF(TOK_NORETURN1, "noreturn")
      DEF(TOK_NORETURN2, "__noreturn__")
+     DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
+     DEF(TOK_builtin_constant_p, "__builtin_constant_p")
 
 /* builtin functions or variables */
      DEF(TOK_memcpy, "memcpy")