aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc-urlifier.h
blob: 1262bf5c190fee9e79c55a594baf66abae6ca665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Automatic generation of links into GCC's documentation.
   Copyright (C) 2023-2024 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#ifndef GCC_GCC_URLIFIER_H
#define GCC_GCC_URLIFIER_H

#include "pretty-print-urlifier.h"
#include "label-text.h"

extern std::unique_ptr<urlifier> make_gcc_urlifier (unsigned int lang_mask);
extern char *make_doc_url (const char *doc_url_suffix);

/* RAII class to temporarily override global_dc's urlifier
   with another one (possibly nullptr).  */

class auto_override_urlifier
{
public:
  auto_override_urlifier (urlifier *new_urlifier);
  ~auto_override_urlifier ();

protected:
  urlifier * const m_old_urlifier;
};

/* Subclass of urlifier that attempts to add URLs to quoted strings
   containing names of attributes.  */

class attribute_urlifier : public urlifier
{
public:
  attribute_urlifier ();
  attribute_urlifier (const char *target_docs_name);

  char *
  get_url_for_quoted_text (const char *p, size_t sz) const final override;

  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.  */
  label_text
  get_url_suffix_for_quoted_text (const char *p) const ATTRIBUTE_UNUSED;

private:
  const char *m_target_docs_name;
};

/* RAII class: during the lifetime of instances, global_dc will attempt
   to auto-generate documentation links for any attributes mentioned in
   quotes in diagnostics .  */

class auto_urlify_attributes
{
public:
  auto_urlify_attributes ()
  : m_override (&m_urlifier)
  {
  }

private:
  attribute_urlifier m_urlifier;
  auto_override_urlifier m_override;
};

#endif /* GCC_GCC_URLIFIER_H */