clang 10.0.0git

Classes | Functions
PPExpressions.cpp File Reference
`#include "clang/Lex/Preprocessor.h"`
`#include "clang/Basic/IdentifierTable.h"`
`#include "clang/Basic/SourceLocation.h"`
`#include "clang/Basic/SourceManager.h"`
`#include "clang/Basic/TargetInfo.h"`
`#include "clang/Basic/TokenKinds.h"`
`#include "clang/Lex/CodeCompletionHandler.h"`
`#include "clang/Lex/LexDiagnostic.h"`
`#include "clang/Lex/LiteralSupport.h"`
`#include "clang/Lex/MacroInfo.h"`
`#include "clang/Lex/PPCallbacks.h"`
`#include "clang/Lex/Token.h"`
`#include "llvm/ADT/APSInt.h"`
`#include "llvm/ADT/SmallString.h"`
`#include "llvm/ADT/StringRef.h"`
`#include "llvm/Support/ErrorHandling.h"`
`#include "llvm/Support/SaveAndRestore.h"`
`#include <cassert>`
Include dependency graph for PPExpressions.cpp:

Go to the source code of this file.

## Classes
struct | DefinedTracker
| DefinedTracker - This struct is used while parsing expressions to keep track of whether !defined(X) has been seen. More...

## Functions
static bool | EvaluateDirectiveSubExpr (PPValue &LHS, unsigned MinPrec, Token &PeekTok, bool ValueLive, bool &IncludedUndefinedIds, Preprocessor &PP)
| EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is PeekTok, and whose precedence is PeekPrec. More...
static bool | EvaluateDefined (PPValue &Result, Token &PeekTok, DefinedTracker &DT, bool ValueLive, Preprocessor &PP)
| EvaluateDefined - Process a 'defined(sym)' expression. More...
static bool | EvaluateValue (PPValue &Result, Token &PeekTok, DefinedTracker &DT, bool ValueLive, Preprocessor &PP)
| EvaluateValue - Evaluate the token PeekTok (and any others needed) and return the computed value in Result. More...
static unsigned | getPrecedence (tok::TokenKind Kind)
| getPrecedence - Return the precedence of the specified binary operator token. More...
static void | diagnoseUnexpectedOperator (Preprocessor &PP, PPValue &LHS, Token &Tok)

## Function Documentation

## ◆ diagnoseUnexpectedOperator()

static void diagnoseUnexpectedOperator | ( | Preprocessor & | PP,
|  | PPValue & | LHS,
|  | Token & | Tok
| ) |  |
| static

Definition at line 527 of file PPExpressions.cpp.

References clang::Preprocessor::Diag(), clang::Token::getLocation(), and clang::Token::is().

Referenced by EvaluateDirectiveSubExpr().

## ◆ EvaluateDefined()

static bool EvaluateDefined | ( | PPValue & | Result,
|  | Token & | PeekTok,
|  | DefinedTracker & | DT,
|  | bool | ValueLive,
|  | Preprocessor & | PP
| ) |  |
| static

EvaluateDefined - Process a 'defined(sym)' expression.

Definition at line 100 of file PPExpressions.cpp.

References clang::Preprocessor::CheckMacroName(), clang::CodeCompletionHandler::CodeCompleteMacroName(), DefinedTracker::DefinedMacro, clang::Preprocessor::Diag(), clang::Preprocessor::getCodeCompletionHandler(), clang::SourceManager::getFileID(), clang::Token::getIdentifierInfo(), clang::Token::getLocation(), clang::Preprocessor::getMacroDefinition(), clang::MacroDefinition::getMacroInfo(), clang::Preprocessor::getPPCallbacks(), clang::SourceManager::getSLocEntry(), clang::Preprocessor::getSourceManager(), DefinedTracker::IncludedUndefinedIds, clang::Token::is(), clang::Token::isNot(), clang::SourceLocation::isValid(), clang::Preprocessor::LexNonComment(), clang::Preprocessor::LexUnexpandedNonComment(), clang::Preprocessor::markMacroAsUsed(), clang::MU_Other, clang::Preprocessor::setCodeCompletionReached(), DefinedTracker::State, and DefinedTracker::TheMacro.

Referenced by EvaluateValue().

## ◆ EvaluateDirectiveSubExpr()

static bool EvaluateDirectiveSubExpr | ( | PPValue & | LHS,
|  | unsigned | MinPrec,
|  | Token & | PeekTok,
|  | bool | ValueLive,
|  | bool & | IncludedUndefinedIds,
|  | Preprocessor & | PP
| ) |  |
| static

EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is PeekTok, and whose precedence is PeekPrec.

This returns the result in LHS.

If ValueLive is false, then this value is being evaluated in a context where the result is not used. As such, avoid diagnostics that relate to evaluation, such as division by zero warnings.

Definition at line 543 of file PPExpressions.cpp.

References Diag(), clang::Preprocessor::Diag(), diagnoseUnexpectedOperator(), EvaluateValue(), clang::SourceRange::getEnd(), clang::Token::getKind(), clang::Preprocessor::getLangOpts(), clang::Token::getLocation(), getPrecedence(), DefinedTracker::IncludedUndefinedIds, clang::Token::is(), clang::Token::isNot(), clang::Preprocessor::LexNonComment(), DefinedTracker::NotDefinedMacro, DefinedTracker::State, DefinedTracker::TheMacro, and clang::format::Tok.

Referenced by EvaluateValue().

## ◆ EvaluateValue()

static bool EvaluateValue | ( | PPValue & | Result,
|  | Token & | PeekTok,
|  | DefinedTracker & | DT,
|  | bool | ValueLive,
|  | Preprocessor & | PP
| ) |  |
| static

EvaluateValue - Evaluate the token PeekTok (and any others needed) and return the computed value in Result.

Return true if there was an error parsing. This function also returns information about the form of the expression in DT. See above for information on what DT means.

If ValueLive is false, then this value is being evaluated in a context where the result is not used. As such, avoid diagnostics that relate to evaluation.

Definition at line 227 of file PPExpressions.cpp.

References clang::CodeCompletionHandler::CodeCompletePreprocessorExpression(), DefinedTracker::DefinedMacro, clang::Preprocessor::Diag(), EvaluateDefined(), EvaluateDirectiveSubExpr(), clang::TargetInfo::getChar16Width(), clang::TargetInfo::getChar32Width(), clang::TargetInfo::getCharWidth(), clang::Preprocessor::getCodeCompletionHandler(), clang::Token::getIdentifierInfo(), clang::TargetInfo::getIntWidth(), clang::Token::getKind(), clang::Preprocessor::getLangOpts(), clang::Token::getLocation(), clang::Preprocessor::getSpelling(), clang::Preprocessor::getTargetInfo(), clang::TargetInfo::getWCharType(), clang::TargetInfo::getWCharWidth(), clang::Token::hasUDSuffix(), DefinedTracker::IncludedUndefinedIds, clang::Token::is(), clang::IdentifierInfo::isCPlusPlusOperatorKeyword(), clang::Token::isNot(), clang::IdentifierInfo::isStr(), clang::TargetInfo::isTypeSigned(), clang::Preprocessor::LexNonComment(), DefinedTracker::NotDefinedMacro, clang::Preprocessor::setCodeCompletionReached(), DefinedTracker::State, and DefinedTracker::Unknown.

Referenced by EvaluateDirectiveSubExpr().

## ◆ getPrecedence()

static unsigned getPrecedence | ( | tok::TokenKind | Kind | ) |
| static

getPrecedence - Return the precedence of the specified binary operator token.

This returns: ~0 - Invalid token. 14 -> 3 - various operators. 0 - 'eod' or ')'

Definition at line 498 of file PPExpressions.cpp.

Referenced by EvaluateDirectiveSubExpr().