home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / smc / parser.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  15.5 KB  |  410 lines

  1. /*****************************************************************************/
  2. #ifndef _PARSER_H_
  3. #define _PARSER_H_
  4. /*****************************************************************************/
  5. #ifndef _ERROR_H_
  6. #include "error.h"
  7. #endif
  8. /*****************************************************************************/
  9. #ifndef _HASH_H_
  10. #include "hash.h"
  11. #endif
  12. /*****************************************************************************/
  13. #ifndef _SCAN_H_
  14. #include "scan.h"
  15. #endif
  16. /*****************************************************************************/
  17. #ifndef _ALLOC_H_
  18. #include "alloc.h"
  19. #endif
  20. /*****************************************************************************
  21.  *
  22.  *  When we re-enter the parser, we have to save the current state so that
  23.  *  the "outer" calls don't get screwed.
  24.  */
  25.  
  26. DEFMGMT
  27. struct  parserState
  28. {
  29.     bool                psSaved;
  30.     scannerState        psScanSt;
  31.     SymDef              psCurComp;
  32. };
  33.  
  34. /*****************************************************************************
  35.  *
  36.  *  The following holds the current "using" state and is used whenever we
  37.  *  introduce a new "using" region (so that the state on entry to that
  38.  *  region can be restored).
  39.  */
  40.  
  41. DEFMGMT
  42. struct  usingState
  43. {
  44.     UseList             usUseList;
  45.     UseList             usUseDesc;
  46. };
  47.  
  48. /*****************************************************************************/
  49.  
  50. DEFMGMT
  51. class parser
  52. {
  53.         /*********************************************************************/
  54.         /*  Initialization and finalization - call once per lifetime.        */
  55.         /*********************************************************************/
  56.  
  57. public:
  58.  
  59.         int             parserInit(Compiler comp);
  60.         void            parserDone();
  61.  
  62.         /*********************************************************************/
  63.         /*  Main entry point to prepare the given source text for parsing    */
  64.         /*********************************************************************/
  65.  
  66. public:
  67.  
  68.         SymDef          parsePrepSrc(stringBuff     file,
  69.                                      QueuedFile     fileBuff,
  70.                                      const  char  * srcText,
  71.                                      SymTab         symtab);
  72.  
  73.         /*********************************************************************/
  74.         /*  The following keeps track of which hash table(s) to use, etc.    */
  75.         /*********************************************************************/
  76.  
  77. private:
  78.  
  79.         Compiler        parseComp;
  80.         SymTab          parseStab;
  81.         HashTab         parseHash;
  82.         Scanner         parseScan;
  83.  
  84.         norls_allocator parseAllocPriv;     // private temp allocator
  85.  
  86.         block_allocator*parseAllocTemp;     // allocator to use for symtab
  87.         norls_allocator*parseAllocPerm;     // allocator to use for hashtab
  88.  
  89.         /*********************************************************************/
  90.         /*  Members used for processing declarations and "using" clauses     */
  91.         /*********************************************************************/
  92.  
  93. public:
  94.         void            parseUsingInit();
  95.         void            parseUsingDone();
  96.  
  97. private:
  98.         SymDef          parseCurSym;
  99.         SymDef          parseCurCmp;
  100.  
  101.         UseList         parseCurUseList;
  102.         UseList         parseCurUseDesc;
  103.  
  104.         usingState      parseInitialUse;
  105.  
  106.         void            parseUsingScpBeg(  OUT usingState REF state, SymDef owner);
  107.         void            parseUsingDecl();
  108.         void            parseUsingScpEnd(IN    usingState REF state);
  109.  
  110.         void            parseInsertUses (INOUT usingState REF state, SymDef inner,
  111.                                                                      SymDef outer);
  112.         void            parseInsertUsesR(                            SymDef inner,
  113.                                                                      SymDef outer);
  114.         void            parseRemoveUses (IN    usingState REF state);
  115.  
  116. public:
  117.         UseList         parseInsertUses (UseList useList, SymDef inner);
  118.  
  119.         /*********************************************************************/
  120.         /*  Methods used for parsing declarations and other things           */
  121.         /*********************************************************************/
  122.  
  123. private:
  124.  
  125.         bool            parseOldStyle;
  126.  
  127.         bool            parseNoTypeDecl;
  128.  
  129.         bool            parseBaseCTcall;
  130.         bool            parseThisCTcall;
  131.  
  132.         GenArgDscF      parseGenFormals();
  133.  
  134. public:
  135.         SymDef          parseSpecificType(SymDef clsSym, TypDef elemTp = NULL);
  136. private:
  137.  
  138.         TypDef          parseCheck4type(tokens          nxtTok,
  139.                                         bool            isCast = false);
  140.  
  141.         TypDef          parseDclrtrTerm(dclrtrName      nameMode,
  142.                                         bool            forReal,
  143.                                         DeclMod         modsPtr,
  144.                                         TypDef          baseType,
  145.                                         TypDef  *     * baseRef,
  146.                                         Ident         * nameRet,
  147.                                         QualName      * qualRet);
  148.  
  149.         CorDeclSecurity parseSecAction();
  150.  
  151. public:
  152.  
  153.         SymDef          parseAttribute (unsigned        tgtMask,
  154.                                     OUT unsigned    REF useMask,
  155.                                     OUT genericBuff REF blobAddr,
  156.                                     OUT size_t      REF blobSize);
  157.  
  158.         SecurityInfo    parseCapability(bool            forReal = false);
  159.         SecurityInfo    parsePermission(bool            forReal = false);
  160.  
  161.         SymXinfo        parseBrackAttr (bool            forReal,
  162.                                         unsigned        OKmask,
  163.                                         DeclMod         modsPtr = NULL);
  164.  
  165.         void            parseDeclMods  (accessLevels    defAcc,
  166.                                         DeclMod         mods);
  167.  
  168.         bool            parseIsTypeSpec(bool            noLookup,
  169.                                         bool          * labChkPtr = NULL);
  170.  
  171.         Ident           parseDeclarator(DeclMod         mods,
  172.                                         TypDef          baseType,
  173.                                         dclrtrName      nameMode,
  174.                                         TypDef        * typeRet,
  175.                                         QualName      * qualRet,
  176.                                         bool            forReal);
  177.  
  178.         TypDef          parseTypeSpec  (DeclMod         mods,
  179.                                         bool            forReal);
  180.  
  181. private:
  182.  
  183.         bool            parseIsCtorDecl(SymDef          clsSym);
  184.  
  185.         SymDef          parseNameUse   (bool            typeName,
  186.                                         bool            keepName,
  187.                                         bool            chkOnly = false);
  188.  
  189.         Tree            parseInitExpr();
  190.  
  191.         TypDef          parseType();
  192.  
  193.         DimDef          parseDimList   (bool            isManaged);
  194.  
  195.         ArgDef          parseArgListRec(    ArgDscRec   & argDsc);
  196.  
  197. public:
  198.  
  199.         void            parseArgList   (OUT ArgDscRec REF argDsc);
  200.  
  201.         void    _cdecl  parseArgListNew(    ArgDscRec   & argDsc,
  202.                                             unsigned      argCnt,
  203.                                             bool          argNames, ...);
  204.  
  205. private:
  206.  
  207.         QualName        parseQualNRec  (unsigned        depth,
  208.                                         Ident           name1,
  209.                                         bool            allOK);
  210.  
  211.         QualName        parseQualName  (bool            allOK)
  212.         {
  213.             assert(parseComp->cmpScanner->scanTok.tok == tkID);
  214.  
  215.             return      parseQualNRec(0,  NULL, allOK);
  216.         }
  217.  
  218.         QualName        parseQualName  (Ident name1, bool allOK)
  219.         {
  220.             assert(parseComp->cmpScanner->scanTok.tok == tkDot ||
  221.                    parseComp->cmpScanner->scanTok.tok == tkColon2);
  222.  
  223.             return      parseQualNRec(0, name1, allOK);
  224.         }
  225.  
  226.         void            chkCurTok(int tok, int err);
  227.         void            chkNxtTok(int tok, int err);
  228.  
  229. public:
  230.  
  231.         void            parseResync(tokens delim1, tokens delim2);
  232.  
  233.         /*********************************************************************/
  234.         /*  The following keeps track of default alignment (pragma pack)     */
  235.         /*********************************************************************/
  236.  
  237. private:
  238.  
  239.         unsigned        parseAlignStack;
  240.         unsigned        parseAlignStLvl;
  241.  
  242. public:
  243.  
  244.         unsigned        parseAlignment;
  245.  
  246.         void            parseAlignSet (unsigned align);
  247.         void            parseAlignPush();
  248.         void            parseAlignPop ();
  249.  
  250.         /*********************************************************************/
  251.         /*  The following methods are used to allocate parse tree nodes      */
  252.         /*********************************************************************/
  253.  
  254. private:
  255.         Tree            parseAllocNode();
  256.  
  257. public:
  258.         Tree            parseCreateNode    (treeOps     op);
  259.  
  260.         Tree            parseCreateUSymNode(SymDef      sym,
  261.                                             SymDef      scp = NULL);
  262.         Tree            parseCreateNameNode(Ident       name);
  263.         Tree            parseCreateOperNode(treeOps     op,
  264.                                             Tree        op1,
  265.                                             Tree        op2);
  266.         Tree            parseCreateBconNode(int         val);
  267.         Tree            parseCreateIconNode(__int32     ival,
  268.                                             var_types   typ = TYP_INT);
  269.         Tree            parseCreateLconNode(__int64     lval,
  270.                                             var_types   typ = TYP_LONG);
  271.         Tree            parseCreateFconNode(float       fval);
  272.         Tree            parseCreateDconNode(double      dval);
  273.         Tree            parseCreateSconNode(stringBuff  sval,
  274.                                             size_t      slen,
  275.                                             unsigned    type,
  276.                                             int         wide,
  277.                                             Tree        addx = NULL);
  278.  
  279.         Tree            parseCreateErrNode (unsigned    errn = 0);
  280.  
  281.         /*********************************************************************/
  282.         /*  The following methods display parse trees                        */
  283.         /*********************************************************************/
  284.  
  285. #ifdef  DEBUG
  286.  
  287. public:
  288.         void            parseDispTreeNode(Tree tree, unsigned indent, const char *name = NULL);
  289.         void            parseDispTree    (Tree tree, unsigned indent = 0);
  290.  
  291. #endif
  292.  
  293.         /*********************************************************************/
  294.         /*  The following methods are used to parse expressions              */
  295.         /*********************************************************************/
  296.  
  297.         Tree            parseAddToNodeList (      Tree      nodeList,
  298.                                             INOUT Tree  REF nodeLast,
  299.                                                   Tree      nodeAdd);
  300.  
  301. private:
  302.  
  303.         Tree            parseNewExpr();
  304.         Tree            parseExprList(tokens endTok);
  305.         Tree            parseCastOrExpr();
  306.         Tree            parseTerm(Tree tree = NULL);
  307.         Tree            parseExpr(unsigned prec, Tree pt);
  308.  
  309. public:
  310.         Tree            parseExpr()
  311.         {
  312.             return  parseExpr(0, NULL);
  313.         }
  314.  
  315.         Tree            parseExprComma()
  316.         {
  317.             return  parseExpr(1, NULL); // assumes that precedence of "," is 1
  318.         }
  319.  
  320.         void            parseExprSkip();
  321.  
  322.         bool            parseConstExpr(OUT constVal REF valPtr,
  323.                                            Tree         expr  = NULL,
  324.                                            TypDef       dstt  = NULL,
  325.                                            Tree  *      ncPtr = NULL);
  326.  
  327.         /*********************************************************************/
  328.         /*  The following methods are used to parse function bodies          */
  329.         /*********************************************************************/
  330.  
  331.         Tree            parseLastDecl;
  332.         Tree            parseCurScope;
  333.  
  334.         Tree            parseLabelList;
  335.         unsigned        parseLclVarCnt;
  336.  
  337.         Tree            parseCurSwitch;
  338.  
  339.         bool            parseHadGoto;
  340.  
  341.         Tree            parseTryDecl;
  342.         Tree            parseTryStmt();
  343.  
  344.         Tree            parseFuncBody  (SymDef      fsym,
  345.                                         Tree     *  labels,
  346.                                         unsigned *  locals,
  347.                                         bool     *  hadGoto,
  348.                                         bool     *  baseCT,
  349.                                         bool     *  thisCT);
  350.  
  351.         Tree            parseFuncBlock (SymDef      fsym = NULL);
  352.  
  353.         Tree            parseFuncStmt  (bool        stmtOpt = false);
  354.  
  355.         void            parseLclDclDecl(Tree        decl);
  356.         Tree            parseLclDclMake(Ident       name,
  357.                                         TypDef      type,
  358.                                         Tree        init,
  359.                                         unsigned    mods,
  360.                                         bool        arg);
  361.  
  362.         Tree            parseLookupSym (Ident       name);
  363.  
  364.         /*********************************************************************/
  365.         /*  Record source text information about a namespace or class        */
  366.         /*********************************************************************/
  367.  
  368. private:
  369.  
  370.         SymDef          parsePrepSym      (SymDef   parent,
  371.                                            declMods mods,
  372.                                            tokens   defTok, scanPosTP dclFpos,
  373.                                                             unsigned  dclLine);
  374.  
  375.         DefList         parseMeasureSymDef(SymDef   sym,
  376.                                            declMods mods  , scanPosTP dclFpos,
  377.                                                             unsigned  dclLine);
  378.  
  379.         /*********************************************************************/
  380.         /*  Prepare the given section of the source for parsing              */
  381.         /*********************************************************************/
  382.  
  383. private:
  384.  
  385.         bool            parseReadingText;
  386.  
  387. #ifdef  DEBUG
  388.         unsigned        parseReadingTcnt;
  389. #endif
  390.  
  391. public:
  392.  
  393.         void            parsePrepText (DefSrc                def,
  394.                                        SymDef                compUnit,
  395.                                          OUT parserState REF save);
  396.  
  397.         void            parseDoneText (INOUT parserState REF save);
  398.  
  399.         void            parseSetErrPos(DefSrc                def,
  400.                                        SymDef                compUnit);
  401. };
  402.  
  403. /*****************************************************************************/
  404. #ifndef _INLINES_H_
  405. #include "inlines.h"
  406. #endif
  407. /*****************************************************************************/
  408. #endif
  409. /*****************************************************************************/
  410.