aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc-urlifier.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-01-04 09:36:28 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2024-01-04 09:36:28 -0500
commit4ded42c2c5a5c977dbf67b71c5d78f8a6dca7cbb (patch)
tree3f3c45a67da8464752a6c2bb30821a3e08e0d04f /gcc/gcc-urlifier.cc
parent6ecc1e32353e331137647a65a611eeb01b22184c (diff)
downloadgcc-4ded42c2c5a5c977dbf67b71c5d78f8a6dca7cbb.zip
gcc-4ded42c2c5a5c977dbf67b71c5d78f8a6dca7cbb.tar.gz
gcc-4ded42c2c5a5c977dbf67b71c5d78f8a6dca7cbb.tar.bz2
options: wire up options-urls.cc into gcc_urlifier
Changed in v2: - split out from the code that generates options-urls.cc - call the generated function, rather than use a generated array - pass around lang_mask gcc/ChangeLog: * diagnostic.h (diagnostic_make_option_url_cb): Add lang_mask param. (diagnostic_context::make_option_url): Update for lang_mask param. * gcc-urlifier.cc: Include "opts.h" and "options.h". (gcc_urlifier::gcc_urlifier): Add lang_mask param. (gcc_urlifier::m_lang_mask): New field. (doc_urls): Make static. (gcc_urlifier::get_url_for_quoted_text): Use label_text. (gcc_urlifier::get_url_suffix_for_quoted_text): Use label_text. Look for an option by name before trying a binary search in doc_urls. (gcc_urlifier::get_url_suffix_for_quoted_text): Use label_text. (gcc_urlifier::get_url_suffix_for_option): New. (make_gcc_urlifier): Add lang_mask param. (selftest::gcc_urlifier_cc_tests): Update for above changes. Verify that a URL is found for "-fpack-struct". * gcc-urlifier.def: Drop options "--version" and "-fpack-struct". * gcc-urlifier.h (make_gcc_urlifier): Add lang_mask param. * gcc.cc (driver::global_initializations): Pass 0 for lang_mask to make_gcc_urlifier. * opts-diagnostic.h (get_option_url): Add lang_mask param. * opts.cc (get_option_html_page): Remove special-casing for analyzer and LTO. (get_option_url_suffix): New. (get_option_url): Reimplement. (selftest::test_get_option_html_page): Rename to... (selftest::test_get_option_url_suffix): ...this and update for above changes. (selftest::opts_cc_tests): Update for renaming. * opts.h: Include "rich-location.h". (get_option_url_suffix): New decl. gcc/testsuite/ChangeLog: * lib/gcc-dg.exp: Set TERM to xterm. gcc/ChangeLog: * toplev.cc (general_init): Pass lang_mask to urlifier. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/gcc-urlifier.cc')
-rw-r--r--gcc/gcc-urlifier.cc106
1 files changed, 87 insertions, 19 deletions
diff --git a/gcc/gcc-urlifier.cc b/gcc/gcc-urlifier.cc
index 877445c..6bd176f 100644
--- a/gcc/gcc-urlifier.cc
+++ b/gcc/gcc-urlifier.cc
@@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see
#include "pretty-print.h"
#include "pretty-print-urlifier.h"
#include "gcc-urlifier.h"
+#include "opts.h"
+#include "options.h"
#include "selftest.h"
namespace {
@@ -34,23 +36,34 @@ namespace {
class gcc_urlifier : public urlifier
{
public:
+ gcc_urlifier (unsigned int lang_mask)
+ : m_lang_mask (lang_mask)
+ {}
+
char *get_url_for_quoted_text (const char *p, size_t sz) const final override;
- const char *get_url_suffix_for_quoted_text (const char *p, size_t sz) const;
+ label_text get_url_suffix_for_quoted_text (const char *p, size_t sz) const;
/* We use ATTRIBUTE_UNUSED as this helper is called only from ASSERTs. */
- const char *get_url_suffix_for_quoted_text (const char *p) const ATTRIBUTE_UNUSED;
+ label_text get_url_suffix_for_quoted_text (const char *p) const ATTRIBUTE_UNUSED;
private:
+ label_text get_url_suffix_for_option (const char *p, size_t sz) const;
+
static char *
make_doc_url (const char *doc_url_suffix);
+
+ unsigned int m_lang_mask;
};
/* class gcc_urlifier : public urlifier. */
+/* Manage a hard-coded mapping from quoted string to URL suffixes
+ in gcc-urlifier.def */
+
#define DOC_URL(QUOTED_TEXT, URL_SUFFIX) \
{ (QUOTED_TEXT), (URL_SUFFIX) }
-const struct
+static const struct
{
const char *quoted_text;
const char *url_suffix;
@@ -60,32 +73,53 @@ const struct
};
+/* Implementation of urlifier::get_url_for_quoted_text vfunc for GCC
+ diagnostics. */
+
char *
gcc_urlifier::get_url_for_quoted_text (const char *p, size_t sz) const
{
- if (const char *url_suffix = get_url_suffix_for_quoted_text (p, sz))
- return make_doc_url (url_suffix);
+ label_text url_suffix = get_url_suffix_for_quoted_text (p, sz);
+ if (url_suffix.get ())
+ return make_doc_url (url_suffix.get ());
return nullptr;
}
-const char *
+/* Look for a URL for the quoted string (P, SZ).
+ Return the url suffix if found, or nullptr otherwise. */
+
+label_text
gcc_urlifier::get_url_suffix_for_quoted_text (const char *p, size_t sz) const
{
- /* Binary search. This assumes that the quoted_text fields of doc_urls
+ if (sz == 0)
+ return label_text ();
+
+ /* If this is an option, look up the option and see if we have
+ a URL for it. */
+ if (p[0] == '-')
+ {
+ label_text suffix = get_url_suffix_for_option (p, sz);
+ if (suffix.get ())
+ return suffix;
+ }
+
+ /* Otherwise, look within the hard-coded data table in gcc-urlifier.def.
+
+ Binary search. This assumes that the quoted_text fields of doc_urls
are in sorted order. */
int min = 0;
int max = ARRAY_SIZE (doc_urls) - 1;
while (true)
{
if (min > max)
- return nullptr;
+ return label_text ();
int midpoint = (min + max) / 2;
gcc_assert ((size_t)midpoint < ARRAY_SIZE (doc_urls));
int cmp = strncmp (p, doc_urls[midpoint].quoted_text, sz);
if (cmp == 0)
{
if (doc_urls[midpoint].quoted_text[sz] == '\0')
- return doc_urls[midpoint].url_suffix;
+ return label_text::borrow (doc_urls[midpoint].url_suffix);
else
max = midpoint - 1;
}
@@ -94,15 +128,45 @@ gcc_urlifier::get_url_suffix_for_quoted_text (const char *p, size_t sz) const
else
min = midpoint + 1;
}
- return nullptr;
+
+ /* Not found. */
+ return label_text ();
}
-const char *
+/* For use in selftests. */
+
+label_text
gcc_urlifier::get_url_suffix_for_quoted_text (const char *p) const
{
return get_url_suffix_for_quoted_text (p, strlen (p));
}
+/* Look for a URL for the quoted string (P, SZ) that appears to be
+ an option.
+ Return the url suffix if found, or nullptr otherwise. */
+
+label_text
+gcc_urlifier::get_url_suffix_for_option (const char *p, size_t sz) const
+{
+ /* Look up this option
+
+ find_opt does a binary search, taking a 0-terminated string,
+ and skipping the leading '-'.
+
+ We have a (pointer,size) pair that doesn't necessarily have a
+ terminator, so create a 0-terminated clone of the string. */
+ gcc_assert (sz > 0);
+ char *tmp = xstrndup (p + 1, sz - 1); // skip the leading '-'
+ size_t opt = find_opt (tmp, m_lang_mask);
+ free (tmp);
+
+ if (opt >= N_OPTS)
+ /* Option not recognized. */
+ return label_text ();
+
+ return get_option_url_suffix (opt, m_lang_mask);
+}
+
char *
gcc_urlifier::make_doc_url (const char *doc_url_suffix)
{
@@ -115,9 +179,9 @@ gcc_urlifier::make_doc_url (const char *doc_url_suffix)
} // anonymous namespace
urlifier *
-make_gcc_urlifier ()
+make_gcc_urlifier (unsigned int lang_mask)
{
- return new gcc_urlifier ();
+ return new gcc_urlifier (lang_mask);
}
#if CHECKING_P
@@ -137,22 +201,26 @@ gcc_urlifier_cc_tests ()
doc_urls[idx].quoted_text)
< 0);
- gcc_urlifier u;
+ gcc_urlifier u (0);
- ASSERT_EQ (u.get_url_suffix_for_quoted_text (""), nullptr);
- ASSERT_EQ (u.get_url_suffix_for_quoted_text (")"), nullptr);
+ ASSERT_EQ (u.get_url_suffix_for_quoted_text ("").get (), nullptr);
+ ASSERT_EQ (u.get_url_suffix_for_quoted_text (")").get (), nullptr);
- ASSERT_STREQ (u.get_url_suffix_for_quoted_text ("#pragma message"),
+ ASSERT_STREQ (u.get_url_suffix_for_quoted_text ("#pragma message").get (),
"gcc/Diagnostic-Pragmas.html");
// Incomplete prefix of a quoted_text
- ASSERT_EQ (u.get_url_suffix_for_quoted_text ("#pragma mess"), nullptr);
+ ASSERT_EQ (u.get_url_suffix_for_quoted_text ("#pragma mess").get (), nullptr);
/* Check that every element is findable. */
for (size_t idx = 0; idx < ARRAY_SIZE (doc_urls); idx++)
ASSERT_STREQ
- (u.get_url_suffix_for_quoted_text (doc_urls[idx].quoted_text),
+ (u.get_url_suffix_for_quoted_text (doc_urls[idx].quoted_text).get (),
doc_urls[idx].url_suffix);
+
+ /* Check an option. */
+ ASSERT_STREQ (u.get_url_suffix_for_quoted_text ("-fpack-struct").get (),
+ "gcc/Code-Gen-Options.html#index-fpack-struct");
}
} // namespace selftest