| 2858 | } |
| 2859 | |
| 2860 | void FunctionAdd(const char* pos, const char* funcName, bool isOperator) |
| 2861 | { |
| 2862 | static unsigned int hashFinalizer = GetStringHash("finalize"); |
| 2863 | |
| 2864 | bool functionLocal = false; |
| 2865 | if(newType ? varInfoTop.size() > (newType->definitionDepth + 1) : varInfoTop.size() > 1) |
| 2866 | functionLocal = true; |
| 2867 | |
| 2868 | funcName = (isOperator || (newType && !functionLocal)) ? funcName : GetNameInNamespace(InplaceStr(funcName)).begin; |
| 2869 | |
| 2870 | unsigned int funcNameHash = GetStringHash(funcName), origHash = funcNameHash; |
| 2871 | for(unsigned int i = varInfoTop.back().activeVarCnt; i < CodeInfo::varInfo.size(); i++) |
| 2872 | { |
| 2873 | if(CodeInfo::varInfo[i]->nameHash == funcNameHash) |
| 2874 | ThrowError(pos, "ERROR: name '%s' is already taken for a variable in current scope", funcName); |
| 2875 | } |
| 2876 | |
| 2877 | char *funcNameCopy = (char*)funcName; |
| 2878 | if(newType && !functionLocal) |
| 2879 | { |
| 2880 | funcNameCopy = GetClassFunctionName(newType, funcName); |
| 2881 | funcNameHash = GetStringHash(funcNameCopy); |
| 2882 | } |
| 2883 | |
| 2884 | CodeInfo::funcInfo.push_back(new FunctionInfo(funcNameCopy, funcNameHash, origHash)); |
| 2885 | FunctionInfo* lastFunc = CodeInfo::funcInfo.back(); |
| 2886 | lastFunc->parentFunc = currDefinedFunc.size() > 0 ? currDefinedFunc.back() : NULL; |
| 2887 | |
| 2888 | static unsigned int hashNewS = GetStringHash("__newA"); |
| 2889 | static unsigned int hashNewA = GetStringHash("__newS"); |
| 2890 | if(funcNameHash == hashNewS || funcNameHash == hashNewA) |
| 2891 | { |
| 2892 | if(funcMap.first(funcNameHash)) |
| 2893 | ThrowError(pos, "ERROR: function '%s' is reserved", funcName); |
| 2894 | lastFunc->visible = false; |
| 2895 | } |
| 2896 | |
| 2897 | if(!isOperator) |
| 2898 | lastFunc->parentNamespace = namespaceStack.size() > 1 ? namespaceStack.back() : NULL; |
| 2899 | |
| 2900 | AddFunctionToSortedList(lastFunc); |
| 2901 | |
| 2902 | lastFunc->indexInArr = CodeInfo::funcInfo.size() - 1; |
| 2903 | lastFunc->vTopSize = (unsigned int)varInfoTop.size(); |
| 2904 | lastFunc->retType = currType; |
| 2905 | currDefinedFunc.push_back(lastFunc); |
| 2906 | if(newType && !functionLocal) |
| 2907 | { |
| 2908 | if(origHash == hashFinalizer) |
| 2909 | newType->hasFinalizer = true; |
| 2910 | if(newType->nameHash == origHash) |
| 2911 | lastFunc->typeConstructor = true; |
| 2912 | lastFunc->type = FunctionInfo::THISCALL; |
| 2913 | lastFunc->parentClass = newType; |
| 2914 | if(newType->genericInfo) |
| 2915 | FunctionGeneric(true); |
| 2916 | if(newType->genericBase) |
| 2917 | lastFunc->genericBase = newType->genericBase->genericInfo; |
no test coverage detected