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

Function ParseTypePostExpressions

NULLC/Parser.cpp:278–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278void ParseTypePostExpressions(Lexeme** str, bool allowArray, bool notType, bool allowAutoReturnType, bool allowGenericType, TypeInfo* instanceType, bool* instanceFailure)
279{
280 if(instanceType)
281 assert(instanceFailure);
282
283 bool run = true;
284 while(run)
285 {
286 switch((*str)->type)
287 {
288 case lex_ref:
289 (*str)++;
290 if(notType)
291 ThrowError((*str)->pos, "ERROR: typeof expression result is not a type");
292 if(ParseLexem(str, lex_oparen) || (allowGenericType && ParseLexem(str, lex_generic)))
293 {
294 Lexeme *old = (*str) - 1;
295 // Prepare function type
296 TypeInfo *retType = (TypeInfo*)GetSelectedType();
297 if(!retType && !allowAutoReturnType)
298 ThrowError((*str)->pos, "ERROR: return type of a function type cannot be auto");
299 if(instanceType && (!instanceType->funcType || instanceType->funcType->retType != retType))
300 {
301 *instanceFailure = true;
302 return;
303 }
304 TypeInfo *preferredType = instanceType ? (instanceType->funcType->paramCount ? instanceType->funcType->paramType[0] : NULL) : NULL;
305 TypeHandler *first = NULL, *handle = NULL;
306 unsigned int count = 0;
307 if(ParseSelectType(str, true, allowGenericType, false, true, preferredType, instanceFailure))
308 {
309 do
310 {
311 if(instanceType && count >= instanceType->funcType->paramCount)
312 {
313 *instanceFailure = true;
314 return;
315 }
316 if(count)
317 {
318 preferredType = instanceType ? instanceType->funcType->paramType[count] : NULL;
319 ParseSelectType(str, true, allowGenericType, false, true, preferredType, instanceFailure);
320 handle->next = (TypeHandler*)stringPool.Allocate(sizeof(TypeHandler));
321 handle = handle->next;
322 }else{
323 first = handle = (TypeHandler*)stringPool.Allocate(sizeof(TypeHandler));
324 }
325 handle->varType = (TypeInfo*)GetSelectedType();
326 handle->next = NULL;
327 if(!handle->varType)
328 ThrowError((*str)->pos, "ERROR: parameter type of a function type cannot be auto");
329 bool resolvedToGeneric = handle->varType->dependsOnGeneric;
330 if(instanceType)
331 {
332 assert(!resolvedToGeneric);
333 if(instanceType->funcType->paramType[count] != handle->varType)
334 {
335 *instanceFailure = true;

Callers 2

GetCurrentArgumentTypeFunction · 0.85
ParseSelectTypeFunction · 0.85

Calls 10

assertFunction · 0.85
ThrowErrorFunction · 0.85
ParseLexemFunction · 0.85
GetSelectedTypeFunction · 0.85
ParseSelectTypeFunction · 0.85
SelectTypeByPointerFunction · 0.85
GetFunctionTypeFunction · 0.85
ConvertTypeToReferenceFunction · 0.85
ParseArrayDefinitionFunction · 0.85
AllocateMethod · 0.45

Tested by

no test coverage detected