| 83 | NamespaceInfo* currNamespace = NULL; |
| 84 | |
| 85 | void 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 | |
| 122 | void PopNamespace() |
| 123 | { |
no test coverage detected