">

clang: lib/Lex/PPExpressions.cpp File Reference (original) (raw)

#include "[clang/Basic/IdentifierTable.h](IdentifierTable%5F8h%5Fsource.html)"
#include "[clang/Basic/SourceLocation.h](SourceLocation%5F8h%5Fsource.html)"
#include "[clang/Basic/SourceManager.h](SourceManager%5F8h%5Fsource.html)"
#include "[clang/Basic/TargetInfo.h](include%5F2clang%5F2Basic%5F2TargetInfo%5F8h%5Fsource.html)"
#include "[clang/Basic/TokenKinds.h](TokenKinds%5F8h%5Fsource.html)"
#include "[clang/Lex/CodeCompletionHandler.h](CodeCompletionHandler%5F8h%5Fsource.html)"
#include "[clang/Lex/LexDiagnostic.h](LexDiagnostic%5F8h%5Fsource.html)"
#include "[clang/Lex/LiteralSupport.h](LiteralSupport%5F8h%5Fsource.html)"
#include "[clang/Lex/MacroInfo.h](MacroInfo%5F8h%5Fsource.html)"
#include "[clang/Lex/PPCallbacks.h](PPCallbacks%5F8h%5Fsource.html)"
#include "[clang/Lex/Preprocessor.h](Preprocessor%5F8h%5Fsource.html)"
#include "[clang/Lex/Token.h](Token%5F8h%5Fsource.html)"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SaveAndRestore.h"
#include <cassert>

Go to the source code of this file.

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.
static bool EvaluateDefined (PPValue &Result, Token &PeekTok, DefinedTracker &DT, bool ValueLive, Preprocessor &PP)
EvaluateDefined - Process a 'defined(sym)' expression.
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.
static unsigned getPrecedence (tok::TokenKind Kind)
getPrecedence - Return the precedence of the specified binary operator token.
static void diagnoseUnexpectedOperator (Preprocessor &PP, PPValue &LHS, Token &Tok)

diagnoseUnexpectedOperator()

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

EvaluateDefined()

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

Definition at line 101 of file PPExpressions.cpp.

References clang::Preprocessor::CheckMacroName(), clang::CodeCompletionHandler::CodeCompleteMacroName(), DefinedTracker::DefinedMacro, clang::Preprocessor::Diag(), clang::Preprocessor::emitMacroExpansionWarnings(), clang::Preprocessor::getCodeCompletionHandler(), clang::SrcMgr::SLocEntry::getExpansion(), clang::SourceManager::getFileID(), clang::Token::getIdentifierInfo(), clang::Token::getLocation(), clang::Preprocessor::getMacroDefinition(), clang::IdentifierInfo::getName(), clang::Preprocessor::getPPCallbacks(), clang::SourceManager::getSLocEntry(), clang::Preprocessor::getSourceManager(), DefinedTracker::IncludedUndefinedIds, clang::Token::is(), clang::SrcMgr::ExpansionInfo::isFunctionMacroExpansion(), clang::SourceLocation::isMacroID(), 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()

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 591 of file PPExpressions.cpp.

References clang::Preprocessor::Diag(), diagnoseUnexpectedOperator(), EvaluateDirectiveSubExpr(), EvaluateValue(), clang::Token::getKind(), clang::Preprocessor::getLangOpts(), clang::Token::getLocation(), getPrecedence(), DefinedTracker::IncludedUndefinedIds, clang::Token::isNot(), clang::Preprocessor::LexNonComment(), and toString().

Referenced by EvaluateDirectiveSubExpr(), and EvaluateValue().

EvaluateValue()

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 232 of file PPExpressions.cpp.

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

Referenced by EvaluateDirectiveSubExpr(), and EvaluateValue().

getPrecedence()

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 546 of file PPExpressions.cpp.

Referenced by EvaluateDirectiveSubExpr().