Commit 2f905392 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Reimplemented Symbol::as*() methods using virtual functions.

parent d782ce27
......@@ -320,102 +320,36 @@ bool Symbol::isPrivate() const
{ return _visibility == Private; }
bool Symbol::isScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this) != 0; }
{ return asScopedSymbol() != 0; }
bool Symbol::isEnum() const
{ return dynamic_cast<const Enum *>(this) != 0; }
{ return asEnum() != 0; }
bool Symbol::isFunction() const
{ return dynamic_cast<const Function *>(this) != 0; }
{ return asFunction() != 0; }
bool Symbol::isNamespace() const
{ return dynamic_cast<const Namespace *>(this) != 0; }
{ return asNamespace() != 0; }
bool Symbol::isClass() const
{ return dynamic_cast<const Class *>(this) != 0; }
{ return asClass() != 0; }
bool Symbol::isBlock() const
{ return dynamic_cast<const Block *>(this) != 0; }
{ return asBlock() != 0; }
bool Symbol::isUsingNamespaceDirective() const
{ return dynamic_cast<const UsingNamespaceDirective *>(this) != 0; }
{ return asUsingNamespaceDirective() != 0; }
bool Symbol::isUsingDeclaration() const
{ return dynamic_cast<const UsingDeclaration *>(this) != 0; }
{ return asUsingDeclaration() != 0; }
bool Symbol::isDeclaration() const
{ return dynamic_cast<const Declaration *>(this) != 0; }
{ return asDeclaration() != 0; }
bool Symbol::isArgument() const
{ return dynamic_cast<const Argument *>(this) != 0; }
{ return asArgument() != 0; }
bool Symbol::isBaseClass() const
{ return dynamic_cast<const BaseClass *>(this) != 0; }
const ScopedSymbol *Symbol::asScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this); }
const Enum *Symbol::asEnum() const
{ return dynamic_cast<const Enum *>(this); }
const Function *Symbol::asFunction() const
{ return dynamic_cast<const Function *>(this); }
const Namespace *Symbol::asNamespace() const
{ return dynamic_cast<const Namespace *>(this); }
const Class *Symbol::asClass() const
{ return dynamic_cast<const Class *>(this); }
const Block *Symbol::asBlock() const
{ return dynamic_cast<const Block *>(this); }
const UsingNamespaceDirective *Symbol::asUsingNamespaceDirective() const
{ return dynamic_cast<const UsingNamespaceDirective *>(this); }
const UsingDeclaration *Symbol::asUsingDeclaration() const
{ return dynamic_cast<const UsingDeclaration *>(this); }
const Declaration *Symbol::asDeclaration() const
{ return dynamic_cast<const Declaration *>(this); }
const Argument *Symbol::asArgument() const
{ return dynamic_cast<const Argument *>(this); }
const BaseClass *Symbol::asBaseClass() const
{ return dynamic_cast<const BaseClass *>(this); }
ScopedSymbol *Symbol::asScopedSymbol()
{ return dynamic_cast<ScopedSymbol *>(this); }
Enum *Symbol::asEnum()
{ return dynamic_cast<Enum *>(this); }
Function *Symbol::asFunction()
{ return dynamic_cast<Function *>(this); }
Namespace *Symbol::asNamespace()
{ return dynamic_cast<Namespace *>(this); }
Class *Symbol::asClass()
{ return dynamic_cast<Class *>(this); }
Block *Symbol::asBlock()
{ return dynamic_cast<Block *>(this); }
UsingNamespaceDirective *Symbol::asUsingNamespaceDirective()
{ return dynamic_cast<UsingNamespaceDirective *>(this); }
UsingDeclaration *Symbol::asUsingDeclaration()
{ return dynamic_cast<UsingDeclaration *>(this); }
Declaration *Symbol::asDeclaration()
{ return dynamic_cast<Declaration *>(this); }
Argument *Symbol::asArgument()
{ return dynamic_cast<Argument *>(this); }
BaseClass *Symbol::asBaseClass()
{ return dynamic_cast<BaseClass *>(this); }
{ return asBaseClass() != 0; }
CPLUSPLUS_END_NAMESPACE
......@@ -197,29 +197,29 @@ public:
/// Returns true if this Symbol is a BaseClass.
bool isBaseClass() const;
const ScopedSymbol *asScopedSymbol() const;
const Enum *asEnum() const;
const Function *asFunction() const;
const Namespace *asNamespace() const;
const Class *asClass() const;
const Block *asBlock() const;
const UsingNamespaceDirective *asUsingNamespaceDirective() const;
const UsingDeclaration *asUsingDeclaration() const;
const Declaration *asDeclaration() const;
const Argument *asArgument() const;
const BaseClass *asBaseClass() const;
ScopedSymbol *asScopedSymbol();
Enum *asEnum();
Function *asFunction();
Namespace *asNamespace();
Class *asClass();
Block *asBlock();
UsingNamespaceDirective *asUsingNamespaceDirective();
UsingDeclaration *asUsingDeclaration();
Declaration *asDeclaration();
Argument *asArgument();
BaseClass *asBaseClass();
virtual const ScopedSymbol *asScopedSymbol() const { return 0; }
virtual const Enum *asEnum() const { return 0; }
virtual const Function *asFunction() const { return 0; }
virtual const Namespace *asNamespace() const { return 0; }
virtual const Class *asClass() const { return 0; }
virtual const Block *asBlock() const { return 0; }
virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const { return 0; }
virtual const UsingDeclaration *asUsingDeclaration() const { return 0; }
virtual const Declaration *asDeclaration() const { return 0; }
virtual const Argument *asArgument() const { return 0; }
virtual const BaseClass *asBaseClass() const { return 0; }
virtual ScopedSymbol *asScopedSymbol() { return 0; }
virtual Enum *asEnum() { return 0; }
virtual Function *asFunction() { return 0; }
virtual Namespace *asNamespace() { return 0; }
virtual Class *asClass() { return 0; }
virtual Block *asBlock() { return 0; }
virtual UsingNamespaceDirective *asUsingNamespaceDirective() { return 0; }
virtual UsingDeclaration *asUsingDeclaration() { return 0; }
virtual Declaration *asDeclaration() { return 0; }
virtual Argument *asArgument() { return 0; }
virtual BaseClass *asBaseClass() { return 0; }
/// Returns this Symbol's type.
virtual FullySpecifiedType type() const = 0;
......
......@@ -71,6 +71,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const UsingNamespaceDirective *asUsingNamespaceDirective() const
{ return this; }
virtual UsingNamespaceDirective *asUsingNamespaceDirective()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
......@@ -84,6 +90,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const UsingDeclaration *asUsingDeclaration() const
{ return this; }
virtual UsingDeclaration *asUsingDeclaration()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
......@@ -105,6 +117,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const Declaration *asDeclaration() const
{ return this; }
virtual Declaration *asDeclaration()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
......@@ -127,6 +145,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const Argument *asArgument() const
{ return this; }
virtual Argument *asArgument()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
......@@ -146,6 +170,12 @@ public:
Scope *members() const;
void addMember(Symbol *member);
virtual const ScopedSymbol *asScopedSymbol() const
{ return this; }
virtual ScopedSymbol *asScopedSymbol()
{ return this; }
private:
Scope *_members;
};
......@@ -159,6 +189,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const Block *asBlock() const
{ return this; }
virtual Block *asBlock()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
......@@ -175,6 +211,12 @@ public:
// Type's interface
virtual bool isEqualTo(const Type *other) const;
virtual const Enum *asEnum() const
{ return this; }
virtual Enum *asEnum()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
......@@ -230,6 +272,12 @@ public:
// Type's interface
virtual bool isEqualTo(const Type *other) const;
virtual const Function *asFunction() const
{ return this; }
virtual Function *asFunction()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
......@@ -264,6 +312,12 @@ public:
// Type's interface
virtual bool isEqualTo(const Type *other) const;
virtual const Namespace *asNamespace() const
{ return this; }
virtual Namespace *asNamespace()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
......@@ -281,6 +335,12 @@ public:
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const BaseClass *asBaseClass() const
{ return this; }
virtual BaseClass *asBaseClass()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
......@@ -322,6 +382,12 @@ public:
// Type's interface
virtual bool isEqualTo(const Type *other) const;
virtual const Class *asClass() const
{ return this; }
virtual Class *asClass()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment