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

Function HasConstructor

NULLC/Callbacks.cpp:2797–2852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2795}
2796
2797bool HasConstructor(TypeInfo* type, unsigned arguments, bool* callDefault)
2798{
2799 bestFuncList.clear();
2800
2801 if(type->refLevel || type->arrLevel || type->funcType)
2802 return false;
2803
2804 unsigned funcHash = type->nameHash;
2805 funcHash = StringHashContinue(funcHash, "::");
2806 funcHash = StringHashContinue(funcHash, FindConstructorName(type));
2807 SelectFunctionsForHash(funcHash, 0);
2808
2809 // For a generic type instance, check if base class has a constructor function
2810 unsigned funcBaseHash = 0;
2811 if(type->genericBase)
2812 {
2813 funcBaseHash = type->genericBase->nameHash;
2814 funcBaseHash = StringHashContinue(funcBaseHash, "::");
2815 funcBaseHash = StringHashContinue(funcBaseHash, FindConstructorName(type));
2816 SelectFunctionsForHash(funcBaseHash, 0);
2817 }
2818
2819 // remove functions with wrong argument count
2820 for(unsigned i = 0; i < bestFuncList.size(); i++)
2821 {
2822 FunctionInfo *curr = bestFuncList[i];
2823
2824 VariableInfo *param = curr->firstParam;
2825 for(unsigned int n = 0; n < arguments && param; n++)
2826 param = param->next;
2827
2828 if(curr->paramCount != arguments && !(param && param->defaultValue))
2829 {
2830 bestFuncList[i] = bestFuncList.back();
2831 bestFuncList.pop_back();
2832 i--;
2833 }
2834 }
2835
2836 if(!bestFuncList.size())
2837 {
2838 if(callDefault)
2839 *callDefault = true;
2840 funcHash = StringHashContinue(funcHash, "$");
2841 SelectFunctionsForHash(funcHash, 0);
2842 if(type->genericBase)
2843 {
2844 funcBaseHash = StringHashContinue(funcBaseHash, "$");
2845 SelectFunctionsForHash(funcBaseHash, 0);
2846 }
2847 }
2848
2849 unsigned minRating = ~0u;
2850 SelectBestFunction(bestFuncList.size(), arguments, minRating, type->genericBase ? type : NULL);
2851 return minRating != ~0u;
2852}
2853
2854bool defineCoroutine = false;

Callers 5

FunctionStartFunction · 0.85
AddFunctionCallNodeFunction · 0.85
TypeFinishFunction · 0.85
ParseAddVariableFunction · 0.85
ParseTerminalFunction · 0.85

Calls 7

StringHashContinueFunction · 0.85
FindConstructorNameFunction · 0.85
SelectFunctionsForHashFunction · 0.85
SelectBestFunctionFunction · 0.85
clearMethod · 0.45
sizeMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected