| 1179 | } |
| 1180 | |
| 1181 | VariableInfo* AddVariable(const char* pos, InplaceStr variableName, bool preserveNamespace) |
| 1182 | { |
| 1183 | CodeInfo::lastKnownStartPos = pos; |
| 1184 | |
| 1185 | InplaceStr varName = preserveNamespace ? GetNameInNamespace(variableName) : variableName; |
| 1186 | |
| 1187 | unsigned int hash = GetStringHash(varName.begin, varName.end); |
| 1188 | |
| 1189 | if(TypeInfo **info = CodeInfo::classMap.find(hash)) |
| 1190 | ThrowError(pos, "ERROR: name '%.*s' is already taken for a class", varName.end-varName.begin, varName.begin); |
| 1191 | |
| 1192 | // Check for variables with the same name in current scope |
| 1193 | if(VariableInfo ** info = varMap.find(hash)) |
| 1194 | if((*info)->blockDepth >= varInfoTop.size()) |
| 1195 | ThrowError(pos, "ERROR: name '%.*s' is already taken for a variable in current scope", varName.end-varName.begin, varName.begin); |
| 1196 | // Check for functions with the same name |
| 1197 | CheckCollisionWithFunction(pos, varName, hash, varInfoTop.size()); |
| 1198 | |
| 1199 | if((currType && currType->alignBytes != 0) || currAlign != TypeInfo::UNSPECIFIED_ALIGNMENT) |
| 1200 | { |
| 1201 | unsigned int offset = GetAlignmentOffset(pos, currAlign != TypeInfo::UNSPECIFIED_ALIGNMENT ? currAlign : currType->alignBytes); |
| 1202 | varTop += offset; |
| 1203 | } |
| 1204 | if(currType && currType->hasFinalizer) |
| 1205 | ThrowError(pos, "ERROR: cannot create '%s' that implements 'finalize' on stack", currType->GetFullTypeName()); |
| 1206 | if(currType && !currType->hasFinished && currType != newType) |
| 1207 | ThrowError(pos, "ERROR: type '%s' is not fully defined. You can use '%s ref' or '%s[]' at this point", currType->GetFullTypeName(), currType->GetFullTypeName(), currType->GetFullTypeName()); |
| 1208 | CodeInfo::varInfo.push_back(new VariableInfo(currDefinedFunc.size() > 0 ? currDefinedFunc.back() : NULL, varName, hash, varTop, currType, currDefinedFunc.size() == 0)); |
| 1209 | varDefined = true; |
| 1210 | CodeInfo::varInfo.back()->blockDepth = varInfoTop.size(); |
| 1211 | if(currType) |
| 1212 | varTop += currType->size; |
| 1213 | if(varTop > (1 << 24)) |
| 1214 | ThrowError(pos, "ERROR: variable size limit exceeded"); |
| 1215 | varMap.insert(hash, CodeInfo::varInfo.back()); |
| 1216 | return CodeInfo::varInfo.back(); |
| 1217 | } |
| 1218 | |
| 1219 | void AddVariableReserveNode(const char* pos) |
| 1220 | { |
no test coverage detected