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

Function ParseTypeofExtended

NULLC/Parser.cpp:143–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141};
142
143bool ParseTypeofExtended(Lexeme** str, bool& notType)
144{
145 if(!ParseLexem(str, lex_point))
146 return false;
147
148 if(notType)
149 ThrowError((*str)->pos, "ERROR: typeof expression result is not a type");
150
151 // work around bug in msvs2008
152 Lexeme *curr = *str;
153 bool genericType = GetSelectedType() == typeGeneric;
154 // .argument .return .target
155 if(curr->type == lex_string && curr->length == 8 && memcmp(curr->pos, "argument", 8) == 0)
156 {
157 curr++;
158 if(!GetSelectedType()->funcType && !genericType)
159 ThrowError(curr->pos, "ERROR: 'argument' can only be applied to a function type, but we have '%s'", GetSelectedType()->GetFullTypeName());
160 if(!ParseLexem(&curr, lex_point) && curr->type != lex_obracket)
161 ThrowError(curr->pos, "ERROR: expected '.first'/'.last'/'[N]'/'.size' at this point");
162 unsigned paramCount = !genericType ? GetSelectedType()->funcType->paramCount : 0;
163 if(curr->type == lex_string && curr->length == 5 && memcmp(curr->pos, "first", 5) == 0)
164 {
165 curr++;
166 if(!genericType)
167 {
168 if(!paramCount)
169 ThrowError(curr->pos, "ERROR: this function type '%s' doesn't have arguments", GetSelectedType()->GetFullTypeName());
170 SelectTypeByPointer(GetSelectedType()->funcType->paramType[0]);
171 }
172 }else if(curr->type == lex_string && curr->length == 4 && memcmp(curr->pos, "last", 4) == 0){
173 curr++;
174 if(!genericType)
175 {
176 if(!paramCount)
177 ThrowError(curr->pos, "ERROR: this function type '%s' doesn't have arguments", GetSelectedType()->GetFullTypeName());
178 SelectTypeByPointer(GetSelectedType()->funcType->paramType[paramCount-1]);
179 }
180 }else if(ParseLexem(&curr, lex_obracket)){
181 if(curr->type != lex_number)
182 ThrowError(curr->pos, "ERROR: argument number expected after '['");
183 unsigned request = atoi(curr->pos);
184 if(request >= paramCount && !genericType)
185 ThrowError(curr->pos, "ERROR: this function type '%s' has only %d argument(s)", GetSelectedType()->GetFullTypeName(), paramCount);
186 curr++;
187 if(!ParseLexem(&curr, lex_cbracket))
188 ThrowError(curr->pos, "ERROR: expected ']'");
189 if(!genericType)
190 SelectTypeByPointer(GetSelectedType()->funcType->paramType[request]);
191 }else if(curr->type == lex_string && curr->length == 4 && memcmp(curr->pos, "size", 4) == 0){
192 curr++;
193 CodeInfo::nodeList.push_back(new NodeNumber(genericType ? 0 : (int)paramCount, typeInt));
194 notType = true;
195 }else{
196 ThrowError(curr->pos, "ERROR: expected 'first'/'last'/'size' at this point");
197 }
198 }else if(ParseLexem(&curr, lex_return)){
199 if(!genericType)
200 {

Callers 1

ParseSelectTypeFunction · 0.85

Calls 8

ParseLexemFunction · 0.85
ThrowErrorFunction · 0.85
GetSelectedTypeFunction · 0.85
SelectTypeByPointerFunction · 0.85
assertFunction · 0.85
GetFullTypeNameMethod · 0.80
GetStringHashFunction · 0.70
push_backMethod · 0.45

Tested by

no test coverage detected