]> git.gag.com Git - fw/sdcc/commitdiff
added __typeof extention will return type of a variable / expression
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 21 Nov 2001 17:10:33 +0000 (17:10 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 21 Nov 2001 17:10:33 +0000 (17:10 +0000)
as enumerated in typeof.h

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1627 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCC.lex
src/SDCC.y
src/SDCCast.c
src/SDCCglobl.h
src/SDCCmain.c
src/SDCCsymt.h

index 447560518ff3d0164067cbf819495b8e3751ae87..b9aafd72112dabe0b186328ee83d92d0a9d5b1af 100644 (file)
@@ -171,6 +171,7 @@ struct options  save_options  ;
 "while"        { count(); return(WHILE); }
 "xdata"        { count(); TKEYWORD(XDATA); }
 "..."         { count(); return(VAR_ARGS);}
+"__typeof"     { count(); return TYPEOF;}
 {L}({L}|{D})*  { count(); return(check_type()); }
 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 0{D}+{IS}?     { count(); yylval.val = constVal(yytext); return(CONSTANT); }
index b88ead947e6d48752d91ed80e6ce4321c7fa58b4..7539a6728ca5ea3c4dc80d56c965da785c758fc8 100644 (file)
@@ -74,7 +74,7 @@ value *cenum = NULL  ;  /* current enumeration  type chain*/
 
 %token <yychar> IDENTIFIER TYPE_NAME
 %token <val>   CONSTANT   STRING_LITERAL
-%token SIZEOF 
+%token SIZEOF TYPEOF 
 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
 %token AND_OP OR_OP 
 %token <yyint> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
@@ -278,6 +278,7 @@ unary_expr
    | unary_operator cast_expr { $$ = newNode($1,$2,NULL)    ;  }
    | SIZEOF unary_expr        { $$ = newNode(SIZEOF,NULL,$2);  }
    | SIZEOF '(' type_name ')' { $$ = newAst_VALUE(sizeofOp($3)); }
+   | TYPEOF unary_expr        { $$ = newNode(TYPEOF,NULL,$2);  }
    ;
               
 unary_operator
index bf5b3abf36243ddc146f058dd0d69153c074adb7..c631350c72defa5c8b0bf8dd0ff4a0b7a3d06b46 100644 (file)
@@ -1975,7 +1975,9 @@ decorateType (ast * tree)
     ast *dtl, *dtr;
 
     dtl = decorateType (tree->left);
-    dtr = decorateType (tree->right);
+    /* delay right side for '?' operator since conditional macro expansions might
+       rely on this */
+    dtr = (tree->opval.op == '?' ? tree->right : decorateType (tree->right));
 
     /* this is to take care of situations
        when the tree gets rewritten */
@@ -2885,6 +2887,79 @@ decorateType (ast * tree)
                               tree->opval.val->type);
       return tree;
 
+      /*------------------------------------------------------------------*/
+      /*----------------------------*/
+      /*             typeof         */
+      /*----------------------------*/
+    case TYPEOF:
+       /* return typeof enum value */
+       tree->type = EX_VALUE;
+       {
+           int typeofv = 0;
+           if (IS_SPEC(tree->right->ftype)) {
+               switch (SPEC_NOUN(tree->right->ftype)) {
+               case V_INT:
+                   if (SPEC_LONG(tree->right->ftype)) typeofv = TYPEOF_LONG;
+                   else typeofv = TYPEOF_INT;
+                   break;
+               case V_FLOAT:
+                   typeofv = TYPEOF_FLOAT;
+                   break;
+               case V_CHAR:
+                   typeofv = TYPEOF_CHAR;
+                   break;
+               case V_VOID:
+                   typeofv = TYPEOF_VOID;
+                   break;
+               case V_STRUCT:
+                   typeofv = TYPEOF_STRUCT;
+                   break;
+               case V_BIT:
+                   typeofv = TYPEOF_BIT;
+                   break;
+               case V_SBIT:
+                   typeofv = TYPEOF_SBIT;
+                   break;
+               default:
+                   break;
+               }
+           } else {
+               switch (DCL_TYPE(tree->right->ftype)) {
+               case POINTER:
+                   typeofv = TYPEOF_POINTER;
+                   break;
+               case FPOINTER:
+                   typeofv = TYPEOF_FPOINTER;
+                   break;
+               case CPOINTER:
+                   typeofv = TYPEOF_CPOINTER;
+                   break;
+               case GPOINTER:
+                   typeofv = TYPEOF_GPOINTER;
+                   break;
+               case PPOINTER:
+                   typeofv = TYPEOF_PPOINTER;
+                   break;
+               case IPOINTER:
+                   typeofv = TYPEOF_IPOINTER;
+                   break;
+               case ARRAY:
+                   typeofv = TYPEOF_ARRAY;
+                   break;
+               case FUNCTION:
+                   typeofv = TYPEOF_FUNCTION;
+                   break;
+               default:
+                   break;
+               }
+           }
+           sprintf (buffer, "%d", typeofv);
+           tree->opval.val = constVal (buffer);
+           tree->right = tree->left = NULL;
+           TETYPE (tree) = getSpec (TTYPE (tree) =
+                                    tree->opval.val->type);
+       }
+       return tree;
       /*------------------------------------------------------------------*/
       /*----------------------------*/
       /* conditional operator  '?'  */
@@ -2894,13 +2969,14 @@ decorateType (ast * tree)
       assert(IS_COLON_OP(tree->right));
       /* if already known then replace the tree : optimizer will do it
         but faster to do it here */
-      if (IS_LITERAL (LTYPE(tree))) {
+      if (IS_LITERAL (LTYPE(tree))) {    
          if ( ((int) floatFromVal (valFromType (LETYPE (tree)))) != 0) {
-             return tree->right->left ;
+             return decorateType(tree->right->left) ;
          } else {
-             return tree->right->right ;
+             return decorateType(tree->right->right) ;
          }
       } else {
+         tree->right = decorateType(tree->right);
          TTYPE (tree) = RTYPE(tree);
          TETYPE (tree) = getSpec (TTYPE (tree));
       }
index 0c1f440f7a367f6cd2a2ee92e5a4bb02b09873c1..0efe1d67e12d0890d6516ed3998e9257eb1a4535 100644 (file)
@@ -230,6 +230,7 @@ struct options
     char *calleeSaves[128];    /* list of functions using callee save */
     char *excludeRegs[32];     /* registers excluded from saving */
     int all_callee_saves;      /* callee saves for all functions */
+    int stack_probe;            /* insert call to function __stack_probe */
     /* starting address of the segments */
     int xstack_loc;            /* initial location of external stack */
     int stack_loc;             /* initial value of internal stack pointer */
@@ -237,7 +238,7 @@ struct options
     int data_loc;              /* interram start location       */
     int idata_loc;             /* indirect address space        */
     int code_loc;              /* code location start           */
-    int iram_size;             /* internal ram size (used only for error checking) */
+    int iram_size;             /* internal ram size (used only for error checking) */    
   };
 
 /* forward definition for variables accessed globally */
index 2c1363c054db0a76264caca23b1a48a7fae7e571..a989fe2d8dd44319ce531637a36e2c3cf7eb33c2 100644 (file)
@@ -207,7 +207,8 @@ optionsTable[] = {
     { 0,    "--profile",            &options.profile, "On supported ports, generate extra profiling information" },
     { 0,    "--fommit-frame-pointer", &options.ommitFramePtr, "Leave out the frame pointer." },
     { 0,    "--all-callee-saves",   &options.all_callee_saves, "callee will always save registers used" },
-    { 0,    "--use-accelerator",    &options.useAccelerator,"generate code for  DS390 Arithmetic Accelerator"}
+    { 0,    "--use-accelerator",    &options.useAccelerator,"generate code for  DS390 Arithmetic Accelerator"},
+    { 0,    "--stack-probe",               &options.stack_probe,"insert call to function __stack_probe at each function prologue"}
 };
 
 /** Table of all unsupported options and help text to display when one
index d0274ac0711a849281d83a1cdf3cfaf03c247c16..8660ad3a894e84f735ffb44c0bc40d949dbc5ed4 100644 (file)
 #define SDCC_NAME_MAX  3*SDCC_SYMNAME_MAX // big enough for _<func>_<var>_etc
 #include "SDCChasht.h"
 
+enum {
+    TYPEOF_INT=1,
+    TYPEOF_SHORT,
+    TYPEOF_CHAR,
+    TYPEOF_LONG,
+    TYPEOF_FLOAT,
+    TYPEOF_BIT,
+    TYPEOF_SBIT,
+    TYPEOF_SFR,
+    TYPEOF_VOID,
+    TYPEOF_STRUCT,
+    TYPEOF_ARRAY,
+    TYPEOF_FUNCTION,
+    TYPEOF_POINTER,
+    TYPEOF_FPOINTER,
+    TYPEOF_CPOINTER,
+    TYPEOF_GPOINTER,
+    TYPEOF_PPOINTER,
+    TYPEOF_IPOINTER,
+    TYPEOF_EEPPOINTER
+};
 
 #define HASHTAB_SIZE 256