src/developer/debug/zxdb/console/format_name.cc
// This annoyingly duplicates Identifier::GetName but is required to get syntax highlighting for all
// the components.
This annoyingly duplicates Identifier::GetName but is required to get syntax highlighting for all
the components.
This annoyingly duplicates Identifier :: GetName but is required to get syntax highlighting for all the components .
OutputBuffer FormatIdentifier(const ParsedIdentifier& identifier,
                              const FormatIdentifierOptions& options) {
  OutputBuffer result;
  if (options.show_global_qual && identifier.qualification() == IdentifierQualification::kGlobal)
    result.Append(identifier.GetSeparator());
  const auto& comps = identifier.components();
  for (size_t i = 0; i < comps.size(); i++) {
    const auto& comp = comps[i];
    if (i > 0)
      result.Append(identifier.GetSeparator());
    if (comp.special() == SpecialIdentifier::kNone) {
      std::string name = comp.name();
      if (name.empty()) {
        result.Append(Syntax::kComment, kAnonIdentifierComponentName);
      } else {
        bool needs_escaping = !ExprTokenizer::IsNameToken(name);
        if (needs_escaping)
          result.Append(Syntax::kComment, "$(");
        if (options.bold_last && i == comps.size() - 1)
          result.Append(Syntax::kHeading, needs_escaping ? EscapeComponent(name) : name);
        else
          result.Append(Syntax::kNormal, needs_escaping ? EscapeComponent(name) : name);
        if (needs_escaping)
          result.Append(Syntax::kComment, ")");
      }
    } else if (comp.special() == SpecialIdentifier::kAnon) {
      result.Append(Syntax::kComment, std::string(SpecialIdentifierToString(comp.special())));
    } else {
      if (SpecialIdentifierHasData(comp.special())) {
        result.Append(Syntax::kComment,
                      std::string(SpecialIdentifierToString(comp.special())) + "(");
        result.Append(comp.name());
        result.Append(Syntax::kComment, ")");
      } else {
        result.Append(Syntax::kNormal, std::string(SpecialIdentifierToString(comp.special())));
      }
    }
    if (comp.has_template()) {
      std::string t_string("<");
      if (!comp.template_contents().empty()) {
        if (options.elide_templates) {
          t_string += "…";
        } else {
          for (size_t t_i = 0; t_i < comp.template_contents().size(); t_i++) {
            if (t_i > 0)
              t_string += ", ";
            t_string += comp.template_contents()[t_i];
          }
        }
      }
      t_string.push_back('>');
      result.Append(Syntax::kComment, std::move(t_string));
    }
  }
  return result;
}
OutputBuffer FormatIdentifier ( const ParsedIdentifier & identifier , const FormatIdentifierOptions & options ) { OutputBuffer result ; if ( options . show_global_qual && identifier . qualification ( ) == IdentifierQualification :: kGlobal ) result . Append ( identifier . GetSeparator ( ) ) ; const auto & comps = identifier . components ( ) ; for ( size_t i = 0 ; i < comps . size ( ) ; i ++ ) { const auto & comp = comps [ i ] ; if ( i > 0 ) result . Append ( identifier . GetSeparator ( ) ) ; if ( comp . special ( ) == SpecialIdentifier :: kNone ) { std :: string name = comp . name ( ) ; if ( name . empty ( ) ) { result . Append ( Syntax :: kComment , kAnonIdentifierComponentName ) ; } else { bool needs_escaping = ! ExprTokenizer :: IsNameToken ( name ) ; if ( needs_escaping ) result . Append ( Syntax :: kComment , " " ) ; if ( options . bold_last && i == comps . size ( ) - 1 ) result . Append ( Syntax :: kHeading , needs_escaping ? EscapeComponent ( name ) : name ) ; else result . Append ( Syntax :: kNormal , needs_escaping ? EscapeComponent ( name ) : name ) ; if ( needs_escaping ) result . Append ( Syntax :: kComment , " " ) ; } } else if ( comp . special ( ) == SpecialIdentifier :: kAnon ) { result . Append ( Syntax :: kComment , std :: string ( SpecialIdentifierToString ( comp . special ( ) ) ) ) ; } else { if ( SpecialIdentifierHasData ( comp . special ( ) ) ) { result . Append ( Syntax :: kComment , std :: string ( SpecialIdentifierToString ( comp . special ( ) ) ) + " " ) ; result . Append ( comp . name ( ) ) ; result . Append ( Syntax :: kComment , " " ) ; } else { result . Append ( Syntax :: kNormal , std :: string ( SpecialIdentifierToString ( comp . special ( ) ) ) ) ; } } if ( comp . has_template ( ) ) { std :: string t_string ( " " ) ; if ( ! comp . template_contents ( ) . empty ( ) ) { if ( options . elide_templates ) { t_string += " } else { for ( size_t t_i = 0 ; t_i < comp . template_contents ( ) . size ( ) ; t_i ++ ) { if ( t_i > 0 ) t_string += " " ; t_string += comp . template_contents ( ) [ t_i ] ; } } } t_string . push_back ( ' ' ) ; result . Append ( Syntax :: kComment , std :: move ( t_string ) ) ; } } return result ; }
This annoyingly duplicates Identifier::GetName but is required to get syntax highlighting for all
the components.
This annoyingly duplicates Identifier :: GetName but is required to get syntax highlighting for all the components .
// Name. // Provide names for anonymous components. // Always dim anonymous names. // Other special name. // Special identifier has data, dim the tag part to emphasize the contents. // Standalone special identifier, just append it as normal. // Template.