2020-03-02 20:47:43 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef SRC_AST_STATEMENT_H_
|
|
|
|
#define SRC_AST_STATEMENT_H_
|
|
|
|
|
2020-04-06 19:37:37 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
#include "src/ast/node.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
|
|
|
|
class AssignmentStatement;
|
2020-07-27 15:25:00 +00:00
|
|
|
class BlockStatement;
|
2020-03-02 20:47:43 +00:00
|
|
|
class BreakStatement;
|
2020-07-21 13:42:05 +00:00
|
|
|
class CallStatement;
|
2020-03-02 20:47:43 +00:00
|
|
|
class CaseStatement;
|
|
|
|
class ContinueStatement;
|
2020-07-25 03:34:33 +00:00
|
|
|
class DiscardStatement;
|
2020-03-02 20:47:43 +00:00
|
|
|
class ElseStatement;
|
|
|
|
class FallthroughStatement;
|
|
|
|
class IfStatement;
|
|
|
|
class LoopStatement;
|
|
|
|
class ReturnStatement;
|
|
|
|
class SwitchStatement;
|
2020-03-30 22:46:48 +00:00
|
|
|
class VariableDeclStatement;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
/// Base statement class
|
|
|
|
class Statement : public Node {
|
|
|
|
public:
|
|
|
|
~Statement() override;
|
|
|
|
|
|
|
|
/// @returns true if this is an assign statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsAssign() const;
|
2020-07-27 15:25:00 +00:00
|
|
|
/// @returns true if this is a block statement
|
|
|
|
virtual bool IsBlock() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a break statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsBreak() const;
|
2020-07-21 13:42:05 +00:00
|
|
|
/// @returns true if this is a call statement
|
|
|
|
virtual bool IsCall() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a case statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsCase() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a continue statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsContinue() const;
|
2020-07-25 03:34:33 +00:00
|
|
|
/// @returns true if this is a discard statement
|
|
|
|
virtual bool IsDiscard() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is an else statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsElse() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a fallthrough statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsFallthrough() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is an if statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsIf() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a loop statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsLoop() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a return statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsReturn() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is a switch statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsSwitch() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns true if this is an variable statement
|
2020-04-09 18:52:06 +00:00
|
|
|
virtual bool IsVariableDecl() const;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2020-04-23 13:52:10 +00:00
|
|
|
/// @returns the statement as a const assign statement
|
|
|
|
const AssignmentStatement* AsAssign() const;
|
2020-07-27 15:25:00 +00:00
|
|
|
/// @returns the statement as a const block statement
|
|
|
|
const BlockStatement* AsBlock() const;
|
2020-04-23 13:52:10 +00:00
|
|
|
/// @returns the statement as a const break statement
|
|
|
|
const BreakStatement* AsBreak() const;
|
2020-07-21 13:42:05 +00:00
|
|
|
/// @returns the statement as a const call statement
|
|
|
|
const CallStatement* AsCall() const;
|
2020-04-23 13:52:10 +00:00
|
|
|
/// @returns the statement as a const case statement
|
|
|
|
const CaseStatement* AsCase() const;
|
|
|
|
/// @returns the statement as a const continue statement
|
|
|
|
const ContinueStatement* AsContinue() const;
|
2020-07-25 03:34:33 +00:00
|
|
|
/// @returns the statement as a const discard statement
|
|
|
|
const DiscardStatement* AsDiscard() const;
|
2020-04-23 13:52:10 +00:00
|
|
|
/// @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 loop statement
|
|
|
|
const LoopStatement* AsLoop() 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 variable statement
|
|
|
|
const VariableDeclStatement* AsVariableDecl() const;
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns the statement as an assign statement
|
|
|
|
AssignmentStatement* AsAssign();
|
2020-07-27 15:25:00 +00:00
|
|
|
/// @returns the statement as a block statement
|
|
|
|
BlockStatement* AsBlock();
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns the statement as a break statement
|
|
|
|
BreakStatement* AsBreak();
|
2020-07-21 13:42:05 +00:00
|
|
|
/// @returns the statement as a call statement
|
|
|
|
CallStatement* AsCall();
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns the statement as a case statement
|
|
|
|
CaseStatement* AsCase();
|
|
|
|
/// @returns the statement as a continue statement
|
|
|
|
ContinueStatement* AsContinue();
|
2020-07-25 03:34:33 +00:00
|
|
|
/// @returns the statement as a discard statement
|
|
|
|
DiscardStatement* AsDiscard();
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns the statement as a else statement
|
|
|
|
ElseStatement* AsElse();
|
|
|
|
/// @returns the statement as a fallthrough statement
|
|
|
|
FallthroughStatement* AsFallthrough();
|
|
|
|
/// @returns the statement as a if statement
|
|
|
|
IfStatement* AsIf();
|
|
|
|
/// @returns the statement as a loop statement
|
|
|
|
LoopStatement* AsLoop();
|
|
|
|
/// @returns the statement as a return statement
|
|
|
|
ReturnStatement* AsReturn();
|
|
|
|
/// @returns the statement as a switch statement
|
|
|
|
SwitchStatement* AsSwitch();
|
|
|
|
/// @returns the statement as an variable statement
|
2020-03-30 22:46:48 +00:00
|
|
|
VariableDeclStatement* AsVariableDecl();
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Constructor
|
|
|
|
Statement();
|
|
|
|
/// Constructor
|
|
|
|
/// @param source the source of the expression
|
|
|
|
explicit Statement(const Source& source);
|
|
|
|
/// Move constructor
|
2020-04-09 18:52:06 +00:00
|
|
|
Statement(Statement&&);
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Statement(const Statement&) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // SRC_AST_STATEMENT_H_
|