brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 35f20ee Raw
87 lines · c
1//===- PreprocessorTracker.h - Tracks preprocessor activities -*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===--------------------------------------------------------------------===//8///9/// \file10/// Macro expansions and preprocessor conditional consistency checker.11///12//===--------------------------------------------------------------------===//13 14#ifndef MODULARIZE_PREPROCESSOR_TRACKER_H15#define MODULARIZE_PREPROCESSOR_TRACKER_H16 17#include "clang/Lex/Preprocessor.h"18 19namespace Modularize {20 21/// Preprocessor tracker for modularize.22///23/// The PreprocessorTracker class defines an API for24/// checking macro expansions and preprocessor conditional expressions25/// in a header file for consistency among one or more compilations of26/// the header in a #include scenario.  This is for helping a user27/// find which macro expansions or conditionals might be problematic with28/// respect to using the headers in the modules scenario, because they29/// evaluate to different values depending on how or where a header30/// is included.31///32/// The handlePreprocessorEntry function implementation will register33/// a PPCallbacks object in the given Preprocessor object.  The calls to34/// the callbacks will collect information about the macro expansions35/// and preprocessor conditionals encountered, for later analysis and36/// reporting of inconsistencies between runs performed by calls to37/// the reportInconsistentMacros and reportInconsistentConditionals38/// functions respectively.  The handlePreprocessorExit informs the39/// implementation that a preprocessing session is complete, allowing40/// it to do any needed compilation completion activities in the checker.41class PreprocessorTracker {42public:43  virtual ~PreprocessorTracker();44 45  // Handle entering a preprocessing session.46  // (Called after a Preprocessor object is created, but before preprocessing.)47  virtual void handlePreprocessorEntry(clang::Preprocessor &PP,48                                       llvm::StringRef RootHeaderFile) = 0;49  // Handle exiting a preprocessing session.50  // (Called after preprocessing is complete, but before the Preprocessor51  // object is destroyed.)52  virtual void handlePreprocessorExit() = 0;53 54  // Handle include directive.55  // This function is called every time an include directive is seen by the56  // preprocessor, for the purpose of later checking for 'extern "" {}' or57  // "namespace {}" blocks containing #include directives.58  virtual void handleIncludeDirective(llvm::StringRef DirectivePath,59                                      int DirectiveLine, int DirectiveColumn,60                                      llvm::StringRef TargetPath) = 0;61 62  // Check for include directives within the given source line range.63  // Report errors if any found.  Returns true if no include directives64  // found in block.65  virtual bool checkForIncludesInBlock(clang::Preprocessor &PP,66                                       clang::SourceRange BlockSourceRange,67                                       const char *BlockIdentifierMessage,68                                       llvm::raw_ostream &OS) = 0;69 70  // Report on inconsistent macro instances.71  // Returns true if any mismatches.72  virtual bool reportInconsistentMacros(llvm::raw_ostream &OS) = 0;73 74  // Report on inconsistent conditional directive instances.75  // Returns true if any mismatches.76  virtual bool reportInconsistentConditionals(llvm::raw_ostream &OS) = 0;77 78  // Create instance of PreprocessorTracker.79  static PreprocessorTracker *create(80    llvm::SmallVector<std::string, 32> &Headers,81    bool DoBlockCheckHeaderListOnly);82};83 84} // end namespace Modularize85 86#endif87