tint: Standardize the way we forward-declare

Style guide has been updated to describe the style in use.

Change-Id: I3fc08e3440566106582695f4dc149fa67d8b8dc8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86303
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-04-11 14:37:21 +00:00 committed by Dawn LUCI CQ
parent fd64b10b0d
commit a7230f06ff
38 changed files with 139 additions and 122 deletions

View File

@ -27,6 +27,24 @@
in WGSL or another shader language processed by Tint. If the concept you are in WGSL or another shader language processed by Tint. If the concept you are
trying to name is about distinguishing between alternatives, use `kind` instead. trying to name is about distinguishing between alternatives, use `kind` instead.
* Forward declarations:
* Use forward declarations where possible, instead of using `#include`'s.
* Place forward declarations in their own **un-nested** namespace declarations. \
Example: \
to forward-declare `struct X` in namespace `A` and `struct Y`
in namespace `A::B`, you'd write:
```c++
// Forward declarations
namespace A {
struct X;
} // namespace A
namespace A::B {
struct Y;
} // namespace A::B
// rest of the header code is declared below ...
```
## Compiler support ## Compiler support
Tint requires C++17. Tint requires C++17.

View File

@ -20,10 +20,12 @@
#include "src/tint/ast/attribute.h" #include "src/tint/ast/attribute.h"
#include "src/tint/ast/type.h" #include "src/tint/ast/type.h"
// Forward declarations
namespace tint::ast { namespace tint::ast {
// Forward declarations.
class Expression; class Expression;
} // namespace tint::ast
namespace tint::ast {
/// An array type. If size is zero then it is a runtime array. /// An array type. If size is zero then it is a runtime array.
class Array final : public Castable<Array, Type> { class Array final : public Castable<Array, Type> {

View File

@ -17,10 +17,12 @@
#include "src/tint/ast/expression.h" #include "src/tint/ast/expression.h"
// Forward declarations
namespace tint::ast { namespace tint::ast {
// Forward declaration
class Type; class Type;
} // namespace tint::ast
namespace tint::ast {
/// A bitcast expression /// A bitcast expression
class BitcastExpression final : public Castable<BitcastExpression, Expression> { class BitcastExpression final : public Castable<BitcastExpression, Expression> {

View File

@ -17,11 +17,13 @@
#include "src/tint/ast/expression.h" #include "src/tint/ast/expression.h"
// Forward declarations
namespace tint::ast { namespace tint::ast {
// Forward declarations.
class Type; class Type;
class IdentifierExpression; class IdentifierExpression;
} // namespace tint::ast
namespace tint::ast {
/// A call expression - represents either a: /// A call expression - represents either a:
/// * sem::Function /// * sem::Function

View File

@ -22,14 +22,13 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
namespace sem { } // namespace tint
namespace tint::sem {
class Type; class Type;
class Info; class Info;
} } // namespace tint::sem
} // namespace tint
namespace tint { namespace tint::ast {
namespace ast {
/// AST base class node /// AST base class node
class Node : public Castable<Node, Cloneable> { class Node : public Castable<Node, Cloneable> {
@ -54,7 +53,9 @@ class Node : public Castable<Node, Cloneable> {
Node(const Node&) = delete; Node(const Node&) = delete;
}; };
} // namespace ast } // namespace tint::ast
namespace tint {
/// @param node a pointer to an AST node /// @param node a pointer to an AST node
/// @returns the ProgramID of the given AST node. /// @returns the ProgramID of the given AST node.

View File

@ -20,10 +20,12 @@
#include "src/tint/ast/attribute.h" #include "src/tint/ast/attribute.h"
// Forward declarations
namespace tint::ast { namespace tint::ast {
// Forward declaration
class Type; class Type;
} // namespace tint::ast
namespace tint::ast {
/// A struct member statement. /// A struct member statement.
class StructMember final : public Castable<StructMember, Node> { class StructMember final : public Castable<StructMember, Node> {

View File

@ -23,13 +23,15 @@
#include "src/tint/ast/expression.h" #include "src/tint/ast/expression.h"
#include "src/tint/ast/storage_class.h" #include "src/tint/ast/storage_class.h"
namespace tint::ast {
// Forward declarations // Forward declarations
namespace tint::ast {
class BindingAttribute; class BindingAttribute;
class GroupAttribute; class GroupAttribute;
class LocationAttribute; class LocationAttribute;
class Type; class Type;
} // namespace tint::ast
namespace tint::ast {
/// VariableBindingPoint holds a group and binding attribute. /// VariableBindingPoint holds a group and binding attribute.
struct VariableBindingPoint { struct VariableBindingPoint {

View File

@ -20,10 +20,12 @@
#include "src/tint/ast/attribute.h" #include "src/tint/ast/attribute.h"
// Forward declarations
namespace tint::ast { namespace tint::ast {
// Forward declaration
class Expression; class Expression;
} // namespace tint::ast
namespace tint::ast {
/// A workgroup attribute /// A workgroup attribute
class WorkgroupAttribute final class WorkgroupAttribute final

View File

@ -21,10 +21,12 @@
#include "src/tint/sem/builtin.h" #include "src/tint/sem/builtin.h"
namespace tint {
// Forward declarations // Forward declarations
namespace tint {
class ProgramBuilder; class ProgramBuilder;
} // namespace tint
namespace tint {
/// BuiltinTable is a lookup table of all the WGSL builtin functions /// BuiltinTable is a lookup table of all the WGSL builtin functions
class BuiltinTable { class BuiltinTable {

View File

@ -43,20 +43,21 @@
TINT_CASTABLE_PUSH_DISABLE_WARNINGS(); TINT_CASTABLE_PUSH_DISABLE_WARNINGS();
// Forward declarations
namespace tint { namespace tint {
// Forward declaration
class CastableBase; class CastableBase;
/// Ignore is used as a special type used for skipping over types for trait /// Ignore is used as a special type used for skipping over types for trait
/// helper functions. /// helper functions.
class Ignore {}; class Ignore {};
} // namespace tint
namespace detail { namespace tint::detail {
template <typename T> template <typename T>
struct TypeInfoOf; struct TypeInfoOf;
} // namespace tint::detail
} // namespace detail namespace tint {
/// True if all template types that are not Ignore derive from CastableBase /// True if all template types that are not Ignore derive from CastableBase
template <typename... TYPES> template <typename... TYPES>

View File

@ -29,6 +29,11 @@
#include "src/tint/traits.h" #include "src/tint/traits.h"
// Forward declarations // Forward declarations
namespace tint {
class CloneContext;
class Program;
class ProgramBuilder;
} // namespace tint
namespace tint::ast { namespace tint::ast {
class FunctionList; class FunctionList;
class Node; class Node;
@ -36,11 +41,6 @@ class Node;
namespace tint { namespace tint {
// Forward Declarations
class CloneContext;
class Program;
class ProgramBuilder;
ProgramID ProgramIDOf(const Program*); ProgramID ProgramIDOf(const Program*);
ProgramID ProgramIDOf(const ProgramBuilder*); ProgramID ProgramIDOf(const ProgramBuilder*);

View File

@ -25,15 +25,15 @@
#include "src/tint/symbol_table.h" #include "src/tint/symbol_table.h"
// Forward Declarations // Forward Declarations
namespace tint {
class CloneContext;
} // namespace tint
namespace tint::ast { namespace tint::ast {
class Module; class Module;
} // namespace tint::ast } // namespace tint::ast
namespace tint { namespace tint {
// Forward declarations
class CloneContext;
/// Program holds the AST, Type information and SymbolTable for a tint program. /// Program holds the AST, Type information and SymbolTable for a tint program.
class Program { class Program {
public: public:

View File

@ -99,12 +99,14 @@
#endif #endif
// Forward declarations // Forward declarations
namespace tint {
class CloneContext;
} // namespace tint
namespace tint::ast { namespace tint::ast {
class VariableDeclStatement; class VariableDeclStatement;
} // namespace tint::ast } // namespace tint::ast
namespace tint { namespace tint {
class CloneContext;
/// ProgramBuilder is a mutable builder for a Program. /// ProgramBuilder is a mutable builder for a Program.
/// To construct a Program, populate the builder and then `std::move` it to a /// To construct a Program, populate the builder and then `std::move` it to a

View File

@ -27,13 +27,13 @@
#include "src/tint/castable.h" #include "src/tint/castable.h"
#include "src/tint/utils/block_allocator.h" #include "src/tint/utils/block_allocator.h"
// Forward Declarations // Forward declarations
namespace tint { namespace tint {
class ProgramBuilder; class ProgramBuilder;
namespace ast {
class Type;
}
} // namespace tint } // namespace tint
namespace tint::ast {
class Type;
} // namespace tint::ast
namespace tint::reader::spirv { namespace tint::reader::spirv {

View File

@ -36,8 +36,7 @@
#include "src/tint/utils/unique_vector.h" #include "src/tint/utils/unique_vector.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class IndexAccessorExpression; class IndexAccessorExpression;
class BinaryExpression; class BinaryExpression;
class BitcastExpression; class BitcastExpression;
@ -53,8 +52,8 @@ class ReturnStatement;
class SwitchStatement; class SwitchStatement;
class UnaryOpExpression; class UnaryOpExpression;
class Variable; class Variable;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class Array; class Array;
class Atomic; class Atomic;
class BlockStatement; class BlockStatement;
@ -67,8 +66,7 @@ class LoopStatement;
class Statement; class Statement;
class SwitchStatement; class SwitchStatement;
class TypeConstructor; class TypeConstructor;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::resolver { namespace tint::resolver {

View File

@ -25,7 +25,7 @@
// Forward declarations // Forward declarations
namespace tint::sem { namespace tint::sem {
class Type; class Type;
} } // namespace tint::sem
namespace tint::sem { namespace tint::sem {

View File

@ -17,15 +17,13 @@
#include "src/tint/sem/statement.h" #include "src/tint/sem/statement.h"
// Forward Declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class ForLoopStatement; class ForLoopStatement;
} } // namespace tint::ast
namespace sem { namespace tint::sem {
class Expression; class Expression;
} } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -24,18 +24,16 @@
#include "src/tint/utils/unique_vector.h" #include "src/tint/utils/unique_vector.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class BuiltinAttribute; class BuiltinAttribute;
class Function; class Function;
class LocationAttribute; class LocationAttribute;
class ReturnStatement; class ReturnStatement;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class Builtin; class Builtin;
class Variable; class Variable;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -18,15 +18,13 @@
#include "src/tint/sem/statement.h" #include "src/tint/sem/statement.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class IfStatement; class IfStatement;
class ElseStatement; class ElseStatement;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class Expression; class Expression;
} } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -25,7 +25,7 @@
// Forward declarations // Forward declarations
namespace tint::sem { namespace tint::sem {
class Module; class Module;
} } // namespace tint::sem
namespace tint::sem { namespace tint::sem {

View File

@ -20,7 +20,7 @@
// Forward declarations // Forward declarations
namespace tint::ast { namespace tint::ast {
class LoopStatement; class LoopStatement;
} } // namespace tint::ast
namespace tint::sem { namespace tint::sem {

View File

@ -19,10 +19,10 @@
#include "src/tint/sem/type.h" #include "src/tint/sem/type.h"
// Forward declaration // Forward declarations
namespace tint::sem { namespace tint::sem {
class Vector; class Vector;
} } // namespace tint::sem
namespace tint::sem { namespace tint::sem {

View File

@ -19,16 +19,14 @@
#include "src/tint/sem/expression.h" #include "src/tint/sem/expression.h"
/// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class MemberAccessorExpression; class MemberAccessorExpression;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class Struct; class Struct;
class StructMember; class StructMember;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -19,17 +19,15 @@
#include "src/tint/sem/node.h" #include "src/tint/sem/node.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class Function; class Function;
class Statement; class Statement;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class BlockStatement; class BlockStatement;
class CompoundStatement; class CompoundStatement;
class Function; class Function;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {
namespace detail { namespace detail {

View File

@ -21,10 +21,10 @@
#include "src/tint/ast/storage_texture.h" #include "src/tint/ast/storage_texture.h"
#include "src/tint/sem/texture_type.h" #include "src/tint/sem/texture_type.h"
// Forward Declarations // Forward declarations
namespace tint::sem { namespace tint::sem {
class Manager; class Manager;
} } // namespace tint::sem
namespace tint::sem { namespace tint::sem {

View File

@ -28,15 +28,13 @@
#include "src/tint/symbol.h" #include "src/tint/symbol.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class StructMember; class StructMember;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class StructMember; class StructMember;
class Type; class Type;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -18,8 +18,7 @@
#include <type_traits> #include <type_traits>
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class Array; class Array;
class CallExpression; class CallExpression;
class Expression; class Expression;
@ -35,8 +34,8 @@ class StructMember;
class Type; class Type;
class TypeDecl; class TypeDecl;
class Variable; class Variable;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class Array; class Array;
class Call; class Call;
class Expression; class Expression;
@ -51,8 +50,7 @@ class Struct;
class StructMember; class StructMember;
class Type; class Type;
class Variable; class Variable;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -25,17 +25,15 @@
#include "src/tint/sem/parameter_usage.h" #include "src/tint/sem/parameter_usage.h"
// Forward declarations // Forward declarations
namespace tint { namespace tint::ast {
namespace ast {
class IdentifierExpression; class IdentifierExpression;
class Variable; class Variable;
} // namespace ast } // namespace tint::ast
namespace sem { namespace tint::sem {
class CallTarget; class CallTarget;
class Type; class Type;
class VariableUser; class VariableUser;
} // namespace sem } // namespace tint::sem
} // namespace tint
namespace tint::sem { namespace tint::sem {

View File

@ -24,7 +24,7 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
} } // namespace tint
namespace tint::transform { namespace tint::transform {

View File

@ -23,7 +23,7 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
} } // namespace tint
namespace tint::transform { namespace tint::transform {

View File

@ -23,7 +23,7 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
} } // namespace tint
namespace tint::transform { namespace tint::transform {

View File

@ -22,7 +22,7 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
} } // namespace tint
namespace tint::transform { namespace tint::transform {

View File

@ -21,7 +21,7 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class CloneContext; class CloneContext;
} } // namespace tint
namespace tint::transform { namespace tint::transform {

View File

@ -31,10 +31,10 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class Program; class Program;
namespace writer::glsl {
class GeneratorImpl;
} // namespace writer::glsl
} // namespace tint } // namespace tint
namespace tint::writer::glsl {
class GeneratorImpl;
} // namespace tint::writer::glsl
namespace tint::writer::glsl { namespace tint::writer::glsl {

View File

@ -29,10 +29,10 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class Program; class Program;
namespace writer::hlsl {
class GeneratorImpl;
} // namespace writer::hlsl
} // namespace tint } // namespace tint
namespace tint::writer::hlsl {
class GeneratorImpl;
} // namespace tint::writer::hlsl
namespace tint::writer::hlsl { namespace tint::writer::hlsl {

View File

@ -27,10 +27,10 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class Program; class Program;
namespace writer::msl {
class GeneratorImpl;
} // namespace writer::msl
} // namespace tint } // namespace tint
namespace tint::writer::msl {
class GeneratorImpl;
} // namespace tint::writer::msl
namespace tint::writer::msl { namespace tint::writer::msl {

View File

@ -24,11 +24,11 @@
// Forward declarations // Forward declarations
namespace tint { namespace tint {
class Program; class Program;
namespace writer::spirv { }
namespace tint::writer::spirv {
class Builder; class Builder;
class BinaryWriter; class BinaryWriter;
} // namespace writer::spirv } // namespace tint::writer::spirv
} // namespace tint
namespace tint::writer::spirv { namespace tint::writer::spirv {

View File

@ -20,12 +20,12 @@
#include "src/tint/writer/text.h" #include "src/tint/writer/text.h"
namespace tint {
// Forward declarations // Forward declarations
namespace tint {
class Program; class Program;
} // namespace tint
namespace writer::wgsl { namespace tint::writer::wgsl {
class GeneratorImpl; class GeneratorImpl;
@ -61,7 +61,6 @@ struct Result {
/// @returns the resulting WGSL and supplementary information /// @returns the resulting WGSL and supplementary information
Result Generate(const Program* program, const Options& options); Result Generate(const Program* program, const Options& options);
} // namespace writer::wgsl } // namespace tint::writer::wgsl
} // namespace tint
#endif // SRC_TINT_WRITER_WGSL_GENERATOR_H_ #endif // SRC_TINT_WRITER_WGSL_GENERATOR_H_