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_STRUCT_H_
|
|
|
|
#define SRC_AST_STRUCT_H_
|
|
|
|
|
2021-04-20 15:04:21 +00:00
|
|
|
#include <string>
|
2020-03-02 20:47:43 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2021-03-11 17:39:32 +00:00
|
|
|
#include "src/ast/decoration.h"
|
2021-04-30 19:58:49 +00:00
|
|
|
#include "src/ast/named_type.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
#include "src/ast/struct_member.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
|
|
|
|
/// A struct statement.
|
2021-04-30 19:58:49 +00:00
|
|
|
class Struct : public Castable<Struct, NamedType> {
|
2020-03-02 20:47:43 +00:00
|
|
|
public:
|
2020-10-08 18:33:25 +00:00
|
|
|
/// Create a new struct statement
|
2021-04-13 23:27:27 +00:00
|
|
|
/// @param program_id the identifier of the program that owns this node
|
2020-10-08 18:33:25 +00:00
|
|
|
/// @param source The input source for the import statement
|
2021-04-20 15:04:21 +00:00
|
|
|
/// @param name The name of the structure
|
2020-10-08 18:33:25 +00:00
|
|
|
/// @param members The struct members
|
|
|
|
/// @param decorations The struct decorations
|
2021-04-13 23:27:27 +00:00
|
|
|
Struct(ProgramID program_id,
|
|
|
|
const Source& source,
|
2021-04-20 15:04:21 +00:00
|
|
|
Symbol name,
|
2020-12-12 12:52:44 +00:00
|
|
|
StructMemberList members,
|
2021-03-11 17:39:32 +00:00
|
|
|
DecorationList decorations);
|
2020-03-02 20:47:43 +00:00
|
|
|
/// Move constructor
|
2020-04-09 18:52:06 +00:00
|
|
|
Struct(Struct&&);
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
~Struct() override;
|
|
|
|
|
2020-10-08 18:33:25 +00:00
|
|
|
/// @returns the struct decorations
|
2021-03-11 17:39:32 +00:00
|
|
|
const DecorationList& decorations() const { return decorations_; }
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
/// @returns the members
|
2020-04-06 19:37:37 +00:00
|
|
|
const StructMemberList& members() const { return members_; }
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-01-11 16:24:32 +00:00
|
|
|
/// Returns the struct member with the given symbol or nullptr if non exists.
|
|
|
|
/// @param symbol the symbol of the member
|
2020-08-25 21:22:37 +00:00
|
|
|
/// @returns the struct member or nullptr if not found
|
2021-01-11 16:24:32 +00:00
|
|
|
StructMember* get_member(const Symbol& symbol) const;
|
2020-08-25 21:22:37 +00:00
|
|
|
|
2020-10-08 18:33:25 +00:00
|
|
|
/// @returns true if the struct is block decorated
|
|
|
|
bool IsBlockDecorated() const;
|
|
|
|
|
2020-12-01 18:04:17 +00:00
|
|
|
/// Clones this node and all transitive child nodes using the `CloneContext`
|
|
|
|
/// `ctx`.
|
|
|
|
/// @param ctx the clone context
|
|
|
|
/// @return the newly cloned node
|
|
|
|
Struct* Clone(CloneContext* ctx) const override;
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
/// 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-04-16 19:07:51 +00:00
|
|
|
void to_str(const sem::Info& sem,
|
2021-01-29 10:55:40 +00:00
|
|
|
std::ostream& out,
|
|
|
|
size_t indent) const override;
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-04-20 15:04:21 +00:00
|
|
|
/// @returns the name for the type
|
|
|
|
std::string type_name() const override;
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
private:
|
|
|
|
Struct(const Struct&) = delete;
|
|
|
|
|
2020-12-15 14:52:38 +00:00
|
|
|
StructMemberList const members_;
|
2021-03-11 17:39:32 +00:00
|
|
|
DecorationList const decorations_;
|
2020-03-02 20:47:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // SRC_AST_STRUCT_H_
|