• Home
  • Raw
  • Download

Lines Matching refs:state

188   explicit ComplexityGuard(State *state) : state_(state) {  in ComplexityGuard()  argument
189 ++state->recursion_depth; in ComplexityGuard()
190 ++state->steps; in ComplexityGuard()
255 static void InitState(State *state, const char *mangled, char *out, in InitState() argument
257 state->mangled_begin = mangled; in InitState()
258 state->out = out; in InitState()
259 state->out_end_idx = out_size; in InitState()
260 state->recursion_depth = 0; in InitState()
261 state->steps = 0; in InitState()
263 state->parse_state.mangled_idx = 0; in InitState()
264 state->parse_state.out_cur_idx = 0; in InitState()
265 state->parse_state.prev_name_idx = 0; in InitState()
266 state->parse_state.prev_name_length = -1; in InitState()
267 state->parse_state.nest_level = -1; in InitState()
268 state->parse_state.append = true; in InitState()
271 static inline const char *RemainingInput(State *state) { in RemainingInput() argument
272 return &state->mangled_begin[state->parse_state.mangled_idx]; in RemainingInput()
278 static bool ParseOneCharToken(State *state, const char one_char_token) { in ParseOneCharToken() argument
279 ComplexityGuard guard(state); in ParseOneCharToken()
281 if (RemainingInput(state)[0] == one_char_token) { in ParseOneCharToken() local
282 ++state->parse_state.mangled_idx; in ParseOneCharToken()
291 static bool ParseTwoCharToken(State *state, const char *two_char_token) { in ParseTwoCharToken() argument
292 ComplexityGuard guard(state); in ParseTwoCharToken()
294 if (RemainingInput(state)[0] == two_char_token[0] && in ParseTwoCharToken()
295 RemainingInput(state)[1] == two_char_token[1]) { in ParseTwoCharToken()
296 state->parse_state.mangled_idx += 2; in ParseTwoCharToken()
304 static bool ParseCharClass(State *state, const char *char_class) { in ParseCharClass() argument
305 ComplexityGuard guard(state); in ParseCharClass()
307 if (RemainingInput(state)[0] == '\0') { in ParseCharClass() local
312 if (RemainingInput(state)[0] == *p) { in ParseCharClass()
313 ++state->parse_state.mangled_idx; in ParseCharClass()
320 static bool ParseDigit(State *state, int *digit) { in ParseDigit() argument
321 char c = RemainingInput(state)[0]; in ParseDigit()
322 if (ParseCharClass(state, "0123456789")) { in ParseDigit()
336 static bool OneOrMore(ParseFunc parse_func, State *state) { in OneOrMore() argument
337 if (parse_func(state)) { in OneOrMore()
338 while (parse_func(state)) { in OneOrMore()
349 static bool ZeroOrMore(ParseFunc parse_func, State *state) { in ZeroOrMore() argument
350 while (parse_func(state)) { in ZeroOrMore()
358 static void Append(State *state, const char *const str, const int length) { in Append() argument
360 if (state->parse_state.out_cur_idx + 1 < in Append()
361 state->out_end_idx) { // +1 for '\0' in Append()
362 state->out[state->parse_state.out_cur_idx++] = str[i]; in Append()
365 state->parse_state.out_cur_idx = state->out_end_idx + 1; in Append()
369 if (state->parse_state.out_cur_idx < state->out_end_idx) { in Append()
370 state->out[state->parse_state.out_cur_idx] = in Append()
410 static bool EndsWith(State *state, const char chr) { in EndsWith() argument
411 return state->parse_state.out_cur_idx > 0 && in EndsWith()
412 chr == state->out[state->parse_state.out_cur_idx - 1]; in EndsWith()
416 static void MaybeAppendWithLength(State *state, const char *const str, in MaybeAppendWithLength() argument
418 if (state->parse_state.append && length > 0) { in MaybeAppendWithLength()
421 if (str[0] == '<' && EndsWith(state, '<')) { in MaybeAppendWithLength()
422 Append(state, " ", 1); in MaybeAppendWithLength()
426 state->parse_state.prev_name_idx = state->parse_state.out_cur_idx; in MaybeAppendWithLength()
427 state->parse_state.prev_name_length = length; in MaybeAppendWithLength()
429 Append(state, str, length); in MaybeAppendWithLength()
434 static bool MaybeAppendDecimal(State *state, unsigned int val) { in MaybeAppendDecimal() argument
441 if (state->parse_state.append) { in MaybeAppendDecimal()
451 Append(state, p, kMaxLength - (p - buf)); in MaybeAppendDecimal()
459 static bool MaybeAppend(State *state, const char *const str) { in MaybeAppend() argument
460 if (state->parse_state.append) { in MaybeAppend()
462 MaybeAppendWithLength(state, str, length); in MaybeAppend()
468 static bool EnterNestedName(State *state) { in EnterNestedName() argument
469 state->parse_state.nest_level = 0; in EnterNestedName()
474 static bool LeaveNestedName(State *state, int16_t prev_value) { in LeaveNestedName() argument
475 state->parse_state.nest_level = prev_value; in LeaveNestedName()
480 static bool DisableAppend(State *state) { in DisableAppend() argument
481 state->parse_state.append = false; in DisableAppend()
486 static bool RestoreAppend(State *state, bool prev_value) { in RestoreAppend() argument
487 state->parse_state.append = prev_value; in RestoreAppend()
492 static void MaybeIncreaseNestLevel(State *state) { in MaybeIncreaseNestLevel() argument
493 if (state->parse_state.nest_level > -1) { in MaybeIncreaseNestLevel()
494 ++state->parse_state.nest_level; in MaybeIncreaseNestLevel()
499 static void MaybeAppendSeparator(State *state) { in MaybeAppendSeparator() argument
500 if (state->parse_state.nest_level >= 1) { in MaybeAppendSeparator()
501 MaybeAppend(state, "::"); in MaybeAppendSeparator()
506 static void MaybeCancelLastSeparator(State *state) { in MaybeCancelLastSeparator() argument
507 if (state->parse_state.nest_level >= 1 && state->parse_state.append && in MaybeCancelLastSeparator()
508 state->parse_state.out_cur_idx >= 2) { in MaybeCancelLastSeparator()
509 state->parse_state.out_cur_idx -= 2; in MaybeCancelLastSeparator()
510 state->out[state->parse_state.out_cur_idx] = '\0'; in MaybeCancelLastSeparator()
516 static bool IdentifierIsAnonymousNamespace(State *state, int length) { in IdentifierIsAnonymousNamespace() argument
520 StrPrefix(RemainingInput(state), anon_prefix)); in IdentifierIsAnonymousNamespace()
524 static bool ParseMangledName(State *state);
525 static bool ParseEncoding(State *state);
526 static bool ParseName(State *state);
527 static bool ParseUnscopedName(State *state);
528 static bool ParseNestedName(State *state);
529 static bool ParsePrefix(State *state);
530 static bool ParseUnqualifiedName(State *state);
531 static bool ParseSourceName(State *state);
532 static bool ParseLocalSourceName(State *state);
533 static bool ParseUnnamedTypeName(State *state);
534 static bool ParseNumber(State *state, int *number_out);
535 static bool ParseFloatNumber(State *state);
536 static bool ParseSeqId(State *state);
537 static bool ParseIdentifier(State *state, int length);
538 static bool ParseOperatorName(State *state, int *arity);
539 static bool ParseSpecialName(State *state);
540 static bool ParseCallOffset(State *state);
541 static bool ParseNVOffset(State *state);
542 static bool ParseVOffset(State *state);
543 static bool ParseCtorDtorName(State *state);
544 static bool ParseDecltype(State *state);
545 static bool ParseType(State *state);
546 static bool ParseCVQualifiers(State *state);
547 static bool ParseBuiltinType(State *state);
548 static bool ParseFunctionType(State *state);
549 static bool ParseBareFunctionType(State *state);
550 static bool ParseClassEnumType(State *state);
551 static bool ParseArrayType(State *state);
552 static bool ParsePointerToMemberType(State *state);
553 static bool ParseTemplateParam(State *state);
554 static bool ParseTemplateTemplateParam(State *state);
555 static bool ParseTemplateArgs(State *state);
556 static bool ParseTemplateArg(State *state);
557 static bool ParseBaseUnresolvedName(State *state);
558 static bool ParseUnresolvedName(State *state);
559 static bool ParseExpression(State *state);
560 static bool ParseExprPrimary(State *state);
561 static bool ParseExprCastValue(State *state);
562 static bool ParseLocalName(State *state);
563 static bool ParseLocalNameSuffix(State *state);
564 static bool ParseDiscriminator(State *state);
565 static bool ParseSubstitution(State *state, bool accept_std);
599 static bool ParseMangledName(State *state) { in ParseMangledName() argument
600 ComplexityGuard guard(state); in ParseMangledName()
602 return ParseTwoCharToken(state, "_Z") && ParseEncoding(state); in ParseMangledName()
608 static bool ParseEncoding(State *state) { in ParseEncoding() argument
609 ComplexityGuard guard(state); in ParseEncoding()
616 if (ParseName(state) && Optional(ParseBareFunctionType(state))) { in ParseEncoding()
620 if (ParseSpecialName(state)) { in ParseEncoding()
630 static bool ParseName(State *state) { in ParseName() argument
631 ComplexityGuard guard(state); in ParseName()
633 if (ParseNestedName(state) || ParseLocalName(state)) { in ParseName()
645 ParseState copy = state->parse_state; in ParseName()
647 if (ParseSubstitution(state, /*accept_std=*/false) && in ParseName()
648 ParseTemplateArgs(state)) { in ParseName()
651 state->parse_state = copy; in ParseName()
655 return ParseUnscopedName(state) && Optional(ParseTemplateArgs(state)); in ParseName()
660 static bool ParseUnscopedName(State *state) { in ParseUnscopedName() argument
661 ComplexityGuard guard(state); in ParseUnscopedName()
663 if (ParseUnqualifiedName(state)) { in ParseUnscopedName()
667 ParseState copy = state->parse_state; in ParseUnscopedName()
668 if (ParseTwoCharToken(state, "St") && MaybeAppend(state, "std::") && in ParseUnscopedName()
669 ParseUnqualifiedName(state)) { in ParseUnscopedName()
672 state->parse_state = copy; in ParseUnscopedName()
678 static inline bool ParseRefQualifier(State *state) { in ParseRefQualifier() argument
679 return ParseCharClass(state, "OR"); in ParseRefQualifier()
686 static bool ParseNestedName(State *state) { in ParseNestedName() argument
687 ComplexityGuard guard(state); in ParseNestedName()
689 ParseState copy = state->parse_state; in ParseNestedName()
690 if (ParseOneCharToken(state, 'N') && EnterNestedName(state) && in ParseNestedName()
691 Optional(ParseCVQualifiers(state)) && in ParseNestedName()
692 Optional(ParseRefQualifier(state)) && ParsePrefix(state) && in ParseNestedName()
693 LeaveNestedName(state, copy.nest_level) && in ParseNestedName()
694 ParseOneCharToken(state, 'E')) { in ParseNestedName()
697 state->parse_state = copy; in ParseNestedName()
712 static bool ParsePrefix(State *state) { in ParsePrefix() argument
713 ComplexityGuard guard(state); in ParsePrefix()
717 MaybeAppendSeparator(state); in ParsePrefix()
718 if (ParseTemplateParam(state) || in ParsePrefix()
719 ParseSubstitution(state, /*accept_std=*/true) || in ParsePrefix()
720 ParseUnscopedName(state) || in ParsePrefix()
721 (ParseOneCharToken(state, 'M') && ParseUnnamedTypeName(state))) { in ParsePrefix()
723 MaybeIncreaseNestLevel(state); in ParsePrefix()
726 MaybeCancelLastSeparator(state); in ParsePrefix()
727 if (has_something && ParseTemplateArgs(state)) { in ParsePrefix()
728 return ParsePrefix(state); in ParsePrefix()
741 static bool ParseUnqualifiedName(State *state) { in ParseUnqualifiedName() argument
742 ComplexityGuard guard(state); in ParseUnqualifiedName()
744 return (ParseOperatorName(state, nullptr) || ParseCtorDtorName(state) || in ParseUnqualifiedName()
745 ParseSourceName(state) || ParseLocalSourceName(state) || in ParseUnqualifiedName()
746 ParseUnnamedTypeName(state)); in ParseUnqualifiedName()
750 static bool ParseSourceName(State *state) { in ParseSourceName() argument
751 ComplexityGuard guard(state); in ParseSourceName()
753 ParseState copy = state->parse_state; in ParseSourceName()
755 if (ParseNumber(state, &length) && ParseIdentifier(state, length)) { in ParseSourceName()
758 state->parse_state = copy; in ParseSourceName()
767 static bool ParseLocalSourceName(State *state) { in ParseLocalSourceName() argument
768 ComplexityGuard guard(state); in ParseLocalSourceName()
770 ParseState copy = state->parse_state; in ParseLocalSourceName()
771 if (ParseOneCharToken(state, 'L') && ParseSourceName(state) && in ParseLocalSourceName()
772 Optional(ParseDiscriminator(state))) { in ParseLocalSourceName()
775 state->parse_state = copy; in ParseLocalSourceName()
783 static bool ParseUnnamedTypeName(State *state) { in ParseUnnamedTypeName() argument
784 ComplexityGuard guard(state); in ParseUnnamedTypeName()
786 ParseState copy = state->parse_state; in ParseUnnamedTypeName()
792 if (ParseTwoCharToken(state, "Ut") && Optional(ParseNumber(state, &which)) && in ParseUnnamedTypeName()
794 ParseOneCharToken(state, '_')) { in ParseUnnamedTypeName()
795 MaybeAppend(state, "{unnamed type#"); in ParseUnnamedTypeName()
796 MaybeAppendDecimal(state, 2 + which); in ParseUnnamedTypeName()
797 MaybeAppend(state, "}"); in ParseUnnamedTypeName()
800 state->parse_state = copy; in ParseUnnamedTypeName()
804 if (ParseTwoCharToken(state, "Ul") && DisableAppend(state) && in ParseUnnamedTypeName()
805 OneOrMore(ParseType, state) && RestoreAppend(state, copy.append) && in ParseUnnamedTypeName()
806 ParseOneCharToken(state, 'E') && Optional(ParseNumber(state, &which)) && in ParseUnnamedTypeName()
808 ParseOneCharToken(state, '_')) { in ParseUnnamedTypeName()
809 MaybeAppend(state, "{lambda()#"); in ParseUnnamedTypeName()
810 MaybeAppendDecimal(state, 2 + which); in ParseUnnamedTypeName()
811 MaybeAppend(state, "}"); in ParseUnnamedTypeName()
814 state->parse_state = copy; in ParseUnnamedTypeName()
822 static bool ParseNumber(State *state, int *number_out) { in ParseNumber() argument
823 ComplexityGuard guard(state); in ParseNumber()
826 if (ParseOneCharToken(state, 'n')) { in ParseNumber()
829 const char *p = RemainingInput(state); in ParseNumber()
844 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseNumber()
845 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseNumber()
857 static bool ParseFloatNumber(State *state) { in ParseFloatNumber() argument
858 ComplexityGuard guard(state); in ParseFloatNumber()
860 const char *p = RemainingInput(state); in ParseFloatNumber()
866 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseFloatNumber()
867 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseFloatNumber()
875 static bool ParseSeqId(State *state) { in ParseSeqId() argument
876 ComplexityGuard guard(state); in ParseSeqId()
878 const char *p = RemainingInput(state); in ParseSeqId()
884 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseSeqId()
885 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseSeqId()
892 static bool ParseIdentifier(State *state, int length) { in ParseIdentifier() argument
893 ComplexityGuard guard(state); in ParseIdentifier()
895 if (length < 0 || !AtLeastNumCharsRemaining(RemainingInput(state), length)) { in ParseIdentifier()
898 if (IdentifierIsAnonymousNamespace(state, length)) { in ParseIdentifier()
899 MaybeAppend(state, "(anonymous namespace)"); in ParseIdentifier()
901 MaybeAppendWithLength(state, RemainingInput(state), length); in ParseIdentifier()
903 state->parse_state.mangled_idx += length; in ParseIdentifier()
910 static bool ParseOperatorName(State *state, int *arity) { in ParseOperatorName() argument
911 ComplexityGuard guard(state); in ParseOperatorName()
913 if (!AtLeastNumCharsRemaining(RemainingInput(state), 2)) { in ParseOperatorName()
917 ParseState copy = state->parse_state; in ParseOperatorName()
918 if (ParseTwoCharToken(state, "cv") && MaybeAppend(state, "operator ") && in ParseOperatorName()
919 EnterNestedName(state) && ParseType(state) && in ParseOperatorName()
920 LeaveNestedName(state, copy.nest_level)) { in ParseOperatorName()
926 state->parse_state = copy; in ParseOperatorName()
929 if (ParseOneCharToken(state, 'v') && ParseDigit(state, arity) && in ParseOperatorName()
930 ParseSourceName(state)) { in ParseOperatorName()
933 state->parse_state = copy; in ParseOperatorName()
937 if (!(IsLower(RemainingInput(state)[0]) && in ParseOperatorName()
938 IsAlpha(RemainingInput(state)[1]))) { in ParseOperatorName()
944 if (RemainingInput(state)[0] == p->abbrev[0] && in ParseOperatorName()
945 RemainingInput(state)[1] == p->abbrev[1]) { in ParseOperatorName()
949 MaybeAppend(state, "operator"); in ParseOperatorName()
951 MaybeAppend(state, " "); in ParseOperatorName()
953 MaybeAppend(state, p->real_name); in ParseOperatorName()
954 state->parse_state.mangled_idx += 2; in ParseOperatorName()
979 static bool ParseSpecialName(State *state) { in ParseSpecialName() argument
980 ComplexityGuard guard(state); in ParseSpecialName()
982 ParseState copy = state->parse_state; in ParseSpecialName()
983 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "VTIS") && in ParseSpecialName()
984 ParseType(state)) { in ParseSpecialName()
987 state->parse_state = copy; in ParseSpecialName()
989 if (ParseTwoCharToken(state, "Tc") && ParseCallOffset(state) && in ParseSpecialName()
990 ParseCallOffset(state) && ParseEncoding(state)) { in ParseSpecialName()
993 state->parse_state = copy; in ParseSpecialName()
995 if (ParseTwoCharToken(state, "GV") && ParseName(state)) { in ParseSpecialName()
998 state->parse_state = copy; in ParseSpecialName()
1000 if (ParseOneCharToken(state, 'T') && ParseCallOffset(state) && in ParseSpecialName()
1001 ParseEncoding(state)) { in ParseSpecialName()
1004 state->parse_state = copy; in ParseSpecialName()
1007 if (ParseTwoCharToken(state, "TC") && ParseType(state) && in ParseSpecialName()
1008 ParseNumber(state, nullptr) && ParseOneCharToken(state, '_') && in ParseSpecialName()
1009 DisableAppend(state) && ParseType(state)) { in ParseSpecialName()
1010 RestoreAppend(state, copy.append); in ParseSpecialName()
1013 state->parse_state = copy; in ParseSpecialName()
1015 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "FJ") && in ParseSpecialName()
1016 ParseType(state)) { in ParseSpecialName()
1019 state->parse_state = copy; in ParseSpecialName()
1021 if (ParseTwoCharToken(state, "GR") && ParseName(state)) { in ParseSpecialName()
1024 state->parse_state = copy; in ParseSpecialName()
1026 if (ParseTwoCharToken(state, "GA") && ParseEncoding(state)) { in ParseSpecialName()
1029 state->parse_state = copy; in ParseSpecialName()
1031 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "hv") && in ParseSpecialName()
1032 ParseCallOffset(state) && ParseEncoding(state)) { in ParseSpecialName()
1035 state->parse_state = copy; in ParseSpecialName()
1041 static bool ParseCallOffset(State *state) { in ParseCallOffset() argument
1042 ComplexityGuard guard(state); in ParseCallOffset()
1044 ParseState copy = state->parse_state; in ParseCallOffset()
1045 if (ParseOneCharToken(state, 'h') && ParseNVOffset(state) && in ParseCallOffset()
1046 ParseOneCharToken(state, '_')) { in ParseCallOffset()
1049 state->parse_state = copy; in ParseCallOffset()
1051 if (ParseOneCharToken(state, 'v') && ParseVOffset(state) && in ParseCallOffset()
1052 ParseOneCharToken(state, '_')) { in ParseCallOffset()
1055 state->parse_state = copy; in ParseCallOffset()
1061 static bool ParseNVOffset(State *state) { in ParseNVOffset() argument
1062 ComplexityGuard guard(state); in ParseNVOffset()
1064 return ParseNumber(state, nullptr); in ParseNVOffset()
1068 static bool ParseVOffset(State *state) { in ParseVOffset() argument
1069 ComplexityGuard guard(state); in ParseVOffset()
1071 ParseState copy = state->parse_state; in ParseVOffset()
1072 if (ParseNumber(state, nullptr) && ParseOneCharToken(state, '_') && in ParseVOffset()
1073 ParseNumber(state, nullptr)) { in ParseVOffset()
1076 state->parse_state = copy; in ParseVOffset()
1085 static bool ParseCtorDtorName(State *state) { in ParseCtorDtorName() argument
1086 ComplexityGuard guard(state); in ParseCtorDtorName()
1088 ParseState copy = state->parse_state; in ParseCtorDtorName()
1089 if (ParseOneCharToken(state, 'C') && ParseCharClass(state, "1234")) { in ParseCtorDtorName()
1090 const char *const prev_name = state->out + state->parse_state.prev_name_idx; in ParseCtorDtorName()
1091 MaybeAppendWithLength(state, prev_name, in ParseCtorDtorName()
1092 state->parse_state.prev_name_length); in ParseCtorDtorName()
1095 state->parse_state = copy; in ParseCtorDtorName()
1097 if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "0124")) { in ParseCtorDtorName()
1098 const char *const prev_name = state->out + state->parse_state.prev_name_idx; in ParseCtorDtorName()
1099 MaybeAppend(state, "~"); in ParseCtorDtorName()
1100 MaybeAppendWithLength(state, prev_name, in ParseCtorDtorName()
1101 state->parse_state.prev_name_length); in ParseCtorDtorName()
1104 state->parse_state = copy; in ParseCtorDtorName()
1111 static bool ParseDecltype(State *state) { in ParseDecltype() argument
1112 ComplexityGuard guard(state); in ParseDecltype()
1115 ParseState copy = state->parse_state; in ParseDecltype()
1116 if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "tT") && in ParseDecltype()
1117 ParseExpression(state) && ParseOneCharToken(state, 'E')) { in ParseDecltype()
1120 state->parse_state = copy; in ParseDecltype()
1143 static bool ParseType(State *state) { in ParseType() argument
1144 ComplexityGuard guard(state); in ParseType()
1146 ParseState copy = state->parse_state; in ParseType()
1161 if (ParseCVQualifiers(state)) { in ParseType()
1162 const bool result = ParseType(state); in ParseType()
1163 if (!result) state->parse_state = copy; in ParseType()
1166 state->parse_state = copy; in ParseType()
1172 if (ParseCharClass(state, "OPRCG")) { in ParseType()
1173 const bool result = ParseType(state); in ParseType()
1174 if (!result) state->parse_state = copy; in ParseType()
1177 state->parse_state = copy; in ParseType()
1179 if (ParseTwoCharToken(state, "Dp") && ParseType(state)) { in ParseType()
1182 state->parse_state = copy; in ParseType()
1184 if (ParseOneCharToken(state, 'U') && ParseSourceName(state) && in ParseType()
1185 ParseType(state)) { in ParseType()
1188 state->parse_state = copy; in ParseType()
1190 if (ParseBuiltinType(state) || ParseFunctionType(state) || in ParseType()
1191 ParseClassEnumType(state) || ParseArrayType(state) || in ParseType()
1192 ParsePointerToMemberType(state) || ParseDecltype(state) || in ParseType()
1194 ParseSubstitution(state, /*accept_std=*/false)) { in ParseType()
1198 if (ParseTemplateTemplateParam(state) && ParseTemplateArgs(state)) { in ParseType()
1201 state->parse_state = copy; in ParseType()
1204 if (ParseTemplateParam(state)) { in ParseType()
1214 static bool ParseCVQualifiers(State *state) { in ParseCVQualifiers() argument
1215 ComplexityGuard guard(state); in ParseCVQualifiers()
1218 num_cv_qualifiers += ParseOneCharToken(state, 'r'); in ParseCVQualifiers()
1219 num_cv_qualifiers += ParseOneCharToken(state, 'V'); in ParseCVQualifiers()
1220 num_cv_qualifiers += ParseOneCharToken(state, 'K'); in ParseCVQualifiers()
1231 static bool ParseBuiltinType(State *state) { in ParseBuiltinType() argument
1232 ComplexityGuard guard(state); in ParseBuiltinType()
1238 if (ParseOneCharToken(state, p->abbrev[0])) { in ParseBuiltinType()
1239 MaybeAppend(state, p->real_name); in ParseBuiltinType()
1242 } else if (p->abbrev[2] == '\0' && ParseTwoCharToken(state, p->abbrev)) { in ParseBuiltinType()
1243 MaybeAppend(state, p->real_name); in ParseBuiltinType()
1248 ParseState copy = state->parse_state; in ParseBuiltinType()
1249 if (ParseOneCharToken(state, 'u') && ParseSourceName(state)) { in ParseBuiltinType()
1252 state->parse_state = copy; in ParseBuiltinType()
1257 static bool ParseFunctionType(State *state) { in ParseFunctionType() argument
1258 ComplexityGuard guard(state); in ParseFunctionType()
1260 ParseState copy = state->parse_state; in ParseFunctionType()
1261 if (ParseOneCharToken(state, 'F') && in ParseFunctionType()
1262 Optional(ParseOneCharToken(state, 'Y')) && ParseBareFunctionType(state) && in ParseFunctionType()
1263 ParseOneCharToken(state, 'E')) { in ParseFunctionType()
1266 state->parse_state = copy; in ParseFunctionType()
1271 static bool ParseBareFunctionType(State *state) { in ParseBareFunctionType() argument
1272 ComplexityGuard guard(state); in ParseBareFunctionType()
1274 ParseState copy = state->parse_state; in ParseBareFunctionType()
1275 DisableAppend(state); in ParseBareFunctionType()
1276 if (OneOrMore(ParseType, state)) { in ParseBareFunctionType()
1277 RestoreAppend(state, copy.append); in ParseBareFunctionType()
1278 MaybeAppend(state, "()"); in ParseBareFunctionType()
1281 state->parse_state = copy; in ParseBareFunctionType()
1286 static bool ParseClassEnumType(State *state) { in ParseClassEnumType() argument
1287 ComplexityGuard guard(state); in ParseClassEnumType()
1289 return ParseName(state); in ParseClassEnumType()
1294 static bool ParseArrayType(State *state) { in ParseArrayType() argument
1295 ComplexityGuard guard(state); in ParseArrayType()
1297 ParseState copy = state->parse_state; in ParseArrayType()
1298 if (ParseOneCharToken(state, 'A') && ParseNumber(state, nullptr) && in ParseArrayType()
1299 ParseOneCharToken(state, '_') && ParseType(state)) { in ParseArrayType()
1302 state->parse_state = copy; in ParseArrayType()
1304 if (ParseOneCharToken(state, 'A') && Optional(ParseExpression(state)) && in ParseArrayType()
1305 ParseOneCharToken(state, '_') && ParseType(state)) { in ParseArrayType()
1308 state->parse_state = copy; in ParseArrayType()
1313 static bool ParsePointerToMemberType(State *state) { in ParsePointerToMemberType() argument
1314 ComplexityGuard guard(state); in ParsePointerToMemberType()
1316 ParseState copy = state->parse_state; in ParsePointerToMemberType()
1317 if (ParseOneCharToken(state, 'M') && ParseType(state) && ParseType(state)) { in ParsePointerToMemberType()
1320 state->parse_state = copy; in ParsePointerToMemberType()
1326 static bool ParseTemplateParam(State *state) { in ParseTemplateParam() argument
1327 ComplexityGuard guard(state); in ParseTemplateParam()
1329 if (ParseTwoCharToken(state, "T_")) { in ParseTemplateParam()
1330 MaybeAppend(state, "?"); // We don't support template substitutions. in ParseTemplateParam()
1334 ParseState copy = state->parse_state; in ParseTemplateParam()
1335 if (ParseOneCharToken(state, 'T') && ParseNumber(state, nullptr) && in ParseTemplateParam()
1336 ParseOneCharToken(state, '_')) { in ParseTemplateParam()
1337 MaybeAppend(state, "?"); // We don't support template substitutions. in ParseTemplateParam()
1340 state->parse_state = copy; in ParseTemplateParam()
1346 static bool ParseTemplateTemplateParam(State *state) { in ParseTemplateTemplateParam() argument
1347 ComplexityGuard guard(state); in ParseTemplateTemplateParam()
1349 return (ParseTemplateParam(state) || in ParseTemplateTemplateParam()
1351 ParseSubstitution(state, /*accept_std=*/false)); in ParseTemplateTemplateParam()
1355 static bool ParseTemplateArgs(State *state) { in ParseTemplateArgs() argument
1356 ComplexityGuard guard(state); in ParseTemplateArgs()
1358 ParseState copy = state->parse_state; in ParseTemplateArgs()
1359 DisableAppend(state); in ParseTemplateArgs()
1360 if (ParseOneCharToken(state, 'I') && OneOrMore(ParseTemplateArg, state) && in ParseTemplateArgs()
1361 ParseOneCharToken(state, 'E')) { in ParseTemplateArgs()
1362 RestoreAppend(state, copy.append); in ParseTemplateArgs()
1363 MaybeAppend(state, "<>"); in ParseTemplateArgs()
1366 state->parse_state = copy; in ParseTemplateArgs()
1374 static bool ParseTemplateArg(State *state) { in ParseTemplateArg() argument
1375 ComplexityGuard guard(state); in ParseTemplateArg()
1377 ParseState copy = state->parse_state; in ParseTemplateArg()
1378 if (ParseOneCharToken(state, 'J') && ZeroOrMore(ParseTemplateArg, state) && in ParseTemplateArg()
1379 ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1382 state->parse_state = copy; in ParseTemplateArg()
1452 if (ParseLocalSourceName(state) && Optional(ParseTemplateArgs(state))) { in ParseTemplateArg()
1453 copy = state->parse_state; in ParseTemplateArg()
1454 if (ParseExprCastValue(state) && ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1457 state->parse_state = copy; in ParseTemplateArg()
1463 if (ParseType(state) || ParseExprPrimary(state)) { in ParseTemplateArg()
1466 state->parse_state = copy; in ParseTemplateArg()
1468 if (ParseOneCharToken(state, 'X') && ParseExpression(state) && in ParseTemplateArg()
1469 ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1472 state->parse_state = copy; in ParseTemplateArg()
1479 static inline bool ParseUnresolvedType(State *state) { in ParseUnresolvedType() argument
1481 return (ParseTemplateParam(state) && Optional(ParseTemplateArgs(state))) || in ParseUnresolvedType()
1482 ParseDecltype(state) || ParseSubstitution(state, /*accept_std=*/false); in ParseUnresolvedType()
1486 static inline bool ParseSimpleId(State *state) { in ParseSimpleId() argument
1491 return ParseSourceName(state) && Optional(ParseTemplateArgs(state)); in ParseSimpleId()
1497 static bool ParseBaseUnresolvedName(State *state) { in ParseBaseUnresolvedName() argument
1498 ComplexityGuard guard(state); in ParseBaseUnresolvedName()
1501 if (ParseSimpleId(state)) { in ParseBaseUnresolvedName()
1505 ParseState copy = state->parse_state; in ParseBaseUnresolvedName()
1506 if (ParseTwoCharToken(state, "on") && ParseOperatorName(state, nullptr) && in ParseBaseUnresolvedName()
1507 Optional(ParseTemplateArgs(state))) { in ParseBaseUnresolvedName()
1510 state->parse_state = copy; in ParseBaseUnresolvedName()
1512 if (ParseTwoCharToken(state, "dn") && in ParseBaseUnresolvedName()
1513 (ParseUnresolvedType(state) || ParseSimpleId(state))) { in ParseBaseUnresolvedName()
1516 state->parse_state = copy; in ParseBaseUnresolvedName()
1527 static bool ParseUnresolvedName(State *state) { in ParseUnresolvedName() argument
1528 ComplexityGuard guard(state); in ParseUnresolvedName()
1531 ParseState copy = state->parse_state; in ParseUnresolvedName()
1532 if (Optional(ParseTwoCharToken(state, "gs")) && in ParseUnresolvedName()
1533 ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1536 state->parse_state = copy; in ParseUnresolvedName()
1538 if (ParseTwoCharToken(state, "sr") && ParseUnresolvedType(state) && in ParseUnresolvedName()
1539 ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1542 state->parse_state = copy; in ParseUnresolvedName()
1544 if (ParseTwoCharToken(state, "sr") && ParseOneCharToken(state, 'N') && in ParseUnresolvedName()
1545 ParseUnresolvedType(state) && in ParseUnresolvedName()
1546 OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) && in ParseUnresolvedName()
1547 ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1550 state->parse_state = copy; in ParseUnresolvedName()
1552 if (Optional(ParseTwoCharToken(state, "gs")) && in ParseUnresolvedName()
1553 ParseTwoCharToken(state, "sr") && in ParseUnresolvedName()
1554 OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) && in ParseUnresolvedName()
1555 ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1558 state->parse_state = copy; in ParseUnresolvedName()
1582 static bool ParseExpression(State *state) { in ParseExpression() argument
1583 ComplexityGuard guard(state); in ParseExpression()
1585 if (ParseTemplateParam(state) || ParseExprPrimary(state)) { in ParseExpression()
1590 ParseState copy = state->parse_state; in ParseExpression()
1591 if (ParseTwoCharToken(state, "cl") && OneOrMore(ParseExpression, state) && in ParseExpression()
1592 ParseOneCharToken(state, 'E')) { in ParseExpression()
1595 state->parse_state = copy; in ParseExpression()
1598 if (ParseTwoCharToken(state, "fp") && Optional(ParseCVQualifiers(state)) && in ParseExpression()
1599 Optional(ParseNumber(state, nullptr)) && ParseOneCharToken(state, '_')) { in ParseExpression()
1602 state->parse_state = copy; in ParseExpression()
1605 if (ParseTwoCharToken(state, "fL") && Optional(ParseNumber(state, nullptr)) && in ParseExpression()
1606 ParseOneCharToken(state, 'p') && Optional(ParseCVQualifiers(state)) && in ParseExpression()
1607 Optional(ParseNumber(state, nullptr)) && ParseOneCharToken(state, '_')) { in ParseExpression()
1610 state->parse_state = copy; in ParseExpression()
1620 if (ParseTwoCharToken(state, "cv")) { in ParseExpression()
1621 if (ParseType(state)) { in ParseExpression()
1622 ParseState copy2 = state->parse_state; in ParseExpression()
1623 if (ParseOneCharToken(state, '_') && ZeroOrMore(ParseExpression, state) && in ParseExpression()
1624 ParseOneCharToken(state, 'E')) { in ParseExpression()
1627 state->parse_state = copy2; in ParseExpression()
1628 if (ParseExpression(state)) { in ParseExpression()
1639 if (ParseOperatorName(state, &arity) && in ParseExpression()
1641 (arity < 3 || ParseExpression(state)) && in ParseExpression()
1642 (arity < 2 || ParseExpression(state)) && in ParseExpression()
1643 (arity < 1 || ParseExpression(state))) { in ParseExpression()
1647 state->parse_state = copy; in ParseExpression()
1650 if (ParseTwoCharToken(state, "st") && ParseType(state)) { in ParseExpression()
1653 state->parse_state = copy; in ParseExpression()
1656 if ((ParseTwoCharToken(state, "dt") || ParseTwoCharToken(state, "pt")) && in ParseExpression()
1657 ParseExpression(state) && ParseType(state)) { in ParseExpression()
1660 state->parse_state = copy; in ParseExpression()
1665 if (ParseTwoCharToken(state, "ds") && ParseExpression(state) && in ParseExpression()
1666 ParseExpression(state)) { in ParseExpression()
1669 state->parse_state = copy; in ParseExpression()
1672 if (ParseTwoCharToken(state, "sp") && ParseExpression(state)) { in ParseExpression()
1675 state->parse_state = copy; in ParseExpression()
1677 return ParseUnresolvedName(state); in ParseExpression()
1706 static bool ParseExprPrimary(State *state) { in ParseExprPrimary() argument
1707 ComplexityGuard guard(state); in ParseExprPrimary()
1709 ParseState copy = state->parse_state; in ParseExprPrimary()
1713 if (ParseTwoCharToken(state, "LZ")) { in ParseExprPrimary()
1714 if (ParseEncoding(state) && ParseOneCharToken(state, 'E')) { in ParseExprPrimary()
1718 state->parse_state = copy; in ParseExprPrimary()
1723 if (ParseOneCharToken(state, 'L') && ParseType(state) && in ParseExprPrimary()
1724 ParseExprCastValue(state)) { in ParseExprPrimary()
1727 state->parse_state = copy; in ParseExprPrimary()
1729 if (ParseOneCharToken(state, 'L') && ParseMangledName(state) && in ParseExprPrimary()
1730 ParseOneCharToken(state, 'E')) { in ParseExprPrimary()
1733 state->parse_state = copy; in ParseExprPrimary()
1739 static bool ParseExprCastValue(State *state) { in ParseExprCastValue() argument
1740 ComplexityGuard guard(state); in ParseExprCastValue()
1745 ParseState copy = state->parse_state; in ParseExprCastValue()
1746 if (ParseNumber(state, nullptr) && ParseOneCharToken(state, 'E')) { in ParseExprCastValue()
1749 state->parse_state = copy; in ParseExprCastValue()
1751 if (ParseFloatNumber(state) && ParseOneCharToken(state, 'E')) { in ParseExprCastValue()
1754 state->parse_state = copy; in ParseExprCastValue()
1768 static bool ParseLocalNameSuffix(State *state) { in ParseLocalNameSuffix() argument
1769 ComplexityGuard guard(state); in ParseLocalNameSuffix()
1772 if (MaybeAppend(state, "::") && ParseName(state) && in ParseLocalNameSuffix()
1773 Optional(ParseDiscriminator(state))) { in ParseLocalNameSuffix()
1780 if (state->parse_state.append) { in ParseLocalNameSuffix()
1781 state->out[state->parse_state.out_cur_idx - 2] = '\0'; in ParseLocalNameSuffix()
1784 return ParseOneCharToken(state, 's') && Optional(ParseDiscriminator(state)); in ParseLocalNameSuffix()
1787 static bool ParseLocalName(State *state) { in ParseLocalName() argument
1788 ComplexityGuard guard(state); in ParseLocalName()
1790 ParseState copy = state->parse_state; in ParseLocalName()
1791 if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && in ParseLocalName()
1792 ParseOneCharToken(state, 'E') && ParseLocalNameSuffix(state)) { in ParseLocalName()
1795 state->parse_state = copy; in ParseLocalName()
1800 static bool ParseDiscriminator(State *state) { in ParseDiscriminator() argument
1801 ComplexityGuard guard(state); in ParseDiscriminator()
1803 ParseState copy = state->parse_state; in ParseDiscriminator()
1804 if (ParseOneCharToken(state, '_') && ParseNumber(state, nullptr)) { in ParseDiscriminator()
1807 state->parse_state = copy; in ParseDiscriminator()
1822 static bool ParseSubstitution(State *state, bool accept_std) { in ParseSubstitution() argument
1823 ComplexityGuard guard(state); in ParseSubstitution()
1825 if (ParseTwoCharToken(state, "S_")) { in ParseSubstitution()
1826 MaybeAppend(state, "?"); // We don't support substitutions. in ParseSubstitution()
1830 ParseState copy = state->parse_state; in ParseSubstitution()
1831 if (ParseOneCharToken(state, 'S') && ParseSeqId(state) && in ParseSubstitution()
1832 ParseOneCharToken(state, '_')) { in ParseSubstitution()
1833 MaybeAppend(state, "?"); // We don't support substitutions. in ParseSubstitution()
1836 state->parse_state = copy; in ParseSubstitution()
1839 if (ParseOneCharToken(state, 'S')) { in ParseSubstitution()
1842 if (RemainingInput(state)[0] == p->abbrev[1] && in ParseSubstitution()
1844 MaybeAppend(state, "std"); in ParseSubstitution()
1846 MaybeAppend(state, "::"); in ParseSubstitution()
1847 MaybeAppend(state, p->real_name); in ParseSubstitution()
1849 ++state->parse_state.mangled_idx; in ParseSubstitution()
1854 state->parse_state = copy; in ParseSubstitution()
1860 static bool ParseTopLevelMangledName(State *state) { in ParseTopLevelMangledName() argument
1861 ComplexityGuard guard(state); in ParseTopLevelMangledName()
1863 if (ParseMangledName(state)) { in ParseTopLevelMangledName()
1864 if (RemainingInput(state)[0] != '\0') { in ParseTopLevelMangledName() local
1866 if (IsFunctionCloneSuffix(RemainingInput(state))) { in ParseTopLevelMangledName()
1871 if (RemainingInput(state)[0] == '@') { in ParseTopLevelMangledName() local
1872 MaybeAppend(state, RemainingInput(state)); in ParseTopLevelMangledName()
1882 static bool Overflowed(const State *state) { in Overflowed() argument
1883 return state->parse_state.out_cur_idx >= state->out_end_idx; in Overflowed()
1888 State state; in Demangle() local
1889 InitState(&state, mangled, out, out_size); in Demangle()
1890 return ParseTopLevelMangledName(&state) && !Overflowed(&state); in Demangle()