1// Copyright 2020 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "src/ast/statement.h"
16
17#include "src/ast/assignment_statement.h"
18#include "src/ast/break_statement.h"
19#include "src/ast/call_statement.h"
20#include "src/ast/continue_statement.h"
21#include "src/ast/discard_statement.h"
22#include "src/ast/fallthrough_statement.h"
23#include "src/ast/if_statement.h"
24#include "src/ast/loop_statement.h"
25#include "src/ast/return_statement.h"
26#include "src/ast/switch_statement.h"
27#include "src/ast/variable_decl_statement.h"
28
29TINT_INSTANTIATE_TYPEINFO(tint::ast::Statement);
30
31namespace tint {
32namespace ast {
33
34Statement::Statement(ProgramID pid, const Source& src) : Base(pid, src) {}
35
36Statement::Statement(Statement&&) = default;
37
38Statement::~Statement() = default;
39
40const char* Statement::Name() const {
41  if (Is<AssignmentStatement>()) {
42    return "assignment statement";
43  }
44  if (Is<BlockStatement>()) {
45    return "block statement";
46  }
47  if (Is<BreakStatement>()) {
48    return "break statement";
49  }
50  if (Is<CaseStatement>()) {
51    return "case statement";
52  }
53  if (Is<CallStatement>()) {
54    return "function call";
55  }
56  if (Is<ContinueStatement>()) {
57    return "continue statement";
58  }
59  if (Is<DiscardStatement>()) {
60    return "discard statement";
61  }
62  if (Is<ElseStatement>()) {
63    return "else statement";
64  }
65  if (Is<FallthroughStatement>()) {
66    return "fallthrough statement";
67  }
68  if (Is<IfStatement>()) {
69    return "if statement";
70  }
71  if (Is<LoopStatement>()) {
72    return "loop statement";
73  }
74  if (Is<ReturnStatement>()) {
75    return "return statement";
76  }
77  if (Is<SwitchStatement>()) {
78    return "switch statement";
79  }
80  if (Is<VariableDeclStatement>()) {
81    return "variable declaration";
82  }
83  return "statement";
84}
85
86}  // namespace ast
87}  // namespace tint
88