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

Function ParseClassDefinition

NULLC/Parser.cpp:728–798  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

726}
727
728bool ParseClassDefinition(Lexeme** str)
729{
730 if(!ParseAlignment(str))
731 SetCurrentAlignment(0);
732
733 if(ParseLexem(str, lex_class))
734 {
735 if((*str)->type != lex_string)
736 ThrowError((*str)->pos, "ERROR: class name expected");
737 TypeInfo *proto = TypeBegin((*str)->pos, (*str)->pos+(*str)->length);
738 (*str)++;
739
740 if(ParseLexem(str, lex_less))
741 {
742 if(proto)
743 ThrowError((*str)->pos, "ERROR: type was forward declared as a non-generic type");
744 CodeInfo::typeInfo.back()->dependsOnGeneric = true;
745 TypeGeneric(unsigned(*str - CodeInfo::lexStart));
746 TypeInfo *newType = GetSelectedType();
747 AliasInfo *aliasList = NULL;
748 unsigned count = 0;
749 do
750 {
751 if((*str)->type != lex_string)
752 ThrowError((*str)->pos, count ? "ERROR: generic type alias required after ','" : "ERROR: generic type alias required after '<'");
753 if((*str)->length >= NULLC_MAX_VARIABLE_NAME_LENGTH)
754 ThrowError((*str)->pos, "ERROR: alias name length is limited to 2048 symbols");
755 if(ParseSelectType(str))
756 ThrowError((*str)->pos, "ERROR: there is already a type or an alias with the same name");
757
758 AliasInfo *info = TypeInfo::CreateAlias(InplaceStr((*str)->pos, (*str)->length), typeGeneric);
759 CodeInfo::classMap.insert(info->nameHash, info->type);
760 info->next = aliasList;
761 aliasList = info;
762
763 (*str)++;
764 count++;
765 }while(ParseLexem(str, lex_comma));
766 newType->childAlias = aliasList;
767 newType->genericInfo->aliasCount = count;
768 if(!ParseLexem(str, lex_greater))
769 ThrowError((*str)->pos, "ERROR: '>' expected after generic type alias list");
770 if(!ParseLexem(str, lex_ofigure))
771 ThrowError((*str)->pos, "ERROR: '{' not found after class name");
772 // Skip class body
773 unsigned braces = 1;
774 while(braces)
775 {
776 if((*str)->type == lex_none)
777 ThrowError((*str)->pos, "ERROR: unknown lexeme in class body");
778 if(ParseLexem(str, lex_ofigure))
779 braces++;
780 else if(ParseLexem(str, lex_cfigure))
781 braces--;
782 else
783 (*str)++;
784 }
785 TypeFinish();

Callers 1

ParseExpressionFunction · 0.85

Calls 13

ParseAlignmentFunction · 0.85
SetCurrentAlignmentFunction · 0.85
ParseLexemFunction · 0.85
ThrowErrorFunction · 0.85
TypeBeginFunction · 0.85
TypeGenericFunction · 0.85
GetSelectedTypeFunction · 0.85
ParseSelectTypeFunction · 0.85
InplaceStrClass · 0.85
TypeFinishFunction · 0.85
TypePrototypeFinishFunction · 0.85
ParseClassBodyFunction · 0.85

Tested by

no test coverage detected