summaryrefslogtreecommitdiff
path: root/source/slang/slang-ast-base.cpp
blob: d4904d2dec326188ed3b6ca1c95cab41a108e1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "slang-ast-base.h"
#include "slang-ast-builder.h"

namespace Slang
{
    void NodeBase::_initDebug(ASTNodeType inAstNodeType, ASTBuilder* inAstBuilder)
    {
#ifdef _DEBUG
        SLANG_UNUSED(inAstNodeType);
        static int32_t uidCounter = 0;
        static int32_t breakValue = 0;
        uidCounter++;
        _debugUID = uidCounter;
        if (inAstBuilder->getId() == -1)
            _debugUID = -_debugUID;
        if (breakValue != 0 && _debugUID == breakValue)
            SLANG_BREAKPOINT(0)
#else
        SLANG_UNUSED(inAstNodeType);
        SLANG_UNUSED(inAstBuilder);
#endif
    }
    DeclRefBase* Decl::getDefaultDeclRef()
    {
        if (auto astBuilder = getCurrentASTBuilder())
        {
            const Index currentEpoch = astBuilder->getEpoch();
            if (currentEpoch != m_defaultDeclRefEpoch || !m_defaultDeclRef)
            {
                m_defaultDeclRef = astBuilder->getOrCreate<DirectDeclRef>(this);
                m_defaultDeclRefEpoch = currentEpoch;
            }
        }
        return m_defaultDeclRef;
    }

    bool Decl::isChildOf(Decl* other) const
    {
        for (auto parent = parentDecl; parent; parent = parent->parentDecl)
            if (parent == other)
                return true;
        return false;
    }

}