Path: blob/main/contrib/llvm-project/clang/include/clang-c/CXDiagnostic.h
35233 views
/*===-- clang-c/CXDiagnostic.h - C Index Diagnostics --------------*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header provides the interface to C Index diagnostics. *|10|* *|11\*===----------------------------------------------------------------------===*/1213#ifndef LLVM_CLANG_C_CXDIAGNOSTIC_H14#define LLVM_CLANG_C_CXDIAGNOSTIC_H1516#include "clang-c/CXSourceLocation.h"17#include "clang-c/CXString.h"18#include "clang-c/ExternC.h"19#include "clang-c/Platform.h"2021LLVM_CLANG_C_EXTERN_C_BEGIN2223/**24* \defgroup CINDEX_DIAG Diagnostic reporting25*26* @{27*/2829/**30* Describes the severity of a particular diagnostic.31*/32enum CXDiagnosticSeverity {33/**34* A diagnostic that has been suppressed, e.g., by a command-line35* option.36*/37CXDiagnostic_Ignored = 0,3839/**40* This diagnostic is a note that should be attached to the41* previous (non-note) diagnostic.42*/43CXDiagnostic_Note = 1,4445/**46* This diagnostic indicates suspicious code that may not be47* wrong.48*/49CXDiagnostic_Warning = 2,5051/**52* This diagnostic indicates that the code is ill-formed.53*/54CXDiagnostic_Error = 3,5556/**57* This diagnostic indicates that the code is ill-formed such58* that future parser recovery is unlikely to produce useful59* results.60*/61CXDiagnostic_Fatal = 462};6364/**65* A single diagnostic, containing the diagnostic's severity,66* location, text, source ranges, and fix-it hints.67*/68typedef void *CXDiagnostic;6970/**71* A group of CXDiagnostics.72*/73typedef void *CXDiagnosticSet;7475/**76* Determine the number of diagnostics in a CXDiagnosticSet.77*/78CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);7980/**81* Retrieve a diagnostic associated with the given CXDiagnosticSet.82*83* \param Diags the CXDiagnosticSet to query.84* \param Index the zero-based diagnostic number to retrieve.85*86* \returns the requested diagnostic. This diagnostic must be freed87* via a call to \c clang_disposeDiagnostic().88*/89CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,90unsigned Index);9192/**93* Describes the kind of error that occurred (if any) in a call to94* \c clang_loadDiagnostics.95*/96enum CXLoadDiag_Error {97/**98* Indicates that no error occurred.99*/100CXLoadDiag_None = 0,101102/**103* Indicates that an unknown error occurred while attempting to104* deserialize diagnostics.105*/106CXLoadDiag_Unknown = 1,107108/**109* Indicates that the file containing the serialized diagnostics110* could not be opened.111*/112CXLoadDiag_CannotLoad = 2,113114/**115* Indicates that the serialized diagnostics file is invalid or116* corrupt.117*/118CXLoadDiag_InvalidFile = 3119};120121/**122* Deserialize a set of diagnostics from a Clang diagnostics bitcode123* file.124*125* \param file The name of the file to deserialize.126* \param error A pointer to a enum value recording if there was a problem127* deserializing the diagnostics.128* \param errorString A pointer to a CXString for recording the error string129* if the file was not successfully loaded.130*131* \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These132* diagnostics should be released using clang_disposeDiagnosticSet().133*/134CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(135const char *file, enum CXLoadDiag_Error *error, CXString *errorString);136137/**138* Release a CXDiagnosticSet and all of its contained diagnostics.139*/140CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);141142/**143* Retrieve the child diagnostics of a CXDiagnostic.144*145* This CXDiagnosticSet does not need to be released by146* clang_disposeDiagnosticSet.147*/148CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);149150/**151* Destroy a diagnostic.152*/153CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);154155/**156* Options to control the display of diagnostics.157*158* The values in this enum are meant to be combined to customize the159* behavior of \c clang_formatDiagnostic().160*/161enum CXDiagnosticDisplayOptions {162/**163* Display the source-location information where the164* diagnostic was located.165*166* When set, diagnostics will be prefixed by the file, line, and167* (optionally) column to which the diagnostic refers. For example,168*169* \code170* test.c:28: warning: extra tokens at end of #endif directive171* \endcode172*173* This option corresponds to the clang flag \c -fshow-source-location.174*/175CXDiagnostic_DisplaySourceLocation = 0x01,176177/**178* If displaying the source-location information of the179* diagnostic, also include the column number.180*181* This option corresponds to the clang flag \c -fshow-column.182*/183CXDiagnostic_DisplayColumn = 0x02,184185/**186* If displaying the source-location information of the187* diagnostic, also include information about source ranges in a188* machine-parsable format.189*190* This option corresponds to the clang flag191* \c -fdiagnostics-print-source-range-info.192*/193CXDiagnostic_DisplaySourceRanges = 0x04,194195/**196* Display the option name associated with this diagnostic, if any.197*198* The option name displayed (e.g., -Wconversion) will be placed in brackets199* after the diagnostic text. This option corresponds to the clang flag200* \c -fdiagnostics-show-option.201*/202CXDiagnostic_DisplayOption = 0x08,203204/**205* Display the category number associated with this diagnostic, if any.206*207* The category number is displayed within brackets after the diagnostic text.208* This option corresponds to the clang flag209* \c -fdiagnostics-show-category=id.210*/211CXDiagnostic_DisplayCategoryId = 0x10,212213/**214* Display the category name associated with this diagnostic, if any.215*216* The category name is displayed within brackets after the diagnostic text.217* This option corresponds to the clang flag218* \c -fdiagnostics-show-category=name.219*/220CXDiagnostic_DisplayCategoryName = 0x20221};222223/**224* Format the given diagnostic in a manner that is suitable for display.225*226* This routine will format the given diagnostic to a string, rendering227* the diagnostic according to the various options given. The228* \c clang_defaultDiagnosticDisplayOptions() function returns the set of229* options that most closely mimics the behavior of the clang compiler.230*231* \param Diagnostic The diagnostic to print.232*233* \param Options A set of options that control the diagnostic display,234* created by combining \c CXDiagnosticDisplayOptions values.235*236* \returns A new string containing for formatted diagnostic.237*/238CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,239unsigned Options);240241/**242* Retrieve the set of display options most similar to the243* default behavior of the clang compiler.244*245* \returns A set of display options suitable for use with \c246* clang_formatDiagnostic().247*/248CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);249250/**251* Determine the severity of the given diagnostic.252*/253CINDEX_LINKAGE enum CXDiagnosticSeverity254clang_getDiagnosticSeverity(CXDiagnostic);255256/**257* Retrieve the source location of the given diagnostic.258*259* This location is where Clang would print the caret ('^') when260* displaying the diagnostic on the command line.261*/262CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);263264/**265* Retrieve the text of the given diagnostic.266*/267CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);268269/**270* Retrieve the name of the command-line option that enabled this271* diagnostic.272*273* \param Diag The diagnostic to be queried.274*275* \param Disable If non-NULL, will be set to the option that disables this276* diagnostic (if any).277*278* \returns A string that contains the command-line option used to enable this279* warning, such as "-Wconversion" or "-pedantic".280*/281CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,282CXString *Disable);283284/**285* Retrieve the category number for this diagnostic.286*287* Diagnostics can be categorized into groups along with other, related288* diagnostics (e.g., diagnostics under the same warning flag). This routine289* retrieves the category number for the given diagnostic.290*291* \returns The number of the category that contains this diagnostic, or zero292* if this diagnostic is uncategorized.293*/294CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);295296/**297* Retrieve the name of a particular diagnostic category. This298* is now deprecated. Use clang_getDiagnosticCategoryText()299* instead.300*301* \param Category A diagnostic category number, as returned by302* \c clang_getDiagnosticCategory().303*304* \returns The name of the given diagnostic category.305*/306CINDEX_DEPRECATED CINDEX_LINKAGE CXString307clang_getDiagnosticCategoryName(unsigned Category);308309/**310* Retrieve the diagnostic category text for a given diagnostic.311*312* \returns The text of the given diagnostic category.313*/314CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);315316/**317* Determine the number of source ranges associated with the given318* diagnostic.319*/320CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);321322/**323* Retrieve a source range associated with the diagnostic.324*325* A diagnostic's source ranges highlight important elements in the source326* code. On the command line, Clang displays source ranges by327* underlining them with '~' characters.328*329* \param Diagnostic the diagnostic whose range is being extracted.330*331* \param Range the zero-based index specifying which range to332*333* \returns the requested source range.334*/335CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,336unsigned Range);337338/**339* Determine the number of fix-it hints associated with the340* given diagnostic.341*/342CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);343344/**345* Retrieve the replacement information for a given fix-it.346*347* Fix-its are described in terms of a source range whose contents348* should be replaced by a string. This approach generalizes over349* three kinds of operations: removal of source code (the range covers350* the code to be removed and the replacement string is empty),351* replacement of source code (the range covers the code to be352* replaced and the replacement string provides the new code), and353* insertion (both the start and end of the range point at the354* insertion location, and the replacement string provides the text to355* insert).356*357* \param Diagnostic The diagnostic whose fix-its are being queried.358*359* \param FixIt The zero-based index of the fix-it.360*361* \param ReplacementRange The source range whose contents will be362* replaced with the returned replacement string. Note that source363* ranges are half-open ranges [a, b), so the source code should be364* replaced from a and up to (but not including) b.365*366* \returns A string containing text that should be replace the source367* code indicated by the \c ReplacementRange.368*/369CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(370CXDiagnostic Diagnostic, unsigned FixIt, CXSourceRange *ReplacementRange);371372/**373* @}374*/375376LLVM_CLANG_C_EXTERN_C_END377378#endif379380381