Annotation of researchv10no/cmd/cfront/ooptcfront/gram_utils.c, revision 1.1

1.1     ! root        1: /* utilities used by the grammar. We never change them, so why
        !             2:    compile them constantly ? */
        !             3: 
        !             4: #include "cfront.h"
        !             5: 
        !             6: /* macros filtched from gram.skeleton */
        !             7: 
        !             8: #define yylex lalex
        !             9: extern TOK     la_look();
        !            10: extern void    la_backup( TOK, YYSTYPE );
        !            11: extern int     la_cast();
        !            12: extern int     la_decl();
        !            13: extern TOK     lalex();
        !            14: extern int yychar, must_be_id, DECL_TYPE, declTag;
        !            15: FILE * yydebugfile;
        !            16: 
        !            17: char * gram_print_node (int tok, YYSTYPE* val)
        !            18: {
        !            19:     static char buffer[1000];
        !            20: 
        !            21:     switch(tok) {
        !            22:       case ID:
        !            23:       case TNAME:
        !            24:        Pname n = val->pn;
        !            25:        return n->string;
        !            26:       case STRING:
        !            27:        return val->s;
        !            28:       default:
        !            29:        sprintf(buffer, "0x%x", val->p);
        !            30:        return buffer;
        !            31:     }
        !            32: }
        !            33: 
        !            34: #define NEXTTOK() ( (yychar==-1) ? (yychar=yylex(),yychar) : yychar )
        !            35: #define EXPECT_ID() must_be_id = 1
        !            36: #define NOT_EXPECT_ID() must_be_id = 0
        !            37:     
        !            38: Pptr doptr(TOK p, TOK t)
        !            39: {
        !            40:        Pptr r = new ptr(p,0);
        !            41:        switch (t) {
        !            42:        case CONST:
        !            43:                r->rdo = 1;
        !            44:                // if (p == RPTR) error('w',"redundant `const' after &");
        !            45:                break;
        !            46:        case VOLATILE:
        !            47:                error('w',"\"volatile\" not implemented (ignored)");
        !            48:                break;
        !            49:        default:
        !            50:                error("syntax error: *%k",t);
        !            51:        }
        !            52:        return r;
        !            53: }
        !            54: 
        !            55: Pbcl dobase(TOK pr, Pname n, TOK v = 0)
        !            56: {
        !            57:        Pbcl b = new basecl(0,0);
        !            58: 
        !            59:        if (pr == PROTECTED) {
        !            60:                pr = PUBLIC;
        !            61:                error("protectedBC");
        !            62:        }
        !            63:        b->ppp = pr;    // save protection indicator
        !            64: 
        !            65:        if (n) {
        !            66:                if (n->base != TNAME) {
        !            67:                        error("BN%n not aTN",n);
        !            68:                        return 0;
        !            69:                }
        !            70: 
        !            71:                Pbase bt = Pbase(n->tp);
        !            72:                while (bt->base == TYPE) bt = Pbase(bt->b_name->tp);
        !            73: 
        !            74:                if (bt->base != COBJ) {
        !            75:                        error("BN%n not aCN",n);
        !            76:                        return 0;
        !            77:                }
        !            78: 
        !            79:                if (v) {
        !            80:                        if (v != VIRTUAL) error("syntax error:%k inBCD",v);
        !            81:                        b->base = VIRTUAL;
        !            82:                }
        !            83:                else
        !            84:                        b->base = NAME;
        !            85: 
        !            86:                b->bclass = Pclass(bt->b_name->tp);
        !            87:        }
        !            88: 
        !            89:        return b;
        !            90: }
        !            91: 
        !            92: extern int yyparse ();
        !            93: extern YYSTYPE yylval, yyval;
        !            94: 
        !            95: Pname syn()
        !            96: {
        !            97: ll:
        !            98:        switch (yyparse()) {
        !            99:        case 0:         return 0;       // EOF
        !           100:        case 1:         goto ll;        // no action needed
        !           101:        default:        return yyval.pn;
        !           102:        }
        !           103: }
        !           104: 
        !           105: void
        !           106: check_cast()
        !           107: /*
        !           108:        Lookahead to direct parsing of cast
        !           109:        la_cast() returns 1 if lookahead sees an ambiguous old-style C cast.
        !           110: */
        !           111: {
        !           112:        switch( NEXTTOK() ) {
        !           113:        case TYPE: case TNAME:
        !           114:            if ( la_look() == LP && la_cast() ) {
        !           115:                must_be_id = 0;
        !           116:                yychar = DECL_MARKER;
        !           117:            }
        !           118:        }
        !           119: }
        !           120: 
        !           121: void
        !           122: check_decl()
        !           123: /*
        !           124:        Lookahead to direct parsing of local/arg type declarations
        !           125:        la_decl() returns 1 if lookahead sees a declaration.
        !           126: */
        !           127: {
        !           128: 
        !           129:        switch( NEXTTOK() ) {
        !           130:        case TYPE: case TNAME:
        !           131:            if ( la_look() == LP && la_decl() ) {
        !           132:                must_be_id = 0;
        !           133:                DECL_TYPE=yychar;
        !           134:                yychar = DECL_MARKER;
        !           135:            }
        !           136:        }
        !           137: }
        !           138: 
        !           139: void
        !           140: check_tag()
        !           141: /*
        !           142:         Allow the case of inline/virtual/overload as 
        !           143:         modifiers of return type of form struct/class/union x foo() 
        !           144:         SM, COLON, LC ==> real class declaration, not return type
        !           145: */
        !           146: {
        !           147:        switch ( NEXTTOK() ) {
        !           148:        case SM: case COLON: case LC:
        !           149:                declTag = 1;
        !           150:                break;
        !           151:        default:
        !           152:                declTag = 0;
        !           153:                break;
        !           154:         }
        !           155: }
        !           156: 
        !           157: Pname find_fct_dcl (Pname fname)
        !           158: {
        !           159:     Pname function_name;
        !           160: 
        !           161:     if(!(fname && fname->base == NAME && fname->tp && fname->tp->base == FCT))
        !           162:        return 0;
        !           163:     /* In an ideal world, we would defer this to something in semantics.
        !           164:        oh well, here we go. */
        !           165: 
        !           166:     if (fname->n_qualifier) {  
        !           167:        Pname cn = fname->n_qualifier;
        !           168: 
        !           169:        switch (cn->base) {
        !           170:          case TNAME:
        !           171:            break;
        !           172:          case NAME:
        !           173:            cn = gtbl->look(cn->string,0);
        !           174:            if (cn && cn->base==TNAME) break;
        !           175:          default:
        !           176:            error("badQr%n for%n",fname->n_qualifier,fname);
        !           177:            return 0;
        !           178:        }
        !           179: 
        !           180:        if (cn->tp->base != COBJ) {
        !           181:            return 0;
        !           182:        }
        !           183: 
        !           184:        cn = Pbase(cn->tp)->b_name;
        !           185: 
        !           186:        Pclass cl = Pclass(cn->tp);
        !           187: 
        !           188:        if ((cl->defined&(DEFINED|SIMPLIFIED)) == 0) {
        !           189:            error("C%nU",cn);
        !           190:            return 0;
        !           191:        }
        !           192: 
        !           193:        Ptable etbl = cl->memtbl;
        !           194:        Pname x = etbl->look(fname->string,0);
        !           195:        if (x==0 || x->n_table!=etbl) {
        !           196:            error("%n is not aM of%n",fname,cn);
        !           197:            return 0;
        !           198:        }
        !           199: 
        !           200:        if(x->base != NAME || x->tp == 0) {
        !           201:            return 0;
        !           202:        }
        !           203: 
        !           204:        function_name = x;
        !           205:     } else {
        !           206:        function_name = gtbl->look (fname->string, 0);
        !           207:        if(!function_name) {
        !           208:          err::print ("No function %s.", err::name_string (fname));
        !           209:            return 0;
        !           210:        }
        !           211:     }
        !           212: 
        !           213:     switch(function_name->tp->base) {
        !           214:       case FCT:
        !           215:        break;
        !           216:       case OVERLOAD:
        !           217:        function_name = Pgen(function_name->tp)->find(Pfct(fname->tp),0);
        !           218:        if(!function_name) {
        !           219:          err::print ("Pragma specifies undefined function.");
        !           220:            return 0;
        !           221:        }
        !           222:     }
        !           223: 
        !           224:     return function_name;
        !           225: }
        !           226: 
        !           227: 
        !           228: void mark_abnormal_query_function (Pname fname)
        !           229: {
        !           230:     Pname function_name =  find_fct_dcl(fname);
        !           231:     if(!function_name) {
        !           232:       err::print("#pragma ObjectStore query_abnormal_operator must be followed by a function declaration.");
        !           233:     }
        !           234:     else Pfct(function_name->tp)->f_query_abnormal = 1;
        !           235: }
        !           236: 
        !           237: void declare_query_zvec_compare_function (Pname fn)
        !           238: {
        !           239:     Pname function_name = find_fct_dcl(fn);
        !           240:     int found = 0;
        !           241:     if(!function_name)
        !           242:       err::print("#pragma ObjectStore query_zvec_compare_function must be followed by a function declaration.");
        !           243:     else Pfct(function_name->tp)->f_query_compare = 1;
        !           244: }
        !           245: 
        !           246: void declare_query_zvec_copy_function (Pname fn)
        !           247: {
        !           248:     Pname function_name = find_fct_dcl(fn);
        !           249:     int found = 0;
        !           250:     if(!function_name)
        !           251:       err::print("#pragma ObjectStore query_zvec_copy_function must be followed by a function declaration.");
        !           252:     else Pfct(function_name->tp)->f_query_copy = 1;
        !           253: }
        !           254: 
        !           255: void register_zvec_type (Ptype t);
        !           256: 
        !           257: void declare_query_zvec_type (Pname tn)
        !           258: {
        !           259:     register_zvec_type (tn->tp);
        !           260: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.