Vuo 2.4.4
Loading...
Searching...
No Matches
VuoReplaceGenericTypesWithSpecializedAction.hh
Go to the documentation of this file.
1
10#pragma once
11
12#include "clang/AST/ASTConsumer.h"
13#include "clang/AST/RecursiveASTVisitor.h"
14#include "clang/Rewrite/Core/Rewriter.h"
16
21class VuoReplaceGenericTypesWithSpecializedAction : public clang::ASTFrontendAction
22{
23public:
24 VuoReplaceGenericTypesWithSpecializedAction(raw_ostream &output, const map<string, string> &replacements, bool shouldReplaceGenericTypesInVuoTypeAnnotations, json_object *specializedModuleDetails, unique_ptr<VuoPreprocessorCallbacks> preprocessorCallbacks);
25 unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &compilerInstance, llvm::StringRef inFile);
26 bool BeginSourceFileAction(clang::CompilerInstance &CI);
28
29private:
30 raw_ostream &output;
31 map<string, string> replacements;
32 bool shouldReplaceGenericTypesInVuoTypeAnnotations;
33 json_object *specializedModuleDetails;
34 unique_ptr<VuoPreprocessorCallbacks> preprocessorCallbacks;
35 clang::Rewriter rewriter;
36
40 class Visitor : public clang::RecursiveASTVisitor<Visitor>
41 {
42 public:
43 Visitor(const map<string, string> &replacements, bool shouldReplaceGenericTypesInVuoTypeAnnotations, json_object *specializedModuleDetails, clang::Rewriter &rewriter);
44 bool VisitFunctionDecl(clang::FunctionDecl *decl);
45 bool VisitDeclRefExpr(clang::DeclRefExpr *expr);
46 bool VisitAnnotateAttr(clang::AnnotateAttr *attr);
47 bool VisitVarDecl(clang::VarDecl *decl);
48
49 private:
50 bool isInModuleSourceFile(clang::SourceRange sourceRange);
51 void replaceGenericTypeNamesInTypeSpecifier(clang::QualType qualType, clang::SourceRange sourceRange);
52 bool replaceGenericTypeNamesInIdentifier(string &identifier);
53 vector<string> orderedGenericTypeNames;
54 const map<string, string> replacements;
55 bool shouldReplaceGenericTypesInVuoTypeAnnotations;
56 json_object *specializedModuleDetails;
57 clang::Rewriter &rewriter;
58 };
59
63 class Consumer : public clang::ASTConsumer
64 {
65 public:
66 Consumer(const map<string, string> &replacements, bool shouldReplaceGenericTypesInVuoTypeAnnotations, json_object *specializedModuleDetails, clang::Rewriter &rewriter);
67 void HandleTranslationUnit(clang::ASTContext &context);
68
69 private:
70 Visitor visitor;
71 };
72};