Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/syn/ast.hh
    1| // Synopsis C++ Parser: ast.hh header file
    2| // Defines the AST classes in the AST namespace
    3| 
    4| // $Id: ast.hh,v 1.22 2003/01/27 06:53:36 chalky Exp $
    5| //
    6| // This file is a part of Synopsis.
    7| // Copyright (C) 2002 Stephen Davies
    8| //
    9| // Synopsis is free software; you can redistribute it and/or modify it
   10| // under the terms of the GNU General Public License as published by
   11| // the Free Software Foundation; either version 2 of the License, or
   12| // (at your option) any later version.
   13| //
   14| // This program is distributed in the hope that it will be useful,
   15| // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17| // General Public License for more details.
   18| //
   19| // You should have received a copy of the GNU General Public License
   20| // along with this program; if not, write to the Free Software
   21| // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   22| // 02111-1307, USA.
   23| 
   24| // vim: set ts=8 sts=2 sw=2 et:
   25| // File: ast.h
   26| // A C++ class hierarchy that more or less mirrors the AST hierarchy in
   27| // Python/Core.AST.
   28| 
   29| #ifndef H_SYNOPSIS_CPP_AST
   30| #define H_SYNOPSIS_CPP_AST
   31| 
   32| #include "common.hh"
   33| 
   34| // Forward declare Dictionary
   35| class Dictionary;
   36| 
   37| // Forward declare Types::Type, Declared and Template
   38| namespace Types
   39| {
   40| class Type;
   41| class Declared;
   42| class Template;
   43| }
   44| 
   45| //. A namespace for the AST hierarchy
   46| namespace AST
   47| {
   48| // Forward declaration of AST::Visitor defined in this file
   49| class Visitor;
   50| 
   51| // Forward declaration of AST::SourceFile defined in this file
   52| class SourceFile;
   53| 
   54| //. An enumeration of accessability specifiers
   55| enum Access
   56| {
   57|     Default = 0,
   58|     Public,
   59|     Protected,
   60|     Private
   61| };
   62| 
   63| //FIXME: move to somewhere else
   64| //. A struct to hold cross-reference info
   65| struct Reference
   66| {
   67|     std::string file;
   68|     int         line;
   69|     ScopedName  scope;
   70|     std::string context;
   71| 
   72|     // Foundation
   73|     Reference()
   74|             : line(-1)
   75|     { }
   76|     Reference(const std::string& _file, int _line, const ScopedName& _scope, const std::string& _context)
   77|             : file(_file), line(_line), scope(_scope), context(_context)
   78|     { }
   79|     Reference(const Reference& other)
   80|             : file(other.file), line(other.line), scope(other.scope), context(other.context)
   81|     { }
   82| 
   83|     Referenceoperator=(const Reference& other)
   84|     {
   85|         file = other.file;
   86|         line = other.line;
   87|         scope = other.scope;
   88|         context = other.context;
   89|         return *this;
   90|     }
   91| };
   92| 
   93| //. Encapsulation of one Comment, which may span multiple lines.
   94| //. Each comment encapsulates one /* */ block or a block of // comments on
   95| //. adjacent lines. If extract_tails is set, then comments will be added
   96| //. even when they are not adjacent to a declaration - these comments will be
   97| //. marked as "suspect". Most of these will be discarded by the Linker, unless
   98| //. they have appropriate markings such as "//.< comment for previous decl"
   99| class Comment : public cleanup
  100| {
  101| public:
  102|     //. A vector of Comments
  103|     typedef std::vector<Comment*> vector;
  104| 
  105|     //. Constructor
  106|     Comment(SourceFile* file, int line, const std::string& text, bool suspect=false);
  107| 
  108|     //
  109|     // Attributes
  110|     //
  111| 
  112|     //. Returns the filename of this comment
  113|     SourceFile* file() const
  114|     {
  115|         return m_file;
  116|     }
  117| 
  118|     //. Returns the line number of the start of this comment
  119|     int line() const
  120|     {
  121|         return m_line;
  122|     }
  123| 
  124|     //. Returns the text of this comment
  125|     const std::stringtext() const
  126|     {
  127|         return m_text;
  128|     }
  129| 
  130|     //. Sets whether this comment is suspicious
  131|     void set_suspect(bool suspect)
  132|     {
  133|         m_suspect = suspect;
  134|     }
  135| 
  136|     //. Returns whether this comment is suspicious
  137|     bool is_suspect() const
  138|     {
  139|         return m_suspect;
  140|     }
  141| 
  142| private:
  143|     //. The file
  144|     SourceFile* m_file;
  145|     //. The first line number
  146|     int         m_line;
  147|     //. The text
  148|     std::string m_text;
  149|     //. True if this comment is probably not needed. The exception is comments
  150|     //. which will be used as "tails", eg: //.< comment for previous decl
  151|     bool        m_suspect;
  152| };
  153| 
  154| 
  155| //. The base class of the Declaration hierarchy.
  156| //. All declarations have a scoped Name, comments, etc. The filename and
  157| //. type name are constant strings. This is enforced so that the strings
  158| //. will reference the same data, saving both memory and cpu time. For this
  159| //. to work however, you must be careful to use the same strings for
  160| //. constructing the names from, for example from a dictionary.
  161| class Declaration : public cleanup
  162| {
  163| public:
  164|     //. A vector of Declaration objects
  165|     typedef std::vector<Declaration*> vector;
  166| 
  167|     //. Constructor
  168|     Declaration(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  169| 
  170|     //. Destructor. Recursively deletes the comments for this declaration
  171|     virtual
  172|     ~Declaration();
  173| 
  174|     //. Accept the given AST::Visitor
  175|     virtual void
  176|     accept(Visitor*);
  177| 
  178|     //
  179|     // Attribute Methods
  180|     //
  181| 
  182|     //. Returns the scoped name of this declaration
  183|     ScopedNamename()
  184|     {
  185|         return m_name;
  186|     }
  187| 
  188|     //. Constant version of name()
  189|     const ScopedNamename() const
  190|     {
  191|         return m_name;
  192|     }
  193| 
  194|     //. Returns the filename of this declaration
  195|     SourceFile* file() const
  196|     {
  197|         return m_file;
  198|     }
  199| 
  200|     //. Changes the filename of this declaration
  201|     void set_file(SourceFile* file)
  202|     {
  203|         m_file = file;
  204|     }
  205| 
  206|     //. Returns the line number of this declaration
  207|     int line() const
  208|     {
  209|         return m_line;
  210|     }
  211| 
  212|     //. Returns the name of the type (not class) of this declaration
  213|     const std::stringtype() const
  214|     {
  215|         return m_type;
  216|     }
  217| 
  218|     //. Change the type name. Currently only used to indicate template
  219|     //. types
  220|     void set_type(const std::string& type)
  221|     {
  222|         m_type = type;
  223|     }
  224| 
  225|     //. Returns the accessability of this declaration
  226|     Access access() const
  227|     {
  228|         return m_access;
  229|     }
  230| 
  231|     //. Sets the accessability of this declaration
  232|     void set_access(Access axs)
  233|     {
  234|         m_access = axs;
  235|     }
  236| 
  237|     //. Constant version of comments()
  238|     const Comment::vectorcomments() const
  239|     {
  240|         return m_comments;
  241|     }
  242| 
  243|     //. Returns the vector of comments. The vector returned is the private
  244|     //. member vector of this Declaration, so modifications will affect the
  245|     //. Declaration.
  246|     Comment::vectorcomments()
  247|     {
  248|         return m_comments;
  249|     }
  250| 
  251|     //. Return a cached Types::Declared for this Declaration. It is created
  252|     //. on demand and returned every time you call the method on this
  253|     //. object.
  254|     Types::Declared* declared();
  255| 
  256|     //. Return a cached Types::Declared for this Declaration. It is created
  257|     //. on demand and returned every time you call the method on this
  258|     //. object. This is the const version.
  259|     const Types::Declared* declared() const;
  260| 
  261| private:
  262|     //. The filename
  263|     SourceFile*     m_file;
  264|     //. The first line number
  265|     int             m_line;
  266|     //. The string type name
  267|     std::string     m_type;
  268|     //. The scoped name
  269|     ScopedName      m_name;
  270|     //. The vector of Comment objects
  271|     Comment::vector m_comments;
  272|     //. The accessability spec
  273|     Access          m_access;
  274|     //. The Types::Declared cache
  275|     mutable Types::Declared* m_declared;
  276| };
  277| 
  278| //. Information about an #include or #include_next directive.
  279| //. This object is a thin wrapper around the target SourceFile, with some
  280| //. attributes to indicate whether the directive included a macro expansion,
  281| //. and whether it was an #include_next or not.
  282| //.
  283| //. A macro expansion is flagged because often you don't want to include those
  284| //. in an include graph. For example, some headers in the Boost PP library
  285| //. will include other files multiple times, where the file included is given
  286| //. by a macro. It is rare that you actually want to show this macro-dependent
  287| //. include in the documentation or in a graph.
  288| class Include : public cleanup
  289| {
  290| public:
  291|     //. A vector of Includes
  292|     typedef std::vector<Include*> vector;
  293| 
  294|     //. Constructor
  295|     Include(SourceFile* target, bool is_macro, bool is_next);
  296| 
  297|     //. Returns the target of this include
  298|     SourceFile* target() const
  299|     {
  300|         return m_target;
  301|     }
  302| 
  303|     //. Returns whether the include filename was a macro expansion
  304|     bool is_macro() const
  305|     {
  306|         return m_is_macro;
  307|     }
  308| 
  309|     //. Returns whether the include was an #include_next directive
  310|     bool is_next() const
  311|     {
  312|         return m_is_next;
  313|     }
  314| 
  315| private:
  316|     //. The target file of the include or include_next
  317|     SourceFile* m_target;
  318| 
  319|     //. Whether the include filename was a macro expansion
  320|     bool m_is_macro;
  321| 
  322|     //. Whether the include was an #include_next directive
  323|     bool m_is_next;
  324| };
  325| 
  326| //. Information about a source file used to generate the AST.
  327| //.
  328| //. Generally an AST will include SourceFile objects for *all* files,
  329| //. including headers, that were used. The difference is that the main files
  330| //. (those named to the parser) are flagged as "main", and others will not
  331| //. have lists of declarations.
  332| class SourceFile : public cleanup
  333| {
  334| public:
  335|     //. A vector of SourceFiles
  336|     typedef std::vector<SourceFile*> vector;
  337| 
  338|     //. Constructor
  339|     SourceFile(const std::string& filename, const std::string& full_filename, bool is_main);
  340| 
  341|     //. Returns the filename of this SourceFile (may be stripped by a
  342|     //. basename)
  343|     const std::stringfilename() const
  344|     {
  345|         return m_filename;
  346|     }
  347| 
  348|     //. Returns the full filename of this SourceFile
  349|     const std::stringfull_filename() const
  350|     {
  351|         return m_full_filename;
  352|     }
  353| 
  354|     //. Returns whether this is a main file (as opposed to extra included file
  355|     //. just being stored for its list of includes)
  356|     bool is_main()
  357|     {
  358|         return m_is_main;
  359|     }
  360| 
  361|     //. Returns the vector of declarations in this file
  362|     Declaration::vectordeclarations()
  363|     {
  364|         return m_declarations;
  365|     }
  366| 
  367|     //. Returns a const vector of declarations in this file
  368|     const Declaration::vectordeclarations() const
  369|     {
  370|         return m_declarations;
  371|     }
  372| 
  373|     //. Returns a vector of includes in this file
  374|     Include::vectorincludes()
  375|     {
  376|         return m_includes;
  377|     }
  378| 
  379|     //. Returns a const vector of includes in this file
  380|     const Include::vectorincludes() const
  381|     {
  382|         return m_includes;
  383|     }
  384| 
  385| private:
  386|     //. The filename
  387|     std::string m_filename;
  388| 
  389|     //. The full filename
  390|     std::string m_full_filename;
  391| 
  392|     //. Whether this file is a main file 
  393|     bool m_is_main;
  394| 
  395|     //. The vector of declarations
  396|     Declaration::vector m_declarations;
  397| 
  398|     //. The vector of includes
  399|     Include::vector m_includes;
  400| };
  401| 
  402| 
  403| //. Encapsulates a preprocessor macro. Macros are stored in the AST, but since
  404| //. they are not regular C++ syntax they are treated specially: They will be
  405| //. in order compared to other macros, but not to the rest of the AST since
  406| //. the preprocessing stage occurs first. They will always be in the global
  407| //. scope. Note that the parameters is a pointer to a vector - if the pointer
  408| //. is null, then the macro is not function-like. If the pointer is non-null
  409| //. then it points to a vector of parameter names. If the macro is
  410| //. function-like but with no parameters, it is a pointer to an empty vector.
  411| class Macro : public Declaration
  412| {
  413| public:
  414|     //. The type of the parameters
  415|     typedef std::vector<std::stringParameters;
  416| 
  417|     //. Constructor. Assumes ownership of the Parameters vector if it is not a
  418|     //. null pointer.
  419|     Macro(SourceFile* file, int line, const ScopedName& name, Parameters* params, const std::string& text);
  420| 
  421|     //. Destructor
  422|     virtual ~Macro();
  423| 
  424|     //. The parameters of the macro. May be a null pointer if the macro is not
  425|     //. function-like
  426|     const Parametersparameters() const
  427|     {
  428|         return m_parameters;
  429|     }
  430| 
  431|     //. The expansion text of the macro.
  432|     const std::stringtext() const
  433|     {
  434|         return m_text;
  435|     }
  436| 
  437|     //. Accepts the given visitor
  438|     virtual void accept(Visitor*);
  439| 
  440| private:
  441|     //. The parameters
  442|     Parametersm_parameters;
  443| 
  444|     //. The expansion text
  445|     std::string m_text;
  446| };
  447| 
  448| //. Base class for scopes with contained declarations. Each scope has its
  449| //. own Dictionary of names so far accumulated for this scope. Each scope
  450| //. also as a complete vector of scopes where name lookup is to proceed if
  451| //. unsuccessful in this scope. Name lookup is not recursive.
  452| class Scope : public Declaration
  453| {
  454| public:
  455|     //. Constructor
  456|     Scope(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  457| 
  458|     //. Destructor.
  459|     //. Recursively destroys contained declarations
  460|     virtual ~Scope();
  461| 
  462|     //. Accepts the given visitor
  463|     virtual void accept(Visitor*);
  464| 
  465|     //
  466|     // Attribute Methods
  467|     //
  468| 
  469|     //. Constant version of declarations()
  470|     const Declaration::vectordeclarations() const
  471|     {
  472|         return m_declarations;
  473|     }
  474| 
  475|     //. Returns the vector of declarations. The vector returned is the
  476|     //. private member vector of this Scope, so modifications will affect
  477|     //. the Scope.
  478|     Declaration::vectordeclarations()
  479|     {
  480|         return m_declarations;
  481|     }
  482| 
  483| private:
  484|     //. The vector of contained declarations
  485|     Declaration::vector m_declarations;
  486| };
  487| 
  488| 
  489| //. Namespace class
  490| class Namespace : public Scope
  491| {
  492| public:
  493|     //. Constructor
  494|     Namespace(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  495|     //. Destructor
  496|     virtual
  497|     ~Namespace();
  498| 
  499|     //. Accepts the given AST::Visitor
  500|     virtual void
  501|     accept(Visitor*);
  502| }
  503| // class Namespace
  504| 
  505| 
  506| //. Inheritance class. This class encapsulates the information about an
  507| //. inheritance, namely its accessability. Note that classes inherit from
  508| //. types, not class declarations. As such it's possible to inherit from a
  509| //. parameterized type, or a declared typedef or class/struct.
  510| class Inheritance
  511| {
  512| public:
  513|     //. A vector of Inheritance objects
  514|     typedef std::vector<Inheritance*> vector;
  515| 
  516|     //. A typedef of the Attributes type
  517|     typedef std::vector<std::stringAttributes;
  518| 
  519|     //. Constructor
  520|     Inheritance(Types::Type* parent, const Attributes& attributes);
  521| 
  522|     //. Accepts the given AST::Visitor
  523|     void accept(Visitor*);
  524| 
  525|     //
  526|     // Attribute Methods
  527|     //
  528| 
  529|     //. Returns the Class object this inheritance refers to. The method
  530|     //. returns a Type since typedefs to classes are preserved to
  531|     //. enhance readability of the generated docs. Note that the parent
  532|     //. may also be a non-declaration type, such as vector<int>
  533|     Types::Type* parent()
  534|     {
  535|         return m_parent;
  536|     }
  537| 
  538|     //. Returns the attributes of this inheritance
  539|     const Attributesattributes() const
  540|     {
  541|         return m_attrs;
  542|     }
  543| 
  544| private:
  545|     //. The parent class or typedef to class
  546|     Types::Type* m_parent;
  547|     //. The attributes
  548|     Attributes  m_attrs;
  549| };
  550| 
  551| 
  552| //. Class class
  553| class Class : public Scope
  554| {
  555| public:
  556|     //. Constructor
  557|     Class(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  558| 
  559|     //. Destructor. Recursively destroys Inheritance objects
  560|     virtual ~Class();
  561| 
  562|     //. Accepts the given AST::Visitor
  563|     virtual void accept(Visitor*);
  564| 
  565|     //
  566|     // Attribute Methods
  567|     //
  568| 
  569|     //. Constant version of parents()
  570|     const Inheritance::vectorparents() const
  571|     {
  572|         return m_parents;
  573|     }
  574| 
  575|     //. Returns the vector of parent Inheritance objects. The vector
  576|     //. returned is the private member vector of this Class, so
  577|     //. modifications will affect the Class.
  578|     Inheritance::vectorparents()
  579|     {
  580|         return m_parents;
  581|     }
  582| 
  583|     //. Returns the Template object if this is a template
  584|     Types::Template* template_type()
  585|     {
  586|         return m_template;
  587|     }
  588| 
  589|     //. Sets the Template object for this class. NULL means not a template
  590|     void set_template_type(Types::Template* type)
  591|     {
  592|         m_template = type;
  593|     }
  594| 
  595| private:
  596|     //. The vector of parent Inheritance objects
  597|     Inheritance::vector m_parents;
  598|     //. The Template Type for this class if it's a template
  599|     Types::Template*     m_template;
  600| };
  601| 
  602| 
  603| //. Forward declaration. Currently this has no extra attributes.
  604| class Forward : public Declaration
  605| {
  606| public:
  607|     //. Constructor
  608|     Forward(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  609|     //. Constructor that copies an existing declaration
  610|     Forward(AST::Declaration* decl);
  611| 
  612|     //. Accepts the given AST::Visitor
  613|     virtual void accept(Visitor*);
  614| 
  615|     //. Returns the Template object if this is a template
  616|     Types::Template* template_type()
  617|     {
  618|         return m_template;
  619|     }
  620| 
  621|     //. Sets the Template object for this class. NULL means not a template
  622|     void set_template_type(Types::Template* type)
  623|     {
  624|         m_template = type;
  625|     }
  626| 
  627| private:
  628|     //. The Template Type for this forward if it's a template
  629|     Types::Template*     m_template;
  630| };
  631| 
  632| 
  633| //. Typedef declaration
  634| class Typedef : public Declaration
  635| {
  636| public:
  637|     //. Constructor
  638|     Typedef(SourceFile* file, int line, const std::string& type, const ScopedName& name, Types::Type* alias, bool constr);
  639| 
  640|     //. Destructor
  641|     ~Typedef();
  642| 
  643|     //. Accepts the given AST::Visitor
  644|     virtual void accept(Visitor*);
  645| 
  646|     //
  647|     // Attribute Methods
  648|     //
  649| 
  650|     //. Returns the Type object this typedef aliases
  651|     Types::Type* alias()
  652|     {
  653|         return m_alias;
  654|     }
  655| 
  656|     //. Returns true if the Type object was constructed inside the typedef
  657|     bool constructed()
  658|     {
  659|         return m_constr;
  660|     }
  661| 
  662| private:
  663|     //. The alias Type
  664|     Types::Type* m_alias;
  665| 
  666|     //. True if constructed
  667|     bool         m_constr;
  668| };
  669| 
  670| 
  671| //. Variable declaration
  672| class Variable : public Declaration
  673| {
  674| public:
  675|     //. The type of the vector of sizes
  676|     typedef std::vector<size_tSizes;
  677| 
  678|     //. Constructor
  679|     Variable(SourceFile* file, int line, const std::string& type, const ScopedName& name, Types::Type* vtype, bool constr);
  680| 
  681|     //. Destructor
  682|     ~Variable();
  683| 
  684|     //. Accepts the given AST::Visitor
  685|     virtual void accept(Visitor*);
  686| 
  687|     //
  688|     // Attribute Methods
  689|     //
  690| 
  691|     //. Returns the Type object of this variable
  692|     Types::Type* vtype() const
  693|     {
  694|         return m_vtype;
  695|     }
  696| 
  697|     //. Returns true if the Type object was constructed inside the variable
  698|     bool constructed() const
  699|     {
  700|         return m_constr;
  701|     }
  702| 
  703|     //. Returns the array sizes vector
  704|     Sizessizes()
  705|     {
  706|         return m_sizes;
  707|     }
  708| 
  709| private:
  710|     //. The variable Type
  711|     Types::Type* m_vtype;
  712| 
  713|     //. True if constructed
  714|     bool         m_constr;
  715| 
  716|     //. Vector of array sizes. zero length indicates not an array.
  717|     Sizes        m_sizes;
  718| };
  719| 
  720| 
  721| //. Enumerator declaration. This is a name with a value in the containing
  722| //. scope. Enumerators only appear inside Enums via their enumerators()
  723| //. attribute.
  724| class Enumerator : public Declaration
  725| {
  726| public:
  727|     //. Type of a vector of Enumerator objects
  728|     typedef std::vector<Enumerator*> vector;
  729| 
  730|     //. Constructor
  731|     Enumerator(SourceFile* file, int line, const std::string& type, const ScopedName& name, const std::string& value);
  732| 
  733|     //. Accept the given AST::Visitor
  734|     virtual void accept(Visitor*);
  735| 
  736|     //
  737|     // Attribute Methods
  738|     //
  739| 
  740|     //. Returns the value of this enumerator
  741|     const std::stringvalue() const
  742|     {
  743|         return m_value;
  744|     }
  745| 
  746| private:
  747|     //. The value of this enumerator
  748|     std::string m_value;
  749| };
  750| 
  751| 
  752| //. Enum declaration. An enum contains multiple enumerators.
  753| class Enum : public Declaration
  754| {
  755| public:
  756|     //. Constructor
  757|     Enum(SourceFile* file, int line, const std::string& type, const ScopedName& name);
  758|     //. Destructor. Recursively destroys Enumerators
  759|     ~Enum();
  760| 
  761|     //. Accepts the given AST::Visitor
  762|     virtual void
  763|     accept(Visitor*);
  764| 
  765|     //
  766|     // Attribute Methods
  767|     //
  768| 
  769|     //. Returns the vector of Enumerators
  770|     Enumerator::vectorenumerators()
  771|     {
  772|         return m_enums;
  773|     }
  774| 
  775| private:
  776|     //. The vector of Enumerators
  777|     Enumerator::vector m_enums;
  778| };
  779| 
  780| 
  781| //. A const is a name with a value and declared type.
  782| class Const : public Declaration
  783| {
  784| public:
  785|     //. Constructor
  786|     Const(SourceFile* file, int line, const std::string& type, const ScopedName& name, Types::Type* ctype, const std::string& value);
  787| 
  788|     //. Accept the given AST::Visitor
  789|     virtual void accept(Visitor*);
  790| 
  791|     //
  792|     // Attribute Methods
  793|     //
  794| 
  795|     //. Returns the Type object of this const
  796|     Types::Type* ctype()
  797|     {
  798|         return m_ctype;
  799|     }
  800| 
  801|     //. Returns the value of this enumerator
  802|     const std::stringvalue() const
  803|     {
  804|         return m_value;
  805|     }
  806| 
  807| private:
  808|     //. The const Type
  809|     Types::Type* m_ctype;
  810| 
  811|     //. The value of this enumerator
  812|     std::string m_value;
  813| };
  814| 
  815| 
  816| //. Parameter encapsulates one parameter to a function
  817| class Parameter : public cleanup
  818| {
  819| public:
  820|     //. The type of modifiers such as 'in', 'out'
  821|     typedef std::vector<std::stringMods;
  822| 
  823|     //. A vector of Parameter objects
  824|     typedef std::vector<Parameter*> vector;
  825| 
  826|     //. Constructor
  827|     Parameter(const Mods& pre, Types::Type* type, const Mods& post, const std::string& name, const std::string& value);
  828| 
  829|     //. Destructor
  830|     ~Parameter();
  831| 
  832|     //. Accept the given AST::Visitor. Note this is not derived from
  833|     //. Declaration so it is not a virtual method.
  834|     void accept(Visitor*);
  835| 
  836|     //
  837|     // Attribute Methods
  838|     //
  839| 
  840|     //. Returns the premodifier
  841|     Modspremodifier()
  842|     {
  843|         return m_pre;
  844|     }
  845| 
  846|     //. Returns the postmodifier
  847|     Modspostmodifier()
  848|     {
  849|         return m_post;
  850|     }
  851| 
  852|     //. Returns the type of the parameter
  853|     Types::Type* type()
  854|     {
  855|         return m_type;
  856|     }
  857| 
  858|     //. Const version of type()
  859|     const Types::Type* type() const
  860|     {
  861|         return m_type;
  862|     }
  863| 
  864|     //. Returns the name of the parameter
  865|     const std::stringname() const
  866|     {
  867|         return m_name;
  868|     }
  869| 
  870|     //. Returns the value of the parameter
  871|     const std::stringvalue() const
  872|     {
  873|         return m_value;
  874|     }
  875| 
  876|     //. Sets the name of the parameter
  877|     void set_name(const std::string& name)
  878|     {
  879|         m_name = name;
  880|     }
  881| private:
  882|     Mods        m_prem_post;
  883|     Types::Type* m_type;
  884|     std::string m_namem_value;
  885| };
  886| 
  887| 
  888| //. Function encapsulates a function declaration. Note that names may be
  889| //. stored in mangled form, and formatters should use realname() to get
  890| //. the unmangled version. If this is a function template, use the
  891| //. template_type() method to get at the template type
  892| class Function : public Declaration
  893| {
  894| public:
  895|     //. The type of premodifiers
  896|     typedef std::vector<std::stringMods;
  897| 
  898|     //. A vector of Function objects
  899|     typedef std::vector<Function*> vector;
  900| 
  901|     //. Constructor
  902|     Function(
  903|         SourceFile* file, int line, const std::string& type, const ScopedName& name,
  904|         const Mods& premod, Types::Type* ret, const std::string& realname
  905|     );
  906| 
  907|     //. Destructor. Recursively destroys parameters
  908|     ~Function();
  909| 
  910|     //. Accept the given visitor
  911|     virtual void accept(Visitor*);
  912| 
  913|     //
  914|     // Attribute Methods
  915|     //
  916| 
  917|     //. Returns the premodifier vector
  918|     Modspremodifier()
  919|     {
  920|         return m_pre;
  921|     }
  922| 
  923|     //. Returns the return Type
  924|     Types::Type* return_type()
  925|     {
  926|         return m_ret;
  927|     }
  928| 
  929|     //. Returns the real name of this function
  930|     const std::stringrealname() const
  931|     {
  932|         return m_realname;
  933|     }
  934| 
  935|     //. Returns the vector of parameters
  936|     Parameter::vectorparameters()
  937|     {
  938|         return m_params;
  939|     }
  940| 
  941|     //. Returns the Template object if this is a template
  942|     Types::Template* template_type()
  943|     {
  944|         return m_template;
  945|     }
  946| 
  947|     //. Sets the Template object for this class. NULL means not a template
  948|     void set_template_type(Types::Template* type)
  949|     {
  950|         m_template = type;
  951|     }
  952| private:
  953|     //. The premodifier vector
  954|     Mods              m_pre;
  955|     //. The return type
  956|     Types::Type*      m_ret;
  957|     //. The real (unmangled) name
  958|     std::string       m_realname;
  959|     //. The vector of parameters
  960|     Parameter::vector m_params;
  961|     //. The Template Type for this class if it's a template
  962|     Types::Template*  m_template;
  963| };
  964| 
  965| 
  966| //. Operations are similar to functions but Not Quite Right
  967| class Operation : public Function
  968| {
  969| public:
  970|     //. Constructor
  971|     Operation(SourceFile* file, int line, const std::string& type, const ScopedName& name, const Mods& modifiers, Types::Type* ret, const std::string& realname);
  972| 
  973|     //. Accept the given visitor
  974|     virtual void
  975|     accept(Visitor*);
  976| };
  977| 
  978| 
  979| //. The Visitor for the AST hierarchy. This class is just an interface
  980| //. really. It is abstract, and you must reimplement any methods you want.
  981| //. The default implementations of the methods call the visit methods for
  982| //. the subclasses of the visited type, eg visit_namespace calls visit_scope
  983| //. which calls visit_declaration.
  984| class Visitor
  985| {
  986| public:
  987|     // Abstract destructor makes the class abstract
  988|     virtual ~Visitor() = 0;
  989|     virtual void visit_declaration(Declaration*);
  990|     virtual void visit_macro(Macro*);
  991|     virtual void visit_scope(Scope*);
  992|     virtual void visit_namespace(Namespace*);
  993|     virtual void visit_class(Class*);
  994|     virtual void visit_inheritance(Inheritance*);
  995|     virtual void visit_forward(Forward*);
  996|     virtual void visit_typedef(Typedef*);
  997|     virtual void visit_variable(Variable*);
  998|     virtual void visit_const(Const*);
  999|     virtual void visit_enum(Enum*);
 1000|     virtual void visit_enumerator(Enumerator*);
 1001|     virtual void visit_function(Function*);
 1002|     virtual void visit_operation(Operation*);
 1003|     virtual void visit_parameter(Parameter*);
 1004| };
 1005| 
 1006| // namespace AST
 1007| 
 1008| #endif // header guard
 1009| 
 1010| // vim: set ts=8 sts=4 sw=4 et: