Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions source/slang/slang-ast-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

#pragma once

#include "slang-ast-base.h.fiddle"
#include "slang-ast-forward-declarations.h"
#include "slang-ast-support-types.h"
#include "slang-capability.h"

#include "slang-ast-base.h.fiddle"

// This file defines the primary base classes for the hierarchy of
// AST nodes and related objects. For example, this is where the
// basic `Decl`, `Stmt`, `Expr`, `type`, etc. definitions come from.
Expand Down Expand Up @@ -37,10 +36,7 @@ class NodeBase

void _initDebug(ASTNodeType inAstNodeType, ASTBuilder* inAstBuilder);

SyntaxClass<NodeBase> getClass() const
{
return SyntaxClass<NodeBase>(astNodeType);
}
SyntaxClass<NodeBase> getClass() const { return SyntaxClass<NodeBase>(astNodeType); }

/// The type of the node. ASTNodeType(-1) is an invalid node type, and shouldn't appear on any
/// correctly constructed (through ASTBuilder) NodeBase derived class.
Expand All @@ -57,37 +53,25 @@ class NodeBase
template<typename T>
SLANG_FORCE_INLINE T* dynamicCast(NodeBase* node)
{
return (node &&
node->getClass().isSubClassOf<T>())
? static_cast<T*>(node)
: nullptr;
return (node && node->getClass().isSubClassOf<T>()) ? static_cast<T*>(node) : nullptr;
}

template<typename T>
SLANG_FORCE_INLINE const T* dynamicCast(const NodeBase* node)
{
return (node &&
node->getClass().isSubClassOf<T>())
? static_cast<const T*>(node)
: nullptr;
return (node && node->getClass().isSubClassOf<T>()) ? static_cast<const T*>(node) : nullptr;
}

template<typename T>
SLANG_FORCE_INLINE T* as(NodeBase* node)
{
return (node &&
node->getClass().isSubClassOf<T>())
? static_cast<T*>(node)
: nullptr;
return (node && node->getClass().isSubClassOf<T>()) ? static_cast<T*>(node) : nullptr;
}

template<typename T>
SLANG_FORCE_INLINE const T* as(const NodeBase* node)
{
return (node &&
node->getClass().isSubClassOf<T>())
? static_cast<const T*>(node)
: nullptr;
return (node && node->getClass().isSubClassOf<T>()) ? static_cast<const T*>(node) : nullptr;
}

// Because DeclRefBase is now a `Val`, we prevent casting it directly into other nodes
Expand Down Expand Up @@ -746,7 +730,9 @@ struct ProvenenceNodeWithLoc
// An intermediate type to represent either a single declaration, or a group of declarations
FIDDLE(abstract)
class DeclBase : public ModifiableSyntaxNode
{ FIDDLE(...) };
{
FIDDLE(...)
};

FIDDLE(abstract)
class Decl : public DeclBase
Expand Down
14 changes: 4 additions & 10 deletions source/slang/slang-ast-boilerplate.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
// slang-ast-boilerplate.cpp

#include "slang-ast-forward-declarations.h"
#include "slang-ast-all.h"
#include "slang-ast-builder.h"
#include "slang-ast-forward-declarations.h"

namespace Slang
{
template<typename T>
struct Helper
{
static void* create(ASTBuilder* builder)
{
return builder->createImpl<T>();
}
static void* create(ASTBuilder* builder) { return builder->createImpl<T>(); }

static void destruct(void* obj)
{
((T*)obj)->~T();
}
static void destruct(void* obj) { ((T*)obj)->~T(); }
};

#if 0 // FIDDLE TEMPLATE:
Expand Down Expand Up @@ -57,4 +51,4 @@ SyntaxClassBase::SyntaxClassBase(ASTNodeType tag)
_info = kAllSyntaxClasses[int(tag)];
}

}
} // namespace Slang
2 changes: 1 addition & 1 deletion source/slang/slang-ast-decl-ref.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// slang-ast-decl-ref.cpp

#include "slang-ast-builder.h"
#include "slang-ast-dispatch.h"
#include "slang-ast-forward-declarations.h"
#include "slang-check-impl.h"
#include "slang-ast-dispatch.h"

namespace Slang
{
Expand Down
1 change: 0 additions & 1 deletion source/slang/slang-ast-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once

#include "slang-ast-base.h"

#include "slang-ast-decl.h.fiddle"

FIDDLE()
Expand Down
10 changes: 2 additions & 8 deletions source/slang/slang-ast-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,11 @@ struct ASTDumpAccess

static void dump(NodeBase* base, ASTDumpContext& context)
{
ASTNodeDispatcher<NodeBase, void>::dispatch(base, [&](auto b)
{
dump_(b, context);
});
ASTNodeDispatcher<NodeBase, void>::dispatch(base, [&](auto b) { dump_(b, context); });
}
};

void ASTDumpContext::dumpObjectReference(
NodeBase* obj,
Index objIndex)
void ASTDumpContext::dumpObjectReference(NodeBase* obj, Index objIndex)
{
SLANG_UNUSED(obj);
ScopeWrite(this).getBuf() << obj->getClass().getName() << ":" << objIndex;
Expand Down Expand Up @@ -858,4 +853,3 @@ void ASTDumpContext::dumpObjectFull(NodeBase* node)
}

} // namespace Slang

1 change: 0 additions & 1 deletion source/slang/slang-ast-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#pragma once

#include "slang-ast-base.h"

#include "slang-ast-expr.h.fiddle"

FIDDLE()
Expand Down
10 changes: 5 additions & 5 deletions source/slang/slang-ast-forward-declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Slang
{

enum class ASTNodeType
{
enum class ASTNodeType
{
#if 0 // FIDDLE TEMPLATE:
%for _, T in ipairs(Slang.NodeBase.subclasses) do
$T,
Expand All @@ -14,8 +14,8 @@ namespace Slang
#define FIDDLE_GENERATED_OUTPUT_ID 0
#include "slang-ast-forward-declarations.h.fiddle"
#endif // FIDDLE END
CountOf
};
CountOf
};

#if 0 // FIDDLE TEMPLATE:
%for _, T in ipairs(Slang.NodeBase.subclasses) do
Expand All @@ -26,4 +26,4 @@ namespace Slang
#include "slang-ast-forward-declarations.h.fiddle"
#endif // FIDDLE END

}
} // namespace Slang
5 changes: 1 addition & 4 deletions source/slang/slang-ast-iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ struct ASTIterator
}
}

void visitDetachExpr(DetachExpr* expr)
{
iterator->maybeDispatchCallback(expr);
}
void visitDetachExpr(DetachExpr* expr) { iterator->maybeDispatchCallback(expr); }
};

struct ASTIteratorStmtVisitor : public StmtVisitor<ASTIteratorStmtVisitor>
Expand Down
Loading
Loading