Adding const As.* functions to statement class

Change-Id: Ie9c0cecfce1ebb7decf377cee7053fb7ae0dee9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20260
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Sarah Mashayekhi 2020-04-23 13:52:10 +00:00 committed by dan sinclair
parent 13a652963c
commit 194b6a2fce
2 changed files with 99 additions and 0 deletions

View File

@ -98,6 +98,76 @@ bool Statement::IsVariableDecl() const {
return false; return false;
} }
const AssignmentStatement* Statement::AsAssign() const {
assert(IsAssign());
return static_cast<const AssignmentStatement*>(this);
}
const BreakStatement* Statement::AsBreak() const {
assert(IsBreak());
return static_cast<const BreakStatement*>(this);
}
const CaseStatement* Statement::AsCase() const {
assert(IsCase());
return static_cast<const CaseStatement*>(this);
}
const ContinueStatement* Statement::AsContinue() const {
assert(IsContinue());
return static_cast<const ContinueStatement*>(this);
}
const ElseStatement* Statement::AsElse() const {
assert(IsElse());
return static_cast<const ElseStatement*>(this);
}
const FallthroughStatement* Statement::AsFallthrough() const {
assert(IsFallthrough());
return static_cast<const FallthroughStatement*>(this);
}
const IfStatement* Statement::AsIf() const {
assert(IsIf());
return static_cast<const IfStatement*>(this);
}
const KillStatement* Statement::AsKill() const {
assert(IsKill());
return static_cast<const KillStatement*>(this);
}
const LoopStatement* Statement::AsLoop() const {
assert(IsLoop());
return static_cast<const LoopStatement*>(this);
}
const NopStatement* Statement::AsNop() const {
assert(IsNop());
return static_cast<const NopStatement*>(this);
}
const ReturnStatement* Statement::AsReturn() const {
assert(IsReturn());
return static_cast<const ReturnStatement*>(this);
}
const SwitchStatement* Statement::AsSwitch() const {
assert(IsSwitch());
return static_cast<const SwitchStatement*>(this);
}
const UnlessStatement* Statement::AsUnless() const {
assert(IsUnless());
return static_cast<const UnlessStatement*>(this);
}
const VariableDeclStatement* Statement::AsVariableDecl() const {
assert(IsVariableDecl());
return static_cast<const VariableDeclStatement*>(this);
}
AssignmentStatement* Statement::AsAssign() { AssignmentStatement* Statement::AsAssign() {
assert(IsAssign()); assert(IsAssign());
return static_cast<AssignmentStatement*>(this); return static_cast<AssignmentStatement*>(this);

View File

@ -72,6 +72,35 @@ class Statement : public Node {
/// @returns true if this is an variable statement /// @returns true if this is an variable statement
virtual bool IsVariableDecl() const; 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 /// @returns the statement as an assign statement
AssignmentStatement* AsAssign(); AssignmentStatement* AsAssign();
/// @returns the statement as a break statement /// @returns the statement as a break statement