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_NODE_H_
|
|
|
|
#define SRC_AST_NODE_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2021-02-17 13:17:39 +00:00
|
|
|
#include "src/clone_context.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
namespace tint {
|
2021-01-21 16:20:40 +00:00
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class CloneContext;
|
2021-01-21 15:42:10 +00:00
|
|
|
namespace type {
|
|
|
|
class Type;
|
|
|
|
}
|
2021-01-29 10:55:40 +00:00
|
|
|
namespace semantic {
|
|
|
|
class Info;
|
|
|
|
}
|
2021-01-21 16:20:40 +00:00
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
namespace ast {
|
|
|
|
|
|
|
|
/// AST base class node
|
2021-02-17 13:17:39 +00:00
|
|
|
class Node : public Castable<Node, Cloneable> {
|
2020-03-02 20:47:43 +00:00
|
|
|
public:
|
2020-11-30 23:30:58 +00:00
|
|
|
~Node() override;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
/// @returns the node source data
|
|
|
|
const Source& source() const { return source_; }
|
|
|
|
|
|
|
|
/// Writes a representation of the node to the output stream
|
2021-01-29 10:55:40 +00:00
|
|
|
/// @param sem the semantic info for the program
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @param out the stream to write to
|
|
|
|
/// @param indent number of spaces to indent the node when writing
|
2021-01-29 10:55:40 +00:00
|
|
|
virtual void to_str(const semantic::Info& sem,
|
|
|
|
std::ostream& out,
|
|
|
|
size_t indent) const = 0;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2020-12-02 15:31:08 +00:00
|
|
|
/// Convenience wrapper around the to_str() method.
|
2021-01-29 10:55:40 +00:00
|
|
|
/// @param sem the semantic info for the program
|
2020-03-02 20:47:43 +00:00
|
|
|
/// @returns the node as a string
|
2021-01-29 10:55:40 +00:00
|
|
|
std::string str(const semantic::Info& sem) const;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Create a new node
|
2020-12-12 01:35:43 +00:00
|
|
|
/// @param source the input source for the node
|
2020-03-02 20:47:43 +00:00
|
|
|
explicit Node(const Source& source);
|
|
|
|
/// Move constructor
|
2020-11-30 23:30:58 +00:00
|
|
|
Node(Node&&);
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
/// Writes indent into stream
|
|
|
|
/// @param out the stream to write to
|
|
|
|
/// @param indent the number of spaces to write
|
|
|
|
void make_indent(std::ostream& out, size_t indent) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Node(const Node&) = delete;
|
|
|
|
|
2020-12-15 14:52:38 +00:00
|
|
|
Source const source_;
|
2020-03-02 20:47:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // SRC_AST_NODE_H_
|