diff --git a/src/ast/statement.cc b/src/ast/statement.cc index 53f60366c1..a5d7f3616c 100644 --- a/src/ast/statement.cc +++ b/src/ast/statement.cc @@ -98,6 +98,76 @@ bool Statement::IsVariableDecl() const { return false; } +const AssignmentStatement* Statement::AsAssign() const { + assert(IsAssign()); + return static_cast(this); +} + +const BreakStatement* Statement::AsBreak() const { + assert(IsBreak()); + return static_cast(this); +} + +const CaseStatement* Statement::AsCase() const { + assert(IsCase()); + return static_cast(this); +} + +const ContinueStatement* Statement::AsContinue() const { + assert(IsContinue()); + return static_cast(this); +} + +const ElseStatement* Statement::AsElse() const { + assert(IsElse()); + return static_cast(this); +} + +const FallthroughStatement* Statement::AsFallthrough() const { + assert(IsFallthrough()); + return static_cast(this); +} + +const IfStatement* Statement::AsIf() const { + assert(IsIf()); + return static_cast(this); +} + +const KillStatement* Statement::AsKill() const { + assert(IsKill()); + return static_cast(this); +} + +const LoopStatement* Statement::AsLoop() const { + assert(IsLoop()); + return static_cast(this); +} + +const NopStatement* Statement::AsNop() const { + assert(IsNop()); + return static_cast(this); +} + +const ReturnStatement* Statement::AsReturn() const { + assert(IsReturn()); + return static_cast(this); +} + +const SwitchStatement* Statement::AsSwitch() const { + assert(IsSwitch()); + return static_cast(this); +} + +const UnlessStatement* Statement::AsUnless() const { + assert(IsUnless()); + return static_cast(this); +} + +const VariableDeclStatement* Statement::AsVariableDecl() const { + assert(IsVariableDecl()); + return static_cast(this); +} + AssignmentStatement* Statement::AsAssign() { assert(IsAssign()); return static_cast(this); diff --git a/src/ast/statement.h b/src/ast/statement.h index e084b73d90..c3188acca6 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -72,6 +72,35 @@ class Statement : public Node { /// @returns true if this is an variable statement virtual bool IsVariableDecl() const; + /// @returns the statement as a const assign statement + const AssignmentStatement* AsAssign() const; + /// @returns the statement as a const break statement + const BreakStatement* AsBreak() const; + /// @returns the statement as a const case statement + const CaseStatement* AsCase() const; + /// @returns the statement as a const continue statement + const ContinueStatement* AsContinue() const; + /// @returns the statement as a const else statement + const ElseStatement* AsElse() const; + /// @returns the statement as a const fallthrough statement + const FallthroughStatement* AsFallthrough() const; + /// @returns the statement as a const if statement + const IfStatement* AsIf() const; + /// @returns the statement as a const kill statement + const KillStatement* AsKill() const; + /// @returns the statement as a const loop statement + const LoopStatement* AsLoop() const; + /// @returns the statement as a const nop statement + const NopStatement* AsNop() const; + /// @returns the statement as a const return statement + const ReturnStatement* AsReturn() const; + /// @returns the statement as a const switch statement + const SwitchStatement* AsSwitch() const; + /// @returns the statement as a const unless statement + const UnlessStatement* AsUnless() const; + /// @returns the statement as a const variable statement + const VariableDeclStatement* AsVariableDecl() const; + /// @returns the statement as an assign statement AssignmentStatement* AsAssign(); /// @returns the statement as a break statement