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

Function ParseShortFunctionDefinition

NULLC/Parser.cpp:1161–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1159}
1160
1161bool ParseShortFunctionDefinition(Lexeme** str)
1162{
1163 if(!ParseLexem(str, lex_less))
1164 return true;
1165
1166 // Save argument starting position
1167 Lexeme *start = *str;
1168 unsigned arguments = 0;
1169 // parse argument count
1170 if((*str)->type != lex_greater)
1171 {
1172 ParseSelectType(str);
1173 if(!ParseLexem(str, lex_string))
1174 ThrowError((*str)->pos, "ERROR: function argument name not found after '<'");
1175 arguments++;
1176 while(ParseLexem(str, lex_comma))
1177 {
1178 ParseSelectType(str);
1179 if(!ParseLexem(str, lex_string))
1180 ThrowError((*str)->pos, "ERROR: function argument name not found after ','");
1181 arguments++;
1182 }
1183 }
1184 // Restore argument starting position
1185 *str = start;
1186 // Get function type
1187 TypeInfo *type = (TypeInfo*)GetCurrentArgumentType((*str)->pos, arguments);
1188
1189 static int unnamedFuncCount = 0;
1190 char *functionName = (char*)stringPool.Allocate(16);
1191 sprintf(functionName, "$funcs%d", unnamedFuncCount);
1192 unnamedFuncCount++;
1193
1194 NamespaceInfo *lastNS = GetCurrentNamespace();
1195 SetCurrentNamespace(NULL);
1196
1197 SelectTypeByPointer(type->funcType->retType);
1198 FunctionAdd((*str)->pos, functionName);
1199
1200 for(unsigned currArg = 0; currArg < arguments; currArg++)
1201 {
1202 if(currArg != 0)
1203 ParseLexem(str, lex_comma);
1204 bool imaginary = ParseSelectType(str);
1205 TypeInfo *selType = (TypeInfo*)GetSelectedType();
1206 SelectTypeByPointer(type->funcType->paramType[currArg]);
1207 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
1208 ThrowError((*str)->pos, "ERROR: parameter name length is limited to 2048 symbols");
1209 if(imaginary && type->funcType->paramType[currArg] == typeGeneric)
1210 {
1211 SelectTypeByPointer(selType);
1212 imaginary = false;
1213 }
1214 if(!imaginary || type->funcType->paramType[currArg] == selType)
1215 {
1216 if(GetSelectedType() == typeGeneric)
1217 ThrowError((*str)->pos, "ERROR: function allows any type for this argument so it must be specified explicitly");
1218 FunctionParameter((*str)->pos, InplaceStr((*str)->pos, (*str)->length));

Callers 1

ParseTerminalFunction · 0.85

Calls 15

ParseLexemFunction · 0.85
ParseSelectTypeFunction · 0.85
ThrowErrorFunction · 0.85
GetCurrentArgumentTypeFunction · 0.85
GetCurrentNamespaceFunction · 0.85
SetCurrentNamespaceFunction · 0.85
SelectTypeByPointerFunction · 0.85
FunctionAddFunction · 0.85
GetSelectedTypeFunction · 0.85
FunctionParameterFunction · 0.85
InplaceStrClass · 0.85
FunctionStartFunction · 0.85

Tested by

no test coverage detected