Skip to content

Commit

Permalink
[SYCLomatic][NFC] Move pre-processor code into seperate PreProcessor.…
Browse files Browse the repository at this point in the history
…cpp/h files. (#2474)
  • Loading branch information
zhimingwang36 authored Nov 11, 2024
1 parent 94743d2 commit 6b7b5a9
Show file tree
Hide file tree
Showing 7 changed files with 907 additions and 845 deletions.
786 changes: 0 additions & 786 deletions clang/lib/DPCT/ASTTraversal.cpp

Large diffs are not rendered by default.

58 changes: 0 additions & 58 deletions clang/lib/DPCT/ASTTraversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,64 +32,6 @@ namespace dpct {

enum class PassKind : unsigned { PK_Analysis = 0, PK_Migration, PK_End };

/// Migration rules at the pre-processing stages, e.g. macro rewriting and
/// including directives rewriting.
class IncludesCallbacks : public PPCallbacks {
TransformSetTy &TransformSet;
SourceManager &SM;
RuleGroups &Groups;

std::unordered_set<std::string> SeenFiles;
bool IsFileInCmd = true;

public:
IncludesCallbacks(TransformSetTy &TransformSet, SourceManager &SM,
RuleGroups &G)
: TransformSet(TransformSet), SM(SM), Groups(G) {}
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *SuggestedModule,
bool ModuleImported,
SrcMgr::CharacteristicKind FileType) override;
/// Hook called whenever a macro definition is seen.
void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) override;
void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range, const MacroArgs *Args) override;
void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override;
void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override;
// TODO: implement one of this for each source language.
bool ReplaceCuMacro(const Token &MacroNameTok, MacroInfo *MI = nullptr);
void ReplaceCuMacro(SourceRange ConditionRange, IfType IT,
SourceLocation IfLoc, SourceLocation ElifLoc);
void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range) override;
void Endif(SourceLocation Loc, SourceLocation IfLoc) override;
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID = FileID()) override;
void If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) override;
void Else(SourceLocation Loc, SourceLocation IfLoc) override;
void Elif(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue, SourceLocation IfLoc) override;
bool ShouldEnter(StringRef FileName, bool IsAngled) override;
bool isInAnalysisScope(SourceLocation Loc);
// Find the "#" before a preprocessing directive, return -1 if have some false
int findPoundSign(SourceLocation DirectiveStart);
void insertCudaArchRepl(std::shared_ptr<clang::dpct::ExtReplacement> Repl);

private:
/// e.g. "__launch_bounds(32, 32) void foo()"
/// Result is "void foo()"
std::shared_ptr<TextModification>
removeMacroInvocationAndTrailingSpaces(SourceRange Range);
};

/// Base class for all tool-related AST traversals.
class ASTTraversal : public ast_matchers::MatchFinder::MatchCallback {
public:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/DPCT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ add_subdirectory(RulesSecurity/ConfusableTable)

add_clang_library(DPCT
ASTTraversal.cpp
PreProcessor.cpp
AnalysisInfo.cpp
RulesLangLib/CUB/CallExprRewriterCUB.cpp
RulesLangLib/CUB/RewriterClassMethods.cpp
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/DPCT/MigrationAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"

#include "PreProcessor.h"
#include "ASTTraversal.h"

#include "RulesSecurity/MisleadingBidirectional.h"

namespace clang {
Expand Down
Loading

0 comments on commit 6b7b5a9

Please sign in to comment.