Synopsis - Cross-Reference

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