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

Function ParseFunctionVariables

NULLC/Parser.cpp:944–1013  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

942}
943
944bool ParseFunctionVariables(Lexeme** str, unsigned nodeOffset)
945{
946 bool genericArg = false;
947 if(!ParseSelectType(str, true, true))
948 return true;
949
950 genericArg = GetSelectedType() ? GetSelectedType()->dependsOnGeneric : false;
951 if(genericArg)
952 FunctionGeneric(true);
953
954 unsigned argID = 0;
955 if(genericArg && nodeOffset)
956 {
957 TypeInfo *curr = GetSelectedType();
958 SelectTypeForGeneric(nodeOffset - 1 + argID);
959 if(curr->refLevel && !GetSelectedType()->refLevel)
960 SelectTypeByPointer(CodeInfo::GetReferenceType(GetSelectedType()));
961 }
962
963 if((*str)->type != lex_string)
964 ThrowError((*str)->pos, "ERROR: variable name not found after type in function variable list");
965
966 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
967 ThrowError((*str)->pos, "ERROR: parameter name length is limited to 2048 symbols");
968 FunctionParameter((*str)->pos, InplaceStr((*str)->pos, (*str)->length));
969 (*str)++;
970
971 if(ParseLexem(str, lex_set))
972 {
973 FunctionPrepareDefault();
974 if(!ParseTernaryExpr(str))
975 ThrowError((*str)->pos, "ERROR: default parameter value not found after '='");
976 FunctionParameterDefault((*str)->pos);
977 }
978
979 while(ParseLexem(str, lex_comma))
980 {
981 argID++;
982 bool lastGeneric = genericArg;
983 genericArg = false;
984 if(!ParseSelectType(str, true, true))
985 genericArg = lastGeneric; // if there is no type and no generic, then this parameter is as generic as the last one
986 genericArg |= GetSelectedType() ? GetSelectedType()->dependsOnGeneric : false;
987 if(genericArg)
988 FunctionGeneric(true);
989 if(genericArg && nodeOffset)
990 {
991 TypeInfo *curr = GetSelectedType();
992 SelectTypeForGeneric(nodeOffset - 1 + argID);
993 if(curr->refLevel && !GetSelectedType()->refLevel)
994 SelectTypeByPointer(CodeInfo::GetReferenceType(GetSelectedType()));
995 }
996
997 if((*str)->type != lex_string)
998 ThrowError((*str)->pos, "ERROR: variable name not found after type in function variable list");
999 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
1000 ThrowError((*str)->pos, "ERROR: parameter name length is limited to 2048 symbols");
1001 FunctionParameter((*str)->pos, InplaceStr((*str)->pos, (*str)->length));

Callers 2

ParseFunctionDefinitionFunction · 0.85

Calls 12

ParseSelectTypeFunction · 0.85
GetSelectedTypeFunction · 0.85
FunctionGenericFunction · 0.85
SelectTypeForGenericFunction · 0.85
SelectTypeByPointerFunction · 0.85
ThrowErrorFunction · 0.85
FunctionParameterFunction · 0.85
InplaceStrClass · 0.85
ParseLexemFunction · 0.85
FunctionPrepareDefaultFunction · 0.85
ParseTernaryExprFunction · 0.85
FunctionParameterDefaultFunction · 0.85

Tested by

no test coverage detected