Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/occ/ptree.h
    1| /*
    2|   Copyright (C) 1997-2000 Shigeru Chiba, University of Tsukuba.
    3| 
    4|   Permission to use, copy, distribute and modify this software and   
    5|   its documentation for any purpose is hereby granted without fee,        
    6|   provided that the above copyright notice appear in all copies and that 
    7|   both that copyright notice and this permission notice appear in 
    8|   supporting documentation.
    9| 
   10|   Shigeru Chiba makes no representations about the suitability of this 
   11|   software for any purpose.  It is provided "as is" without express or
   12|   implied warranty.
   13| */
   14| 
   15| #ifndef _ptree_h
   16| #define _ptree_h
   17| 
   18| #include "ptree-core.h"
   19| #include "token.h"
   20| #include "buffer.h"
   21| 
   22| class Encoding;
   23| 
   24| class Leaf : public Ptree {
   25| public:
   26|     Leaf(char*, int);
   27|     Leaf(Token&);
   28|     bool IsLeaf();
   29| 
   30|     void Print(std::ostream&, intint);
   31|     int Write(std::ostream&, int);
   32|     void WritePS(ProgramString&);
   33| };
   34| 
   35| class CommentedLeaf : public Leaf {
   36| public:
   37|     CommentedLeaf(Token& tk, Ptree* c = NULL) : Leaf(tk) { comments = c; }
   38|     CommentedLeaf(char* p, int l, Ptree* c = NULL) : Leaf(p, l) { comments = c; }
   39|     PtreeGetComments() { return comments; }
   40|     void SetComments(Ptree* c) { comments = c; }
   41| 
   42| private:
   43|     Ptreecomments;
   44| };
   45| 
   46| class LeafName : public CommentedLeaf {
   47| public:
   48|     LeafName(Token&);
   49|     PtreeTranslate(Walker*);
   50|     void Typeof(Walker*, TypeInfo&);
   51| };
   52| 
   53| // class DupLeaf is used by Ptree::Make() and QuoteClass (qMake()).
   54| // The string given to the constructors are duplicated.
   55| 
   56| class DupLeaf : public CommentedLeaf {
   57| public:
   58|     DupLeaf(char*, int);
   59|     DupLeaf(char*, intchar*, int);
   60| 
   61|     void Print(std::ostream&, intint);
   62| };
   63| 
   64| class LeafReserved : public CommentedLeaf {
   65| public:
   66|     LeafReserved(Token& t) : CommentedLeaf(t) {}
   67|     LeafReserved(char* str, int len) : CommentedLeaf(str, len) {}
   68| };
   69| 
   70| class LeafThis : public LeafReserved {
   71| public:
   72|     LeafThis(Token& t) : LeafReserved(t) {}
   73|     int What();
   74|     PtreeTranslate(Walker*);
   75|     void Typeof(Walker*, TypeInfo&);
   76| };
   77| 
   78| #define ResearvedWordDecl(w) \
   79| class Leaf##w : public LeafReserved { \
   80| public: \
   81|     Leaf##w(Token& t) : LeafReserved(t) {} \
   82|     Leaf##w(char* str, int len) : LeafReserved(str, len) {} \
   83|     int What(); \
   84| }
   85| 
   86| ResearvedWordDecl(AUTO);
   87| ResearvedWordDecl(BOOLEAN);
   88| ResearvedWordDecl(CHAR);
   89| ResearvedWordDecl(CONST);
   90| ResearvedWordDecl(DOUBLE);
   91| ResearvedWordDecl(EXTERN);
   92| ResearvedWordDecl(FLOAT);
   93| ResearvedWordDecl(FRIEND);
   94| ResearvedWordDecl(INLINE);
   95| ResearvedWordDecl(INT);
   96| ResearvedWordDecl(LONG);
   97| ResearvedWordDecl(MUTABLE);
   98| ResearvedWordDecl(NAMESPACE);
   99| ResearvedWordDecl(PRIVATE);
  100| ResearvedWordDecl(PROTECTED);
  101| ResearvedWordDecl(PUBLIC);
  102| ResearvedWordDecl(REGISTER);
  103| ResearvedWordDecl(SHORT);
  104| ResearvedWordDecl(SIGNED);
  105| ResearvedWordDecl(STATIC);
  106| ResearvedWordDecl(UNSIGNED);
  107| ResearvedWordDecl(USING);
  108| ResearvedWordDecl(VIRTUAL);
  109| ResearvedWordDecl(VOID);
  110| ResearvedWordDecl(VOLATILE);
  111| 
  112| ResearvedWordDecl(UserKeyword2);
  113| 
  114| #undef ResearvedWordDecl
  115| 
  116| class NonLeaf : public Ptree {
  117| public:
  118|     NonLeaf(Ptree*, Ptree*);
  119|     bool IsLeaf();
  120| 
  121|     void Print(std::ostream&, intint);
  122|     int Write(std::ostream&, int);
  123|     void PrintWithEncodeds(std::ostream&, intint);
  124|     void WritePS(ProgramString&);
  125| 
  126| protected:
  127|     bool TooDeep(std::ostream&, int);
  128| };
  129| 
  130| class PtreeBrace : public NonLeaf {
  131| public:
  132|     PtreeBrace(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  133|     PtreeBrace(Ptree* ob, Ptree* body, Ptree* cb)
  134|         : NonLeaf(ob, Ptree::List(body, cb)) {}
  135| 
  136|     void Print(std::ostream&, intint);
  137|     int Write(std::ostream&, int);
  138| 
  139|     PtreeTranslate(Walker*);
  140| };
  141| 
  142| class PtreeBlock : public PtreeBrace {
  143| public:
  144|     PtreeBlock(Ptree* p, Ptree* q) : PtreeBrace(p, q) {}
  145|     PtreeBlock(Ptree* ob, Ptree* bdy, Ptree* cb) : PtreeBrace(ob, bdy, cb) {}
  146| 
  147|     PtreeTranslate(Walker*);
  148| };
  149| 
  150| class PtreeClassBody : public PtreeBrace {
  151| public:
  152|     PtreeClassBody(Ptree* p, Ptree* q) : PtreeBrace(p, q) {}
  153|     PtreeClassBody(Ptree* ob, Ptree* bdy, Ptree* cb)
  154|                                     : PtreeBrace(ob, bdy, cb) {}
  155| 
  156|     PtreeTranslate(Walker*);
  157| };
  158| 
  159| class PtreeTypedef : public NonLeaf {
  160| public:
  161|     PtreeTypedef(Ptree* p) : NonLeaf(p, nil) {}
  162|     PtreeTypedef(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  163|     int What();
  164|     PtreeTranslate(Walker*);
  165| };
  166| 
  167| class PtreeTemplateDecl : public NonLeaf {
  168| public:
  169|     PtreeTemplateDecl(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  170|     PtreeTemplateDecl(Ptree* p) : NonLeaf(p, nil) {}
  171|     int What();
  172|     PtreeTranslate(Walker*);
  173| };
  174| 
  175| class PtreeTemplateInstantiation : public NonLeaf {
  176| public:
  177|     PtreeTemplateInstantiation(Ptree* p) : NonLeaf(p, nil) {}
  178|     int What();
  179|     PtreeTranslate(Walker*);
  180| };
  181| 
  182| class PtreeExternTemplate : public NonLeaf {
  183| public:
  184|     PtreeExternTemplate(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  185|     PtreeExternTemplate(Ptree* p) : NonLeaf(p, nil) {}
  186|     int What();
  187|     PtreeTranslate(Walker*);
  188| };
  189| 
  190| class PtreeMetaclassDecl : public NonLeaf {
  191| public:
  192|     PtreeMetaclassDecl(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  193|     int What();
  194|     PtreeTranslate(Walker*);
  195| };
  196| 
  197| class PtreeLinkageSpec : public NonLeaf {
  198| public:
  199|     PtreeLinkageSpec(Ptree* p, Ptree* q) : NonLeaf(p, q) {}
  200|     int What();
  201|     PtreeTranslate(Walker*);
  202| };
  203| 
  204| class PtreeNamespaceSpec : public NonLeaf {
  205| public:
  206|     PtreeNamespaceSpec(Ptree* p, Ptree* q) : NonLeaf(p, q) { comments = nil; }
  207|     int What();
  208|     PtreeTranslate(Walker*);
  209| 
  210|     PtreeGetComments() { return comments; }
  211|     void SetComments(Ptree* c) { comments = c; }
  212| 
  213| private:
  214|     Ptreecomments;
  215| };
  216| 
  217| class PtreeUsing : public NonLeaf {
  218| public:
  219|     PtreeUsing(Ptree* p) : NonLeaf(p, nil) {}
  220|     int What();
  221|     PtreeTranslate(Walker*);
  222| };
  223| 
  224| class PtreeDeclaration : public NonLeaf {
  225| public:
  226|     PtreeDeclaration(Ptree* p, Ptree* q) : NonLeaf(p, q) { comments = nil; }
  227|     int What();
  228|     PtreeTranslate(Walker*);
  229| 
  230|     PtreeGetComments() { return comments; }
  231|     void SetComments(Ptree* c) { comments = c; }
  232| 
  233| private:
  234|     Ptreecomments;
  235| };
  236| 
  237| class PtreeDeclarator : public NonLeaf {
  238| public:
  239|     PtreeDeclarator(Ptree*, Encoding&, Encoding&, Ptree*);
  240|     PtreeDeclarator(Encoding&, Encoding&, Ptree*);
  241|     PtreeDeclarator(Ptree*, Ptree*, Encoding&, Encoding&, Ptree*);
  242|     PtreeDeclarator(Ptree*, Encoding&);
  243|     PtreeDeclarator(Encoding&);
  244|     PtreeDeclarator(PtreeDeclarator*, Ptree*, Ptree*);
  245| 
  246|     int What();
  247|     charGetEncodedType();
  248|     charGetEncodedName();
  249|     void SetEncodedType(char* t) { type = t; }
  250|     PtreeName() { return declared_name; }
  251|     void Print(std::ostream&, intint);
  252| 
  253|     PtreeGetComments() { return comments; }
  254|     void SetComments(Ptree* c) { comments = c; }
  255| 
  256| private:
  257|     chartype;
  258|     charname;
  259|     Ptreedeclared_name;
  260|     Ptreecomments;
  261| };
  262| 
  263| class PtreeName : public NonLeaf {
  264| public:
  265|     PtreeName(Ptree*, Encoding&);
  266|     int What();
  267|     charGetEncodedName();
  268|     void Print(std::ostream&, intint);
  269|     PtreeTranslate(Walker*);
  270|     void Typeof(Walker*, TypeInfo&);
  271| 
  272| private:
  273|     charname;
  274| };
  275| 
  276| class PtreeFstyleCastExpr : public NonLeaf {
  277| public:
  278|     PtreeFstyleCastExpr(Encoding&, Ptree*, Ptree*);
  279|     PtreeFstyleCastExpr(char*, Ptree*, Ptree*);
  280|     int What();
  281|     charGetEncodedType();
  282|     void Print(std::ostream&, intint);
  283|     PtreeTranslate(Walker*);
  284|     void Typeof(Walker*, TypeInfo&);
  285| 
  286| private:
  287|     chartype;
  288| };
  289| 
  290| class PtreeClassSpec : public NonLeaf {
  291| public:
  292|     PtreeClassSpec(Ptree*, Ptree*, Ptree*);
  293|     PtreeClassSpec(Ptree*, Ptree*, Ptree*, char*);
  294|     int What();
  295|     PtreeTranslate(Walker*);
  296|     charGetEncodedName();
  297|     PtreeGetComments();
  298| 
  299| private:
  300|     charencoded_name;
  301|     Ptreecomments;
  302| 
  303| friend class Parser;
  304| };
  305| 
  306| class PtreeEnumSpec : public NonLeaf {
  307| public:
  308|     PtreeEnumSpec(Ptree*);
  309|     int What();
  310|     PtreeTranslate(Walker*);
  311|     charGetEncodedName();
  312| 
  313| private:
  314|     charencoded_name;
  315| 
  316| friend class Parser;
  317| };
  318| 
  319| class PtreeAccessSpec : public NonLeaf {
  320| public:
  321|     PtreeAccessSpec(Ptree*, Ptree*);
  322|     int What();
  323|     PtreeTranslate(Walker*);
  324| };
  325| 
  326| class PtreeAccessDecl : public NonLeaf {
  327| public:
  328|     PtreeAccessDecl(Ptree*, Ptree*);
  329|     int What();
  330|     PtreeTranslate(Walker*);
  331| };
  332| 
  333| class PtreeUserAccessSpec : public NonLeaf {
  334| public:
  335|     PtreeUserAccessSpec(Ptree*, Ptree*);
  336|     int What();
  337|     PtreeTranslate(Walker*);
  338| };
  339| 
  340| class PtreeUserdefKeyword : public NonLeaf {
  341| public:
  342|     PtreeUserdefKeyword(Ptree*, Ptree*);
  343|     int What();
  344| };
  345| 
  346| #define PtreeStatementDecl(s)\
  347| class Ptree##s##Statement : public NonLeaf {\
  348| public:\
  349|     Ptree##s##Statement(Ptree* p, Ptree* q) : NonLeaf(p, q) {}\
  350|     int What();\
  351|     Ptree* Translate(Walker*);\
  352| }
  353| 
  354| PtreeStatementDecl(If);
  355| PtreeStatementDecl(Switch);
  356| PtreeStatementDecl(While);
  357| PtreeStatementDecl(Do);
  358| PtreeStatementDecl(For);
  359| PtreeStatementDecl(Try);
  360| PtreeStatementDecl(Break);
  361| PtreeStatementDecl(Continue);
  362| PtreeStatementDecl(Return);
  363| PtreeStatementDecl(Goto);
  364| PtreeStatementDecl(Case);
  365| PtreeStatementDecl(Default);
  366| PtreeStatementDecl(Label);
  367| PtreeStatementDecl(Expr);
  368| 
  369| #undef PtreeStatementDecl
  370| 
  371| #define PtreeExprDecl(n)\
  372| class Ptree##n##Expr : public NonLeaf {\
  373| public:\
  374|     Ptree##n##Expr(Ptree* p, Ptree* q) : NonLeaf(p, q) {}\
  375|     int What();\
  376|     Ptree* Translate(Walker*);\
  377|     void Typeof(Walker*, TypeInfo&);\
  378| }
  379| 
  380| PtreeExprDecl(Comma);
  381| PtreeExprDecl(Assign);
  382| PtreeExprDecl(Cond);
  383| PtreeExprDecl(Infix);
  384| PtreeExprDecl(Pm);
  385| PtreeExprDecl(Cast);
  386| PtreeExprDecl(Unary);
  387| PtreeExprDecl(Throw);
  388| PtreeExprDecl(Sizeof);
  389| PtreeExprDecl(Typeid);
  390| PtreeExprDecl(Typeof);
  391| PtreeExprDecl(New);
  392| PtreeExprDecl(Delete);
  393| PtreeExprDecl(Array);
  394| PtreeExprDecl(Funcall);
  395| PtreeExprDecl(Postfix);
  396| PtreeExprDecl(UserStatement);
  397| PtreeExprDecl(DotMember);
  398| PtreeExprDecl(ArrowMember);
  399| PtreeExprDecl(Paren);
  400| PtreeExprDecl(StaticUserStatement);
  401| 
  402| #undef PtreeExprDecl
  403| 
  404| #endif /* _ptree_h */