clang  6.0.0svn
Functions
Diagnostic.cpp File Reference
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DiagnosticError.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Locale.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for Diagnostic.cpp:

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. More...
 
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. More...
 
static void HandleSelectModifier (const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
 HandleSelectModifier - Handle the integer 'select' modifier. More...
 
static void HandleIntegerSModifier (unsigned ValNo, SmallVectorImpl< char > &OutStr)
 HandleIntegerSModifier - Handle the integer 's' modifier. More...
 
static void HandleOrdinalModifier (unsigned ValNo, SmallVectorImpl< char > &OutStr)
 HandleOrdinalModifier - Handle the integer 'ord' modifier. More...
 
static unsigned PluralNumber (const char *&Start, const char *End)
 PluralNumber - Parse an unsigned integer and advance Start. More...
 
static bool TestPluralRange (unsigned Val, const char *&Start, const char *End)
 TestPluralRange - Test if Val is in the parsed range. Modifies Start. More...
 
static bool EvalPluralExpr (unsigned ValNo, const char *Start, const char *End)
 EvalPluralExpr - Actual expression evaluator for HandlePluralModifier. More...
 
static void HandlePluralModifier (const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
 HandlePluralModifier - Handle the integer 'plural' modifier. More...
 
static const char * getTokenDescForDiagnostic (tok::TokenKind Kind)
 Returns the friendly description for a token kind that will appear without quotes in diagnostic messages. More...
 

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 50 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 561 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 654 of file Diagnostic.cpp.

References 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 509 of file Diagnostic.cpp.

◆ 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 519 of file Diagnostic.cpp.

◆ 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 627 of file Diagnostic.cpp.

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

◆ 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 485 of file Diagnostic.cpp.

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

◆ 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 448 of file Diagnostic.cpp.

◆ PluralNumber()

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

PluralNumber - Parse an unsigned integer and advance Start.

Definition at line 532 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 455 of file Diagnostic.cpp.

Referenced by 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 544 of file Diagnostic.cpp.

References PluralNumber().

Referenced by EvalPluralExpr().