clang 20.0.0git
Functions
Diagnostic.cpp File Reference
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DiagnosticError.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Unicode.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

static void DummyArgToStringFn (DiagnosticsEngine::ArgumentKind AK, intptr_t QT, StringRef Modifier, StringRef Argument, ArrayRef< DiagnosticsEngine::ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, void *Cookie, ArrayRef< intptr_t > QualTypeVals)
 
template<std::size_t StrLen>
static bool ModifierIs (const char *Modifier, unsigned ModifierLen, const char(&Str)[StrLen])
 ModifierIs - Return true if the specified modifier matches specified string.
 
static const char * ScanFormat (const char *I, const char *E, char Target)
 ScanForward - Scans forward, looking for the given character, skipping nested clauses and escaped characters.
 
static void HandleSelectModifier (const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
 HandleSelectModifier - Handle the integer 'select' modifier.
 
static void HandleIntegerSModifier (unsigned ValNo, SmallVectorImpl< char > &OutStr)
 HandleIntegerSModifier - Handle the integer 's' modifier.
 
static void HandleOrdinalModifier (unsigned ValNo, SmallVectorImpl< char > &OutStr)
 HandleOrdinalModifier - Handle the integer 'ord' modifier.
 
static unsigned PluralNumber (const char *&Start, const char *End)
 PluralNumber - Parse an unsigned integer and advance Start.
 
static bool TestPluralRange (unsigned Val, const char *&Start, const char *End)
 TestPluralRange - Test if Val is in the parsed range. Modifies Start.
 
static bool EvalPluralExpr (unsigned ValNo, const char *Start, const char *End)
 EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
 
static void HandlePluralModifier (const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
 HandlePluralModifier - Handle the integer 'plural' modifier.
 
static const char * getTokenDescForDiagnostic (tok::TokenKind Kind)
 Returns the friendly description for a token kind that will appear without quotes in diagnostic messages.
 

Function Documentation

◆ DummyArgToStringFn()

static void DummyArgToStringFn ( DiagnosticsEngine::ArgumentKind  AK,
intptr_t  QT,
StringRef  Modifier,
StringRef  Argument,
ArrayRef< DiagnosticsEngine::ArgumentValue PrevArgs,
SmallVectorImpl< char > &  Output,
void *  Cookie,
ArrayRef< intptr_t QualTypeVals 
)
static

Definition at line 61 of file Diagnostic.cpp.

Referenced by clang::DiagnosticsEngine::DiagnosticsEngine().

◆ EvalPluralExpr()

static bool EvalPluralExpr ( unsigned  ValNo,
const char *  Start,
const char *  End 
)
static

EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.

Definition at line 686 of file Diagnostic.cpp.

References clang::C, PluralNumber(), and TestPluralRange().

Referenced by HandlePluralModifier().

◆ getTokenDescForDiagnostic()

static const char * getTokenDescForDiagnostic ( tok::TokenKind  Kind)
static

Returns the friendly description for a token kind that will appear without quotes in diagnostic messages.

These strings may be translatable in future.

Definition at line 779 of file Diagnostic.cpp.

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ HandleIntegerSModifier()

static void HandleIntegerSModifier ( unsigned  ValNo,
SmallVectorImpl< char > &  OutStr 
)
static

HandleIntegerSModifier - Handle the integer 's' modifier.

This adds the letter 's' to the string if the value is not 1. This is used in cases like this: "you idiot, you have %4 parameter%s4!".

Definition at line 635 of file Diagnostic.cpp.

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ HandleOrdinalModifier()

static void HandleOrdinalModifier ( unsigned  ValNo,
SmallVectorImpl< char > &  OutStr 
)
static

HandleOrdinalModifier - Handle the integer 'ord' modifier.

This prints the ordinal form of the given integer, with 1 corresponding to the first ordinal. Currently this is hard-coded to use the English form.

Definition at line 645 of file Diagnostic.cpp.

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ HandlePluralModifier()

static void HandlePluralModifier ( const Diagnostic DInfo,
unsigned  ValNo,
const char *  Argument,
unsigned  ArgumentLen,
SmallVectorImpl< char > &  OutStr 
)
static

HandlePluralModifier - Handle the integer 'plural' modifier.

This is used for complex plural forms, or in languages where all plurals are complex. The syntax is: plural{cond1:form1|cond2:form2|:form3}, where condn are conditions that are tested in order, the form corresponding to the first that applies being emitted. The empty condition is always true, making the last form a default case. Conditions are simple boolean expressions, where n is the number argument. Here are the rules. condition := expression | empty empty := -> always true expression := numeric [',' expression] -> logical or numeric := range -> true if n in range | '' number '=' range -> true if n % number in range range := number | '[' number ',' number ']' -> ranges are inclusive both ends

Here are some examples from the GNU gettext manual written in this form: English: {1:form0|:form1} Latvian: {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0} Gaeilge: {1:form0|2:form1|:form2} Romanian: {1:form0|0,%100=[1,19]:form1|:form2} Lithuanian: {%10=0,%100=[10,19]:form2|%10=1:form0|:form1} Russian (requires repeated form): {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2} Slovak {1:form0|[2,4]:form1|:form2} Polish (requires repeated form): {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}

Definition at line 752 of file Diagnostic.cpp.

References EvalPluralExpr(), clang::Diagnostic::FormatDiagnostic(), and ScanFormat().

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ HandleSelectModifier()

static void HandleSelectModifier ( const Diagnostic DInfo,
unsigned  ValNo,
const char *  Argument,
unsigned  ArgumentLen,
SmallVectorImpl< char > &  OutStr 
)
static

HandleSelectModifier - Handle the integer 'select' modifier.

This is used like this: select{foo|bar|baz}2. This means that the integer argument "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. This is very useful for certain classes of variant diagnostics.

Definition at line 611 of file Diagnostic.cpp.

References clang::Diagnostic::FormatDiagnostic(), and ScanFormat().

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ ModifierIs()

template<std::size_t StrLen>
static bool ModifierIs ( const char *  Modifier,
unsigned  ModifierLen,
const char(&)  Str[StrLen] 
)
static

ModifierIs - Return true if the specified modifier matches specified string.

Definition at line 574 of file Diagnostic.cpp.

Referenced by clang::Diagnostic::FormatDiagnostic().

◆ PluralNumber()

static unsigned PluralNumber ( const char *&  Start,
const char *  End 
)
static

PluralNumber - Parse an unsigned integer and advance Start.

Definition at line 657 of file Diagnostic.cpp.

Referenced by EvalPluralExpr(), and TestPluralRange().

◆ ScanFormat()

static const char * ScanFormat ( const char *  I,
const char *  E,
char  Target 
)
static

ScanForward - Scans forward, looking for the given character, skipping nested clauses and escaped characters.

Definition at line 581 of file Diagnostic.cpp.

References E, clang::isDigit(), and clang::isPunctuation().

Referenced by clang::Diagnostic::FormatDiagnostic(), HandlePluralModifier(), and HandleSelectModifier().

◆ TestPluralRange()

static bool TestPluralRange ( unsigned  Val,
const char *&  Start,
const char *  End 
)
static

TestPluralRange - Test if Val is in the parsed range. Modifies Start.

Definition at line 669 of file Diagnostic.cpp.

References PluralNumber().

Referenced by EvalPluralExpr().