MCPcopy Create free account
hub / github.com/WheretIB/nullc / PushNamespace

Function PushNamespace

NULLC/Callbacks.cpp:85–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83NamespaceInfo* currNamespace = NULL;
84
85void PushNamespace(InplaceStr space)
86{
87 if(currDefinedFunc.size())
88 ThrowError(space.begin, "ERROR: a namespace definition must appear either at file scope or immediately within another namespace definition");
89
90 // Construct a name hash in a form of "previousname.currentname"
91 unsigned hash;
92 if(namespaceStack.size() == 1)
93 {
94 hash = GetStringHash(space.begin, space.end);
95 }else{
96 hash = namespaceStack.back()->hash;
97 hash = StringHashContinue(hash, ".");
98 hash = StringHashContinue(hash, space.begin, space.end);
99 }
100
101 // Find collisions with known names
102 if(TypeInfo **info = CodeInfo::classMap.find(hash))
103 ThrowError(space.begin, "ERROR: name '%.*s' is already taken for a class", space.end - space.begin, space.begin);
104 CheckCollisionWithFunction(space.begin, space, hash, varInfoTop.size());
105
106 // Find if namespace is already created
107 unsigned i = 0;
108 for(; i < CodeInfo::namespaceInfo.size(); i++)
109 {
110 if(CodeInfo::namespaceInfo[i]->hash == hash)
111 break;
112 }
113 if(i != CodeInfo::namespaceInfo.size())
114 {
115 namespaceStack.push_back(CodeInfo::namespaceInfo[i]);
116 return;
117 }
118 CodeInfo::namespaceInfo.push_back(new NamespaceInfo(space, hash, namespaceStack.size() == 1 ? NULL : namespaceStack.back()));
119 namespaceStack.push_back(CodeInfo::namespaceInfo.back());
120}
121
122void PopNamespace()
123{

Callers 1

ParseExpressionFunction · 0.85

Calls 7

ThrowErrorFunction · 0.85
StringHashContinueFunction · 0.85
GetStringHashFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected