EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/STreeParser.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "STreeParser.h"
00003 
00004 void STreeParser::
00005 MATCH(SORASTBase *_t,int tok)
00006 {
00007         if ( _t->type()!=tok )
00008         {
00009                 if ( guessing ) _GUESS_FAIL;
00010                 else mismatched_token(tok, _t);
00011         }
00012 }
00013 
00014 void STreeParser::
00015 MATCHRANGE(SORASTBase *_t,int tok,int tok2)
00016 {
00017         if ( _t->type()<tok || _t->type()>tok2 )
00018         {
00019                 if ( guessing ) _GUESS_FAIL;
00020                 else mismatched_range(tok, tok2, _t);
00021         }
00022 }
00023 
00024 void STreeParser::
00025 WILDCARD(SORASTBase *_t)
00026 {
00027         if ( _t==NULL )
00028         {
00029                 if ( guessing ) _GUESS_FAIL;
00030                 else missing_wildcard();
00031         }
00032 }
00033 
00034 void STreeParser::
00035 mismatched_range(int looking_for, int upper_token, SORASTBase *found)
00036 {
00037         if ( found!=NULL ) {
00038                 fprintf(stderr,
00039                                 "parse error: expected token range %d..%d found token %d\n",
00040                                 looking_for, upper_token,
00041                                 found->type());
00042         }
00043         else {
00044                 fprintf(stderr,
00045                                 "parse error: expected token range %d..%d found NULL tree\n",
00046                                 looking_for, upper_token);
00047         }
00048 }
00049 
00050 void STreeParser::
00051 missing_wildcard()
00052 {
00053         fprintf(stderr, "parse error: expected any token/tree found found NULL tree\n");
00054 }
00055 
00056 void STreeParser::
00057 mismatched_token(int looking_for, SORASTBase *found)
00058 {
00059         if ( found!=NULL ) {
00060                 fprintf(stderr,
00061                                 "parse error: expected token %d found token %d\n",
00062                                 looking_for,
00063                                 found->type());
00064         }
00065         else {
00066                 fprintf(stderr,
00067                                 "parse error: expected token %d found NULL tree\n",
00068                                 looking_for);
00069         }
00070 }
00071 
00072 void STreeParser::
00073 no_viable_alt(char *rulename, SORASTBase *root)
00074 {
00075         if ( root==NULL )
00076                 fprintf(stderr,
00077                                 "parse error: in rule %s, no viable alternative for NULL tree\n",
00078                                 rulename);
00079         else
00080                 fprintf(stderr,
00081                                 "parse error: in rule %s, no viable alternative for tree\n",
00082                                 rulename);
00083 }
00084 
00085 void STreeParser::
00086 panic(char *err)
00087 {
00088         fprintf(stderr, "panic: %s\n", err);
00089         exit(-1);
00090 }
00091 
00092 void STreeParser::
00093 save_state(STreeParser *buf)
00094 {
00095         buf->try_ok = this->try_ok;
00096         buf->sjrv = this->sjrv;
00097         buf->guessing = this->guessing;
00098         buf->startofguess = this->startofguess;
00099 }
00100 
00101 void STreeParser::
00102 restore_state(STreeParser *buf)
00103 {
00104         this->try_ok = buf->try_ok;
00105         this->sjrv = buf->sjrv;
00106         this->guessing = buf->guessing;
00107         this->startofguess = buf->startofguess;
00108 }
00109 
00110 void STreeParser::
00111 _mkroot(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)
00112 {
00113         *r = t;
00114 }
00115 
00116 void STreeParser::
00117 _mkchild(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)
00118 {
00119 #ifdef BEFORE_GARYS_FIX
00120         /* if no sibling list, must attach to any existing root */
00121         if ( *s==NULL )
00122         {
00123                 *s = *e = t;
00124                 /* If r is NULL, then there was no root defined--must be sibling list */
00125                 if ( *r==NULL ) *r = *s;
00126                 else (*r)->setDown(t);
00127         }
00128         else { (*e)->setRight(t); *e = t; }
00129 #endif
00130 /*
00131         should do nothing if asked to add a NULL argument.  NULL's come up
00132         when a rule wants to return "nothing".
00133 */
00134         /* if no sibling list, must attach to any existing root */
00135         if (*s == NULL)
00136         {
00137                 *s = *e = t;
00138                 // If r is NULL then there was no root defined--must be sibling list
00139                 if (*r == NULL) *r = *s;
00140                 else (*r)->setDown(t);
00141         }
00142         else if (*e != NULL)
00143         {
00144                 (*e)->setRight(t);
00145                 *e = t;
00146         }
00147         if (*e != NULL) {
00148                 while ((*e)->right() != NULL) *e = (SORASTBase *)(*e)->right();
00149         }
00150 }
00151 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines