• Home
  • Raw
  • Download

Lines Matching full:state

151 // State needed for demangling.  This struct is copied in almost every stack
169 // One-off state for demangling that's not subject to backtracking -- either
181 ParseState parse_state; // Backtrackable state copied for most frames.
182 } State; typedef
189 explicit ComplexityGuard(State *state) : state_(state) { in ComplexityGuard() argument
190 ++state->recursion_depth; in ComplexityGuard()
191 ++state->steps; in ComplexityGuard()
222 State *state_;
256 static void InitState(State *state, const char *mangled, char *out, in InitState() argument
258 state->mangled_begin = mangled; in InitState()
259 state->out = out; in InitState()
260 state->out_end_idx = out_size; in InitState()
261 state->recursion_depth = 0; in InitState()
262 state->steps = 0; in InitState()
264 state->parse_state.mangled_idx = 0; in InitState()
265 state->parse_state.out_cur_idx = 0; in InitState()
266 state->parse_state.prev_name_idx = 0; in InitState()
267 state->parse_state.prev_name_length = -1; in InitState()
268 state->parse_state.nest_level = -1; in InitState()
269 state->parse_state.append = true; in InitState()
272 static inline const char *RemainingInput(State *state) { in RemainingInput() argument
273 return &state->mangled_begin[state->parse_state.mangled_idx]; in RemainingInput()
279 static bool ParseOneCharToken(State *state, const char one_char_token) { in ParseOneCharToken() argument
280 ComplexityGuard guard(state); in ParseOneCharToken()
282 if (RemainingInput(state)[0] == one_char_token) { in ParseOneCharToken() local
283 ++state->parse_state.mangled_idx; in ParseOneCharToken()
292 static bool ParseTwoCharToken(State *state, const char *two_char_token) { in ParseTwoCharToken() argument
293 ComplexityGuard guard(state); in ParseTwoCharToken()
295 if (RemainingInput(state)[0] == two_char_token[0] && in ParseTwoCharToken()
296 RemainingInput(state)[1] == two_char_token[1]) { in ParseTwoCharToken()
297 state->parse_state.mangled_idx += 2; in ParseTwoCharToken()
305 static bool ParseCharClass(State *state, const char *char_class) { in ParseCharClass() argument
306 ComplexityGuard guard(state); in ParseCharClass()
308 if (RemainingInput(state)[0] == '\0') { in ParseCharClass() local
313 if (RemainingInput(state)[0] == *p) { in ParseCharClass()
314 ++state->parse_state.mangled_idx; in ParseCharClass()
321 static bool ParseDigit(State *state, int *digit) { in ParseDigit() argument
322 char c = RemainingInput(state)[0]; in ParseDigit()
323 if (ParseCharClass(state, "0123456789")) { in ParseDigit()
336 typedef bool (*ParseFunc)(State *);
337 static bool OneOrMore(ParseFunc parse_func, State *state) { in OneOrMore() argument
338 if (parse_func(state)) { in OneOrMore()
339 while (parse_func(state)) { in OneOrMore()
349 // ParseOneCharToken(state, 'E')).
350 static bool ZeroOrMore(ParseFunc parse_func, State *state) { in ZeroOrMore() argument
351 while (parse_func(state)) { in ZeroOrMore()
359 static void Append(State *state, const char *const str, const int length) { in Append() argument
361 if (state->parse_state.out_cur_idx + 1 < in Append()
362 state->out_end_idx) { // +1 for '\0' in Append()
363 state->out[state->parse_state.out_cur_idx++] = str[i]; in Append()
366 state->parse_state.out_cur_idx = state->out_end_idx + 1; in Append()
370 if (state->parse_state.out_cur_idx < state->out_end_idx) { in Append()
371 state->out[state->parse_state.out_cur_idx] = in Append()
411 static bool EndsWith(State *state, const char chr) { in EndsWith() argument
412 return state->parse_state.out_cur_idx > 0 && in EndsWith()
413 state->parse_state.out_cur_idx < state->out_end_idx && in EndsWith()
414 chr == state->out[state->parse_state.out_cur_idx - 1]; in EndsWith()
417 // Append "str" with some tweaks, iff "append" state is true.
418 static void MaybeAppendWithLength(State *state, const char *const str, in MaybeAppendWithLength() argument
420 if (state->parse_state.append && length > 0) { in MaybeAppendWithLength()
423 if (str[0] == '<' && EndsWith(state, '<')) { in MaybeAppendWithLength()
424 Append(state, " ", 1); in MaybeAppendWithLength()
428 if (state->parse_state.out_cur_idx < state->out_end_idx && in MaybeAppendWithLength()
430 state->parse_state.prev_name_idx = state->parse_state.out_cur_idx; in MaybeAppendWithLength()
431 state->parse_state.prev_name_length = length; in MaybeAppendWithLength()
433 Append(state, str, length); in MaybeAppendWithLength()
438 static bool MaybeAppendDecimal(State *state, unsigned int val) { in MaybeAppendDecimal() argument
445 if (state->parse_state.append) { in MaybeAppendDecimal()
455 Append(state, p, kMaxLength - (p - buf)); in MaybeAppendDecimal()
463 static bool MaybeAppend(State *state, const char *const str) { in MaybeAppend() argument
464 if (state->parse_state.append) { in MaybeAppend()
466 MaybeAppendWithLength(state, str, length); in MaybeAppend()
472 static bool EnterNestedName(State *state) { in EnterNestedName() argument
473 state->parse_state.nest_level = 0; in EnterNestedName()
478 static bool LeaveNestedName(State *state, int16_t prev_value) { in LeaveNestedName() argument
479 state->parse_state.nest_level = prev_value; in LeaveNestedName()
484 static bool DisableAppend(State *state) { in DisableAppend() argument
485 state->parse_state.append = false; in DisableAppend()
489 // Restore the append mode to the previous state.
490 static bool RestoreAppend(State *state, bool prev_value) { in RestoreAppend() argument
491 state->parse_state.append = prev_value; in RestoreAppend()
496 static void MaybeIncreaseNestLevel(State *state) { in MaybeIncreaseNestLevel() argument
497 if (state->parse_state.nest_level > -1) { in MaybeIncreaseNestLevel()
498 ++state->parse_state.nest_level; in MaybeIncreaseNestLevel()
503 static void MaybeAppendSeparator(State *state) { in MaybeAppendSeparator() argument
504 if (state->parse_state.nest_level >= 1) { in MaybeAppendSeparator()
505 MaybeAppend(state, "::"); in MaybeAppendSeparator()
510 static void MaybeCancelLastSeparator(State *state) { in MaybeCancelLastSeparator() argument
511 if (state->parse_state.nest_level >= 1 && state->parse_state.append && in MaybeCancelLastSeparator()
512 state->parse_state.out_cur_idx >= 2) { in MaybeCancelLastSeparator()
513 state->parse_state.out_cur_idx -= 2; in MaybeCancelLastSeparator()
514 state->out[state->parse_state.out_cur_idx] = '\0'; in MaybeCancelLastSeparator()
520 static bool IdentifierIsAnonymousNamespace(State *state, int length) { in IdentifierIsAnonymousNamespace() argument
524 StrPrefix(RemainingInput(state), anon_prefix)); in IdentifierIsAnonymousNamespace()
528 static bool ParseMangledName(State *state);
529 static bool ParseEncoding(State *state);
530 static bool ParseName(State *state);
531 static bool ParseUnscopedName(State *state);
532 static bool ParseNestedName(State *state);
533 static bool ParsePrefix(State *state);
534 static bool ParseUnqualifiedName(State *state);
535 static bool ParseSourceName(State *state);
536 static bool ParseLocalSourceName(State *state);
537 static bool ParseUnnamedTypeName(State *state);
538 static bool ParseNumber(State *state, int *number_out);
539 static bool ParseFloatNumber(State *state);
540 static bool ParseSeqId(State *state);
541 static bool ParseIdentifier(State *state, int length);
542 static bool ParseOperatorName(State *state, int *arity);
543 static bool ParseSpecialName(State *state);
544 static bool ParseCallOffset(State *state);
545 static bool ParseNVOffset(State *state);
546 static bool ParseVOffset(State *state);
547 static bool ParseCtorDtorName(State *state);
548 static bool ParseDecltype(State *state);
549 static bool ParseType(State *state);
550 static bool ParseCVQualifiers(State *state);
551 static bool ParseBuiltinType(State *state);
552 static bool ParseFunctionType(State *state);
553 static bool ParseBareFunctionType(State *state);
554 static bool ParseClassEnumType(State *state);
555 static bool ParseArrayType(State *state);
556 static bool ParsePointerToMemberType(State *state);
557 static bool ParseTemplateParam(State *state);
558 static bool ParseTemplateTemplateParam(State *state);
559 static bool ParseTemplateArgs(State *state);
560 static bool ParseTemplateArg(State *state);
561 static bool ParseBaseUnresolvedName(State *state);
562 static bool ParseUnresolvedName(State *state);
563 static bool ParseExpression(State *state);
564 static bool ParseExprPrimary(State *state);
565 static bool ParseExprCastValue(State *state);
566 static bool ParseLocalName(State *state);
567 static bool ParseLocalNameSuffix(State *state);
568 static bool ParseDiscriminator(State *state);
569 static bool ParseSubstitution(State *state, bool accept_std);
581 // Each parsing function changes the parse state and returns true on
582 // success, or returns false and doesn't change the parse state (note:
584 // To ensure that the parse state isn't changed in the latter case, we
585 // save the original state before we call multiple parsing functions
603 static bool ParseMangledName(State *state) { in ParseMangledName() argument
604 ComplexityGuard guard(state); in ParseMangledName()
606 return ParseTwoCharToken(state, "_Z") && ParseEncoding(state); in ParseMangledName()
612 static bool ParseEncoding(State *state) { in ParseEncoding() argument
613 ComplexityGuard guard(state); in ParseEncoding()
618 // Since Optional(...) can't fail, there's no need to copy the state for in ParseEncoding()
620 if (ParseName(state) && Optional(ParseBareFunctionType(state))) { in ParseEncoding()
624 if (ParseSpecialName(state)) { in ParseEncoding()
634 static bool ParseName(State *state) { in ParseName() argument
635 ComplexityGuard guard(state); in ParseName()
637 if (ParseNestedName(state) || ParseLocalName(state)) { in ParseName()
649 ParseState copy = state->parse_state; in ParseName()
651 if (ParseSubstitution(state, /*accept_std=*/false) && in ParseName()
652 ParseTemplateArgs(state)) { in ParseName()
655 state->parse_state = copy; in ParseName()
657 // Note there's no need to restore state after this since only the first in ParseName()
659 return ParseUnscopedName(state) && Optional(ParseTemplateArgs(state)); in ParseName()
664 static bool ParseUnscopedName(State *state) { in ParseUnscopedName() argument
665 ComplexityGuard guard(state); in ParseUnscopedName()
667 if (ParseUnqualifiedName(state)) { in ParseUnscopedName()
671 ParseState copy = state->parse_state; in ParseUnscopedName()
672 if (ParseTwoCharToken(state, "St") && MaybeAppend(state, "std::") && in ParseUnscopedName()
673 ParseUnqualifiedName(state)) { in ParseUnscopedName()
676 state->parse_state = copy; in ParseUnscopedName()
682 static inline bool ParseRefQualifier(State *state) { in ParseRefQualifier() argument
683 return ParseCharClass(state, "OR"); in ParseRefQualifier()
690 static bool ParseNestedName(State *state) { in ParseNestedName() argument
691 ComplexityGuard guard(state); in ParseNestedName()
693 ParseState copy = state->parse_state; in ParseNestedName()
694 if (ParseOneCharToken(state, 'N') && EnterNestedName(state) && in ParseNestedName()
695 Optional(ParseCVQualifiers(state)) && in ParseNestedName()
696 Optional(ParseRefQualifier(state)) && ParsePrefix(state) && in ParseNestedName()
697 LeaveNestedName(state, copy.nest_level) && in ParseNestedName()
698 ParseOneCharToken(state, 'E')) { in ParseNestedName()
701 state->parse_state = copy; in ParseNestedName()
716 static bool ParsePrefix(State *state) { in ParsePrefix() argument
717 ComplexityGuard guard(state); in ParsePrefix()
721 MaybeAppendSeparator(state); in ParsePrefix()
722 if (ParseTemplateParam(state) || in ParsePrefix()
723 ParseSubstitution(state, /*accept_std=*/true) || in ParsePrefix()
724 ParseUnscopedName(state) || in ParsePrefix()
725 (ParseOneCharToken(state, 'M') && ParseUnnamedTypeName(state))) { in ParsePrefix()
727 MaybeIncreaseNestLevel(state); in ParsePrefix()
730 MaybeCancelLastSeparator(state); in ParsePrefix()
731 if (has_something && ParseTemplateArgs(state)) { in ParsePrefix()
732 return ParsePrefix(state); in ParsePrefix()
745 static bool ParseUnqualifiedName(State *state) { in ParseUnqualifiedName() argument
746 ComplexityGuard guard(state); in ParseUnqualifiedName()
748 return (ParseOperatorName(state, nullptr) || ParseCtorDtorName(state) || in ParseUnqualifiedName()
749 ParseSourceName(state) || ParseLocalSourceName(state) || in ParseUnqualifiedName()
750 ParseUnnamedTypeName(state)); in ParseUnqualifiedName()
754 static bool ParseSourceName(State *state) { in ParseSourceName() argument
755 ComplexityGuard guard(state); in ParseSourceName()
757 ParseState copy = state->parse_state; in ParseSourceName()
759 if (ParseNumber(state, &length) && ParseIdentifier(state, length)) { in ParseSourceName()
762 state->parse_state = copy; in ParseSourceName()
771 static bool ParseLocalSourceName(State *state) { in ParseLocalSourceName() argument
772 ComplexityGuard guard(state); in ParseLocalSourceName()
774 ParseState copy = state->parse_state; in ParseLocalSourceName()
775 if (ParseOneCharToken(state, 'L') && ParseSourceName(state) && in ParseLocalSourceName()
776 Optional(ParseDiscriminator(state))) { in ParseLocalSourceName()
779 state->parse_state = copy; in ParseLocalSourceName()
787 static bool ParseUnnamedTypeName(State *state) { in ParseUnnamedTypeName() argument
788 ComplexityGuard guard(state); in ParseUnnamedTypeName()
790 ParseState copy = state->parse_state; in ParseUnnamedTypeName()
796 if (ParseTwoCharToken(state, "Ut") && Optional(ParseNumber(state, &which)) && in ParseUnnamedTypeName()
798 ParseOneCharToken(state, '_')) { in ParseUnnamedTypeName()
799 MaybeAppend(state, "{unnamed type#"); in ParseUnnamedTypeName()
800 MaybeAppendDecimal(state, 2 + which); in ParseUnnamedTypeName()
801 MaybeAppend(state, "}"); in ParseUnnamedTypeName()
804 state->parse_state = copy; in ParseUnnamedTypeName()
808 if (ParseTwoCharToken(state, "Ul") && DisableAppend(state) && in ParseUnnamedTypeName()
809 OneOrMore(ParseType, state) && RestoreAppend(state, copy.append) && in ParseUnnamedTypeName()
810 ParseOneCharToken(state, 'E') && Optional(ParseNumber(state, &which)) && in ParseUnnamedTypeName()
812 ParseOneCharToken(state, '_')) { in ParseUnnamedTypeName()
813 MaybeAppend(state, "{lambda()#"); in ParseUnnamedTypeName()
814 MaybeAppendDecimal(state, 2 + which); in ParseUnnamedTypeName()
815 MaybeAppend(state, "}"); in ParseUnnamedTypeName()
818 state->parse_state = copy; in ParseUnnamedTypeName()
826 static bool ParseNumber(State *state, int *number_out) { in ParseNumber() argument
827 ComplexityGuard guard(state); in ParseNumber()
830 if (ParseOneCharToken(state, 'n')) { in ParseNumber()
833 const char *p = RemainingInput(state); in ParseNumber()
848 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseNumber()
849 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseNumber()
861 static bool ParseFloatNumber(State *state) { in ParseFloatNumber() argument
862 ComplexityGuard guard(state); in ParseFloatNumber()
864 const char *p = RemainingInput(state); in ParseFloatNumber()
870 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseFloatNumber()
871 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseFloatNumber()
879 static bool ParseSeqId(State *state) { in ParseSeqId() argument
880 ComplexityGuard guard(state); in ParseSeqId()
882 const char *p = RemainingInput(state); in ParseSeqId()
888 if (p != RemainingInput(state)) { // Conversion succeeded. in ParseSeqId()
889 state->parse_state.mangled_idx += p - RemainingInput(state); in ParseSeqId()
896 static bool ParseIdentifier(State *state, int length) { in ParseIdentifier() argument
897 ComplexityGuard guard(state); in ParseIdentifier()
899 if (length < 0 || !AtLeastNumCharsRemaining(RemainingInput(state), length)) { in ParseIdentifier()
902 if (IdentifierIsAnonymousNamespace(state, length)) { in ParseIdentifier()
903 MaybeAppend(state, "(anonymous namespace)"); in ParseIdentifier()
905 MaybeAppendWithLength(state, RemainingInput(state), length); in ParseIdentifier()
907 state->parse_state.mangled_idx += length; in ParseIdentifier()
914 static bool ParseOperatorName(State *state, int *arity) { in ParseOperatorName() argument
915 ComplexityGuard guard(state); in ParseOperatorName()
917 if (!AtLeastNumCharsRemaining(RemainingInput(state), 2)) { in ParseOperatorName()
921 ParseState copy = state->parse_state; in ParseOperatorName()
922 if (ParseTwoCharToken(state, "cv") && MaybeAppend(state, "operator ") && in ParseOperatorName()
923 EnterNestedName(state) && ParseType(state) && in ParseOperatorName()
924 LeaveNestedName(state, copy.nest_level)) { in ParseOperatorName()
930 state->parse_state = copy; in ParseOperatorName()
933 if (ParseOneCharToken(state, 'v') && ParseDigit(state, arity) && in ParseOperatorName()
934 ParseSourceName(state)) { in ParseOperatorName()
937 state->parse_state = copy; in ParseOperatorName()
941 if (!(IsLower(RemainingInput(state)[0]) && in ParseOperatorName()
942 IsAlpha(RemainingInput(state)[1]))) { in ParseOperatorName()
948 if (RemainingInput(state)[0] == p->abbrev[0] && in ParseOperatorName()
949 RemainingInput(state)[1] == p->abbrev[1]) { in ParseOperatorName()
953 MaybeAppend(state, "operator"); in ParseOperatorName()
955 MaybeAppend(state, " "); in ParseOperatorName()
957 MaybeAppend(state, p->real_name); in ParseOperatorName()
958 state->parse_state.mangled_idx += 2; in ParseOperatorName()
984 static bool ParseSpecialName(State *state) { in ParseSpecialName() argument
985 ComplexityGuard guard(state); in ParseSpecialName()
987 ParseState copy = state->parse_state; in ParseSpecialName()
988 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "VTISH") && in ParseSpecialName()
989 ParseType(state)) { in ParseSpecialName()
992 state->parse_state = copy; in ParseSpecialName()
994 if (ParseTwoCharToken(state, "Tc") && ParseCallOffset(state) && in ParseSpecialName()
995 ParseCallOffset(state) && ParseEncoding(state)) { in ParseSpecialName()
998 state->parse_state = copy; in ParseSpecialName()
1000 if (ParseTwoCharToken(state, "GV") && ParseName(state)) { in ParseSpecialName()
1003 state->parse_state = copy; in ParseSpecialName()
1005 if (ParseOneCharToken(state, 'T') && ParseCallOffset(state) && in ParseSpecialName()
1006 ParseEncoding(state)) { in ParseSpecialName()
1009 state->parse_state = copy; in ParseSpecialName()
1012 if (ParseTwoCharToken(state, "TC") && ParseType(state) && in ParseSpecialName()
1013 ParseNumber(state, nullptr) && ParseOneCharToken(state, '_') && in ParseSpecialName()
1014 DisableAppend(state) && ParseType(state)) { in ParseSpecialName()
1015 RestoreAppend(state, copy.append); in ParseSpecialName()
1018 state->parse_state = copy; in ParseSpecialName()
1020 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "FJ") && in ParseSpecialName()
1021 ParseType(state)) { in ParseSpecialName()
1024 state->parse_state = copy; in ParseSpecialName()
1026 if (ParseTwoCharToken(state, "GR") && ParseName(state)) { in ParseSpecialName()
1029 state->parse_state = copy; in ParseSpecialName()
1031 if (ParseTwoCharToken(state, "GA") && ParseEncoding(state)) { in ParseSpecialName()
1034 state->parse_state = copy; in ParseSpecialName()
1036 if (ParseOneCharToken(state, 'T') && ParseCharClass(state, "hv") && in ParseSpecialName()
1037 ParseCallOffset(state) && ParseEncoding(state)) { in ParseSpecialName()
1040 state->parse_state = copy; in ParseSpecialName()
1046 static bool ParseCallOffset(State *state) { in ParseCallOffset() argument
1047 ComplexityGuard guard(state); in ParseCallOffset()
1049 ParseState copy = state->parse_state; in ParseCallOffset()
1050 if (ParseOneCharToken(state, 'h') && ParseNVOffset(state) && in ParseCallOffset()
1051 ParseOneCharToken(state, '_')) { in ParseCallOffset()
1054 state->parse_state = copy; in ParseCallOffset()
1056 if (ParseOneCharToken(state, 'v') && ParseVOffset(state) && in ParseCallOffset()
1057 ParseOneCharToken(state, '_')) { in ParseCallOffset()
1060 state->parse_state = copy; in ParseCallOffset()
1066 static bool ParseNVOffset(State *state) { in ParseNVOffset() argument
1067 ComplexityGuard guard(state); in ParseNVOffset()
1069 return ParseNumber(state, nullptr); in ParseNVOffset()
1073 static bool ParseVOffset(State *state) { in ParseVOffset() argument
1074 ComplexityGuard guard(state); in ParseVOffset()
1076 ParseState copy = state->parse_state; in ParseVOffset()
1077 if (ParseNumber(state, nullptr) && ParseOneCharToken(state, '_') && in ParseVOffset()
1078 ParseNumber(state, nullptr)) { in ParseVOffset()
1081 state->parse_state = copy; in ParseVOffset()
1092 static bool ParseCtorDtorName(State *state) { in ParseCtorDtorName() argument
1093 ComplexityGuard guard(state); in ParseCtorDtorName()
1095 ParseState copy = state->parse_state; in ParseCtorDtorName()
1096 if (ParseOneCharToken(state, 'C')) { in ParseCtorDtorName()
1097 if (ParseCharClass(state, "1234")) { in ParseCtorDtorName()
1099 state->out + state->parse_state.prev_name_idx; in ParseCtorDtorName()
1100 MaybeAppendWithLength(state, prev_name, in ParseCtorDtorName()
1101 state->parse_state.prev_name_length); in ParseCtorDtorName()
1103 } else if (ParseOneCharToken(state, 'I') && ParseCharClass(state, "12") && in ParseCtorDtorName()
1104 ParseClassEnumType(state)) { in ParseCtorDtorName()
1108 state->parse_state = copy; in ParseCtorDtorName()
1110 if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "0124")) { in ParseCtorDtorName()
1111 const char *const prev_name = state->out + state->parse_state.prev_name_idx; in ParseCtorDtorName()
1112 MaybeAppend(state, "~"); in ParseCtorDtorName()
1113 MaybeAppendWithLength(state, prev_name, in ParseCtorDtorName()
1114 state->parse_state.prev_name_length); in ParseCtorDtorName()
1117 state->parse_state = copy; in ParseCtorDtorName()
1124 static bool ParseDecltype(State *state) { in ParseDecltype() argument
1125 ComplexityGuard guard(state); in ParseDecltype()
1128 ParseState copy = state->parse_state; in ParseDecltype()
1129 if (ParseOneCharToken(state, 'D') && ParseCharClass(state, "tT") && in ParseDecltype()
1130 ParseExpression(state) && ParseOneCharToken(state, 'E')) { in ParseDecltype()
1133 state->parse_state = copy; in ParseDecltype()
1157 static bool ParseType(State *state) { in ParseType() argument
1158 ComplexityGuard guard(state); in ParseType()
1160 ParseState copy = state->parse_state; in ParseType()
1175 if (ParseCVQualifiers(state)) { in ParseType()
1176 const bool result = ParseType(state); in ParseType()
1177 if (!result) state->parse_state = copy; in ParseType()
1180 state->parse_state = copy; in ParseType()
1186 if (ParseCharClass(state, "OPRCG")) { in ParseType()
1187 const bool result = ParseType(state); in ParseType()
1188 if (!result) state->parse_state = copy; in ParseType()
1191 state->parse_state = copy; in ParseType()
1193 if (ParseTwoCharToken(state, "Dp") && ParseType(state)) { in ParseType()
1196 state->parse_state = copy; in ParseType()
1198 if (ParseOneCharToken(state, 'U') && ParseSourceName(state) && in ParseType()
1199 ParseType(state)) { in ParseType()
1202 state->parse_state = copy; in ParseType()
1204 if (ParseBuiltinType(state) || ParseFunctionType(state) || in ParseType()
1205 ParseClassEnumType(state) || ParseArrayType(state) || in ParseType()
1206 ParsePointerToMemberType(state) || ParseDecltype(state) || in ParseType()
1208 ParseSubstitution(state, /*accept_std=*/false)) { in ParseType()
1212 if (ParseTemplateTemplateParam(state) && ParseTemplateArgs(state)) { in ParseType()
1215 state->parse_state = copy; in ParseType()
1218 if (ParseTemplateParam(state)) { in ParseType()
1222 if (ParseTwoCharToken(state, "Dv") && ParseNumber(state, nullptr) && in ParseType()
1223 ParseOneCharToken(state, '_')) { in ParseType()
1226 state->parse_state = copy; in ParseType()
1234 static bool ParseCVQualifiers(State *state) { in ParseCVQualifiers() argument
1235 ComplexityGuard guard(state); in ParseCVQualifiers()
1238 num_cv_qualifiers += ParseOneCharToken(state, 'r'); in ParseCVQualifiers()
1239 num_cv_qualifiers += ParseOneCharToken(state, 'V'); in ParseCVQualifiers()
1240 num_cv_qualifiers += ParseOneCharToken(state, 'K'); in ParseCVQualifiers()
1251 static bool ParseBuiltinType(State *state) { in ParseBuiltinType() argument
1252 ComplexityGuard guard(state); in ParseBuiltinType()
1258 if (ParseOneCharToken(state, p->abbrev[0])) { in ParseBuiltinType()
1259 MaybeAppend(state, p->real_name); in ParseBuiltinType()
1262 } else if (p->abbrev[2] == '\0' && ParseTwoCharToken(state, p->abbrev)) { in ParseBuiltinType()
1263 MaybeAppend(state, p->real_name); in ParseBuiltinType()
1268 ParseState copy = state->parse_state; in ParseBuiltinType()
1269 if (ParseOneCharToken(state, 'u') && ParseSourceName(state)) { in ParseBuiltinType()
1272 state->parse_state = copy; in ParseBuiltinType()
1283 static bool ParseExceptionSpec(State *state) { in ParseExceptionSpec() argument
1284 ComplexityGuard guard(state); in ParseExceptionSpec()
1287 if (ParseTwoCharToken(state, "Do")) return true; in ParseExceptionSpec()
1289 ParseState copy = state->parse_state; in ParseExceptionSpec()
1290 if (ParseTwoCharToken(state, "DO") && ParseExpression(state) && in ParseExceptionSpec()
1291 ParseOneCharToken(state, 'E')) { in ParseExceptionSpec()
1294 state->parse_state = copy; in ParseExceptionSpec()
1295 if (ParseTwoCharToken(state, "Dw") && OneOrMore(ParseType, state) && in ParseExceptionSpec()
1296 ParseOneCharToken(state, 'E')) { in ParseExceptionSpec()
1299 state->parse_state = copy; in ParseExceptionSpec()
1305 static bool ParseFunctionType(State *state) { in ParseFunctionType() argument
1306 ComplexityGuard guard(state); in ParseFunctionType()
1308 ParseState copy = state->parse_state; in ParseFunctionType()
1309 if (Optional(ParseExceptionSpec(state)) && ParseOneCharToken(state, 'F') && in ParseFunctionType()
1310 Optional(ParseOneCharToken(state, 'Y')) && ParseBareFunctionType(state) && in ParseFunctionType()
1311 Optional(ParseOneCharToken(state, 'O')) && in ParseFunctionType()
1312 ParseOneCharToken(state, 'E')) { in ParseFunctionType()
1315 state->parse_state = copy; in ParseFunctionType()
1320 static bool ParseBareFunctionType(State *state) { in ParseBareFunctionType() argument
1321 ComplexityGuard guard(state); in ParseBareFunctionType()
1323 ParseState copy = state->parse_state; in ParseBareFunctionType()
1324 DisableAppend(state); in ParseBareFunctionType()
1325 if (OneOrMore(ParseType, state)) { in ParseBareFunctionType()
1326 RestoreAppend(state, copy.append); in ParseBareFunctionType()
1327 MaybeAppend(state, "()"); in ParseBareFunctionType()
1330 state->parse_state = copy; in ParseBareFunctionType()
1335 static bool ParseClassEnumType(State *state) { in ParseClassEnumType() argument
1336 ComplexityGuard guard(state); in ParseClassEnumType()
1338 return ParseName(state); in ParseClassEnumType()
1343 static bool ParseArrayType(State *state) { in ParseArrayType() argument
1344 ComplexityGuard guard(state); in ParseArrayType()
1346 ParseState copy = state->parse_state; in ParseArrayType()
1347 if (ParseOneCharToken(state, 'A') && ParseNumber(state, nullptr) && in ParseArrayType()
1348 ParseOneCharToken(state, '_') && ParseType(state)) { in ParseArrayType()
1351 state->parse_state = copy; in ParseArrayType()
1353 if (ParseOneCharToken(state, 'A') && Optional(ParseExpression(state)) && in ParseArrayType()
1354 ParseOneCharToken(state, '_') && ParseType(state)) { in ParseArrayType()
1357 state->parse_state = copy; in ParseArrayType()
1362 static bool ParsePointerToMemberType(State *state) { in ParsePointerToMemberType() argument
1363 ComplexityGuard guard(state); in ParsePointerToMemberType()
1365 ParseState copy = state->parse_state; in ParsePointerToMemberType()
1366 if (ParseOneCharToken(state, 'M') && ParseType(state) && ParseType(state)) { in ParsePointerToMemberType()
1369 state->parse_state = copy; in ParsePointerToMemberType()
1375 static bool ParseTemplateParam(State *state) { in ParseTemplateParam() argument
1376 ComplexityGuard guard(state); in ParseTemplateParam()
1378 if (ParseTwoCharToken(state, "T_")) { in ParseTemplateParam()
1379 MaybeAppend(state, "?"); // We don't support template substitutions. in ParseTemplateParam()
1383 ParseState copy = state->parse_state; in ParseTemplateParam()
1384 if (ParseOneCharToken(state, 'T') && ParseNumber(state, nullptr) && in ParseTemplateParam()
1385 ParseOneCharToken(state, '_')) { in ParseTemplateParam()
1386 MaybeAppend(state, "?"); // We don't support template substitutions. in ParseTemplateParam()
1389 state->parse_state = copy; in ParseTemplateParam()
1395 static bool ParseTemplateTemplateParam(State *state) { in ParseTemplateTemplateParam() argument
1396 ComplexityGuard guard(state); in ParseTemplateTemplateParam()
1398 return (ParseTemplateParam(state) || in ParseTemplateTemplateParam()
1400 ParseSubstitution(state, /*accept_std=*/false)); in ParseTemplateTemplateParam()
1404 static bool ParseTemplateArgs(State *state) { in ParseTemplateArgs() argument
1405 ComplexityGuard guard(state); in ParseTemplateArgs()
1407 ParseState copy = state->parse_state; in ParseTemplateArgs()
1408 DisableAppend(state); in ParseTemplateArgs()
1409 if (ParseOneCharToken(state, 'I') && OneOrMore(ParseTemplateArg, state) && in ParseTemplateArgs()
1410 ParseOneCharToken(state, 'E')) { in ParseTemplateArgs()
1411 RestoreAppend(state, copy.append); in ParseTemplateArgs()
1412 MaybeAppend(state, "<>"); in ParseTemplateArgs()
1415 state->parse_state = copy; in ParseTemplateArgs()
1423 static bool ParseTemplateArg(State *state) { in ParseTemplateArg() argument
1424 ComplexityGuard guard(state); in ParseTemplateArg()
1426 ParseState copy = state->parse_state; in ParseTemplateArg()
1427 if (ParseOneCharToken(state, 'J') && ZeroOrMore(ParseTemplateArg, state) && in ParseTemplateArg()
1428 ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1431 state->parse_state = copy; in ParseTemplateArg()
1501 if (ParseLocalSourceName(state) && Optional(ParseTemplateArgs(state))) { in ParseTemplateArg()
1502 copy = state->parse_state; in ParseTemplateArg()
1503 if (ParseExprCastValue(state) && ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1506 state->parse_state = copy; in ParseTemplateArg()
1512 if (ParseType(state) || ParseExprPrimary(state)) { in ParseTemplateArg()
1515 state->parse_state = copy; in ParseTemplateArg()
1517 if (ParseOneCharToken(state, 'X') && ParseExpression(state) && in ParseTemplateArg()
1518 ParseOneCharToken(state, 'E')) { in ParseTemplateArg()
1521 state->parse_state = copy; in ParseTemplateArg()
1528 static inline bool ParseUnresolvedType(State *state) { in ParseUnresolvedType() argument
1529 // No ComplexityGuard because we don't copy the state in this stack frame. in ParseUnresolvedType()
1530 return (ParseTemplateParam(state) && Optional(ParseTemplateArgs(state))) || in ParseUnresolvedType()
1531 ParseDecltype(state) || ParseSubstitution(state, /*accept_std=*/false); in ParseUnresolvedType()
1535 static inline bool ParseSimpleId(State *state) { in ParseSimpleId() argument
1536 // No ComplexityGuard because we don't copy the state in this stack frame. in ParseSimpleId()
1540 return ParseSourceName(state) && Optional(ParseTemplateArgs(state)); in ParseSimpleId()
1546 static bool ParseBaseUnresolvedName(State *state) { in ParseBaseUnresolvedName() argument
1547 ComplexityGuard guard(state); in ParseBaseUnresolvedName()
1550 if (ParseSimpleId(state)) { in ParseBaseUnresolvedName()
1554 ParseState copy = state->parse_state; in ParseBaseUnresolvedName()
1555 if (ParseTwoCharToken(state, "on") && ParseOperatorName(state, nullptr) && in ParseBaseUnresolvedName()
1556 Optional(ParseTemplateArgs(state))) { in ParseBaseUnresolvedName()
1559 state->parse_state = copy; in ParseBaseUnresolvedName()
1561 if (ParseTwoCharToken(state, "dn") && in ParseBaseUnresolvedName()
1562 (ParseUnresolvedType(state) || ParseSimpleId(state))) { in ParseBaseUnresolvedName()
1565 state->parse_state = copy; in ParseBaseUnresolvedName()
1576 static bool ParseUnresolvedName(State *state) { in ParseUnresolvedName() argument
1577 ComplexityGuard guard(state); in ParseUnresolvedName()
1580 ParseState copy = state->parse_state; in ParseUnresolvedName()
1581 if (Optional(ParseTwoCharToken(state, "gs")) && in ParseUnresolvedName()
1582 ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1585 state->parse_state = copy; in ParseUnresolvedName()
1587 if (ParseTwoCharToken(state, "sr") && ParseUnresolvedType(state) && in ParseUnresolvedName()
1588 ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1591 state->parse_state = copy; in ParseUnresolvedName()
1593 if (ParseTwoCharToken(state, "sr") && ParseOneCharToken(state, 'N') && in ParseUnresolvedName()
1594 ParseUnresolvedType(state) && in ParseUnresolvedName()
1595 OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) && in ParseUnresolvedName()
1596 ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1599 state->parse_state = copy; in ParseUnresolvedName()
1601 if (Optional(ParseTwoCharToken(state, "gs")) && in ParseUnresolvedName()
1602 ParseTwoCharToken(state, "sr") && in ParseUnresolvedName()
1603 OneOrMore(/* <unresolved-qualifier-level> ::= */ ParseSimpleId, state) && in ParseUnresolvedName()
1604 ParseOneCharToken(state, 'E') && ParseBaseUnresolvedName(state)) { in ParseUnresolvedName()
1607 state->parse_state = copy; in ParseUnresolvedName()
1631 static bool ParseExpression(State *state) { in ParseExpression() argument
1632 ComplexityGuard guard(state); in ParseExpression()
1634 if (ParseTemplateParam(state) || ParseExprPrimary(state)) { in ParseExpression()
1639 ParseState copy = state->parse_state; in ParseExpression()
1640 if (ParseTwoCharToken(state, "cl") && OneOrMore(ParseExpression, state) && in ParseExpression()
1641 ParseOneCharToken(state, 'E')) { in ParseExpression()
1644 state->parse_state = copy; in ParseExpression()
1647 if (ParseTwoCharToken(state, "fp") && Optional(ParseCVQualifiers(state)) && in ParseExpression()
1648 Optional(ParseNumber(state, nullptr)) && ParseOneCharToken(state, '_')) { in ParseExpression()
1651 state->parse_state = copy; in ParseExpression()
1654 if (ParseTwoCharToken(state, "fL") && Optional(ParseNumber(state, nullptr)) && in ParseExpression()
1655 ParseOneCharToken(state, 'p') && Optional(ParseCVQualifiers(state)) && in ParseExpression()
1656 Optional(ParseNumber(state, nullptr)) && ParseOneCharToken(state, '_')) { in ParseExpression()
1659 state->parse_state = copy; in ParseExpression()
1669 if (ParseTwoCharToken(state, "cv")) { in ParseExpression()
1670 if (ParseType(state)) { in ParseExpression()
1671 ParseState copy2 = state->parse_state; in ParseExpression()
1672 if (ParseOneCharToken(state, '_') && ZeroOrMore(ParseExpression, state) && in ParseExpression()
1673 ParseOneCharToken(state, 'E')) { in ParseExpression()
1676 state->parse_state = copy2; in ParseExpression()
1677 if (ParseExpression(state)) { in ParseExpression()
1688 if (ParseOperatorName(state, &arity) && in ParseExpression()
1690 (arity < 3 || ParseExpression(state)) && in ParseExpression()
1691 (arity < 2 || ParseExpression(state)) && in ParseExpression()
1692 (arity < 1 || ParseExpression(state))) { in ParseExpression()
1696 state->parse_state = copy; in ParseExpression()
1699 if (ParseTwoCharToken(state, "st") && ParseType(state)) { in ParseExpression()
1702 state->parse_state = copy; in ParseExpression()
1705 if ((ParseTwoCharToken(state, "dt") || ParseTwoCharToken(state, "pt")) && in ParseExpression()
1706 ParseExpression(state) && ParseType(state)) { in ParseExpression()
1709 state->parse_state = copy; in ParseExpression()
1714 if (ParseTwoCharToken(state, "ds") && ParseExpression(state) && in ParseExpression()
1715 ParseExpression(state)) { in ParseExpression()
1718 state->parse_state = copy; in ParseExpression()
1721 if (ParseTwoCharToken(state, "sp") && ParseExpression(state)) { in ParseExpression()
1724 state->parse_state = copy; in ParseExpression()
1726 return ParseUnresolvedName(state); in ParseExpression()
1755 static bool ParseExprPrimary(State *state) { in ParseExprPrimary() argument
1756 ComplexityGuard guard(state); in ParseExprPrimary()
1758 ParseState copy = state->parse_state; in ParseExprPrimary()
1762 if (ParseTwoCharToken(state, "LZ")) { in ParseExprPrimary()
1763 if (ParseEncoding(state) && ParseOneCharToken(state, 'E')) { in ParseExprPrimary()
1767 state->parse_state = copy; in ParseExprPrimary()
1772 if (ParseOneCharToken(state, 'L') && ParseType(state) && in ParseExprPrimary()
1773 ParseExprCastValue(state)) { in ParseExprPrimary()
1776 state->parse_state = copy; in ParseExprPrimary()
1778 if (ParseOneCharToken(state, 'L') && ParseMangledName(state) && in ParseExprPrimary()
1779 ParseOneCharToken(state, 'E')) { in ParseExprPrimary()
1782 state->parse_state = copy; in ParseExprPrimary()
1788 static bool ParseExprCastValue(State *state) { in ParseExprCastValue() argument
1789 ComplexityGuard guard(state); in ParseExprCastValue()
1794 ParseState copy = state->parse_state; in ParseExprCastValue()
1795 if (ParseNumber(state, nullptr) && ParseOneCharToken(state, 'E')) { in ParseExprCastValue()
1798 state->parse_state = copy; in ParseExprCastValue()
1800 if (ParseFloatNumber(state) && ParseOneCharToken(state, 'E')) { in ParseExprCastValue()
1803 state->parse_state = copy; in ParseExprCastValue()
1817 static bool ParseLocalNameSuffix(State *state) { in ParseLocalNameSuffix() argument
1818 ComplexityGuard guard(state); in ParseLocalNameSuffix()
1821 if (MaybeAppend(state, "::") && ParseName(state) && in ParseLocalNameSuffix()
1822 Optional(ParseDiscriminator(state))) { in ParseLocalNameSuffix()
1829 if (state->parse_state.append) { in ParseLocalNameSuffix()
1830 state->out[state->parse_state.out_cur_idx - 2] = '\0'; in ParseLocalNameSuffix()
1833 return ParseOneCharToken(state, 's') && Optional(ParseDiscriminator(state)); in ParseLocalNameSuffix()
1836 static bool ParseLocalName(State *state) { in ParseLocalName() argument
1837 ComplexityGuard guard(state); in ParseLocalName()
1839 ParseState copy = state->parse_state; in ParseLocalName()
1840 if (ParseOneCharToken(state, 'Z') && ParseEncoding(state) && in ParseLocalName()
1841 ParseOneCharToken(state, 'E') && ParseLocalNameSuffix(state)) { in ParseLocalName()
1844 state->parse_state = copy; in ParseLocalName()
1849 static bool ParseDiscriminator(State *state) { in ParseDiscriminator() argument
1850 ComplexityGuard guard(state); in ParseDiscriminator()
1852 ParseState copy = state->parse_state; in ParseDiscriminator()
1853 if (ParseOneCharToken(state, '_') && ParseNumber(state, nullptr)) { in ParseDiscriminator()
1856 state->parse_state = copy; in ParseDiscriminator()
1871 static bool ParseSubstitution(State *state, bool accept_std) { in ParseSubstitution() argument
1872 ComplexityGuard guard(state); in ParseSubstitution()
1874 if (ParseTwoCharToken(state, "S_")) { in ParseSubstitution()
1875 MaybeAppend(state, "?"); // We don't support substitutions. in ParseSubstitution()
1879 ParseState copy = state->parse_state; in ParseSubstitution()
1880 if (ParseOneCharToken(state, 'S') && ParseSeqId(state) && in ParseSubstitution()
1881 ParseOneCharToken(state, '_')) { in ParseSubstitution()
1882 MaybeAppend(state, "?"); // We don't support substitutions. in ParseSubstitution()
1885 state->parse_state = copy; in ParseSubstitution()
1888 if (ParseOneCharToken(state, 'S')) { in ParseSubstitution()
1891 if (RemainingInput(state)[0] == p->abbrev[1] && in ParseSubstitution()
1893 MaybeAppend(state, "std"); in ParseSubstitution()
1895 MaybeAppend(state, "::"); in ParseSubstitution()
1896 MaybeAppend(state, p->real_name); in ParseSubstitution()
1898 ++state->parse_state.mangled_idx; in ParseSubstitution()
1903 state->parse_state = copy; in ParseSubstitution()
1909 static bool ParseTopLevelMangledName(State *state) { in ParseTopLevelMangledName() argument
1910 ComplexityGuard guard(state); in ParseTopLevelMangledName()
1912 if (ParseMangledName(state)) { in ParseTopLevelMangledName()
1913 if (RemainingInput(state)[0] != '\0') { in ParseTopLevelMangledName() local
1915 if (IsFunctionCloneSuffix(RemainingInput(state))) { in ParseTopLevelMangledName()
1920 if (RemainingInput(state)[0] == '@') { in ParseTopLevelMangledName() local
1921 MaybeAppend(state, RemainingInput(state)); in ParseTopLevelMangledName()
1931 static bool Overflowed(const State *state) { in Overflowed() argument
1932 return state->parse_state.out_cur_idx >= state->out_end_idx; in Overflowed()
1937 State state; in Demangle() local
1938 InitState(&state, mangled, out, out_size); in Demangle()
1939 return ParseTopLevelMangledName(&state) && !Overflowed(&state) && in Demangle()
1940 state.parse_state.out_cur_idx > 0; in Demangle()