diff --git a/src/Compiler/Command.cpp b/src/Compiler/Command.cpp index bdbdaf82..454f4b09 100644 --- a/src/Compiler/Command.cpp +++ b/src/Compiler/Command.cpp @@ -300,13 +300,13 @@ auto CompilationDatabase::query_driver(this Self& self, llvm::StringRef driver) #endif std::string message; - if(int RC = llvm::sys::ExecuteAndWait(driver, - argv, - env, - redirects, - /*SecondsToWait=*/0, - /*MemoryLimit=*/0, - &message)) { + if(int ret_code = llvm::sys::ExecuteAndWait(driver, + argv, + env, + redirects, + /*SecondsToWait=*/0, + /*MemoryLimit=*/0, + &message)) { return unexpected(ErrorKind::InvokeDriverFail, std::move(message)); } @@ -317,9 +317,9 @@ auto CompilationDatabase::query_driver(this Self& self, llvm::StringRef driver) llvm::StringRef content = file.get()->getBuffer(); - const char* TS = "Target: "; - const char* SIS = "#include <...> search starts here:"; - const char* SIE = "End of search list."; + const char* ts = "Target: "; + const char* sis = "#include <...> search starts here:"; + const char* sie = "End of search list."; llvm::SmallVector lines; content.split(lines, '\n', -1, false); @@ -333,19 +333,19 @@ auto CompilationDatabase::query_driver(this Self& self, llvm::StringRef driver) for(const auto& line_ref: lines) { auto line = line_ref.trim(); - if(line.starts_with(TS)) { - line.consume_front(TS); + if(line.starts_with(ts)) { + line.consume_front(ts); target = line; continue; } - if(line == SIS) { + if(line == sis) { found_start_marker = true; in_includes_block = true; continue; } - if(line == SIE) { + if(line == sie) { if(in_includes_block) { in_includes_block = false; } diff --git a/src/Compiler/Compilation.cpp b/src/Compiler/Compilation.cpp index 04ea3b35..34bc016b 100644 --- a/src/Compiler/Compilation.cpp +++ b/src/Compiler/Compilation.cpp @@ -141,9 +141,9 @@ auto create_invocation(CompilationParams& params, auto& front_opts = invocation->getFrontendOpts(); front_opts.DisableFree = false; - clang::LangOptions& langOpts = invocation->getLangOpts(); - langOpts.CommentOpts.ParseAllComments = true; - langOpts.RetainCommentsFromSystemHeaders = true; + clang::LangOptions& lang_opts = invocation->getLangOpts(); + lang_opts.CommentOpts.ParseAllComments = true; + lang_opts.RetainCommentsFromSystemHeaders = true; return invocation; } diff --git a/src/Compiler/CompilationUnit.cpp b/src/Compiler/CompilationUnit.cpp index 25a315c1..1cbf2ad1 100644 --- a/src/Compiler/CompilationUnit.cpp +++ b/src/Compiler/CompilationUnit.cpp @@ -246,9 +246,9 @@ std::vector CompilationUnit::deps() { } } - for(auto& hasInclude: diretive.has_includes) { - if(hasInclude.fid.isValid()) { - deps.try_emplace(file_path(hasInclude.fid)); + for(auto& has_include: diretive.has_includes) { + if(has_include.fid.isValid()) { + deps.try_emplace(file_path(has_include.fid)); } } } @@ -268,9 +268,9 @@ index::SymbolID CompilationUnit::getSymbolID(const clang::NamedDecl* decl) { if(iter != impl->symbol_hash_cache.end()) { hash = iter->second; } else { - llvm::SmallString<128> USR; - index::generateUSRForDecl(decl, USR); - hash = llvm::xxh3_64bits(USR); + llvm::SmallString<128> usr; + index::generateUSRForDecl(decl, usr); + hash = llvm::xxh3_64bits(usr); impl->symbol_hash_cache.try_emplace(decl, hash); } return index::SymbolID{hash, ast::name_of(decl)}; @@ -283,9 +283,9 @@ index::SymbolID CompilationUnit::getSymbolID(const clang::MacroInfo* macro) { if(iter != impl->symbol_hash_cache.end()) { hash = iter->second; } else { - llvm::SmallString<128> USR; - index::generateUSRForMacro(name, macro->getDefinitionLoc(), impl->src_mgr, USR); - hash = llvm::xxh3_64bits(USR); + llvm::SmallString<128> usr; + index::generateUSRForMacro(name, macro->getDefinitionLoc(), impl->src_mgr, usr); + hash = llvm::xxh3_64bits(usr); impl->symbol_hash_cache.try_emplace(macro, hash); } return index::SymbolID{hash, name.str()}; diff --git a/src/Compiler/Diagnostic.cpp b/src/Compiler/Diagnostic.cpp index 9dd39f62..ee85a1cc 100644 --- a/src/Compiler/Diagnostic.cpp +++ b/src/Compiler/Diagnostic.cpp @@ -205,9 +205,9 @@ public: DiagnosticCollectorImpl(std::shared_ptr> diagnostics) : diagnostics(diagnostics) {} - void BeginSourceFile(const clang::LangOptions& Opts, const clang::Preprocessor* PP) override { - options = &Opts; - src_mgr = &PP->getSourceManager(); + void BeginSourceFile(const clang::LangOptions& opts, const clang::Preprocessor* pp) override { + options = &opts; + src_mgr = &pp->getSourceManager(); } void HandleDiagnostic(clang::DiagnosticsEngine::Level level, diff --git a/src/Compiler/Directive.cpp b/src/Compiler/Directive.cpp index cfe55eac..688a21c7 100644 --- a/src/Compiler/Directive.cpp +++ b/src/Compiler/Directive.cpp @@ -9,29 +9,29 @@ namespace { class DirectiveCollector : public clang::PPCallbacks { public: - DirectiveCollector(clang::Preprocessor& PP, + DirectiveCollector(clang::Preprocessor& pp, llvm::DenseMap& directives) : - PP(PP), SM(PP.getSourceManager()), directives(directives) {} + pp(pp), sm(pp.getSourceManager()), directives(directives) {} private: void add_condition(clang::SourceLocation location, Condition::BranchKind kind, Condition::ConditionValue value, clang::SourceRange cond_range) { - auto& directive = directives[SM.getFileID(location)]; + auto& directive = directives[sm.getFileID(location)]; directive.conditions.emplace_back(kind, value, location, cond_range); } void add_condition(clang::SourceLocation loc, Condition::BranchKind kind, clang::PPCallbacks::ConditionValueKind value, - clang::SourceRange conditionRange) { + clang::SourceRange condition_range) { Condition::ConditionValue cond_value = value == clang::PPCallbacks::CVK_False ? Condition::None : value == clang::PPCallbacks::CVK_True ? Condition::True : value == clang::PPCallbacks::CVK_NotEvaluated ? Condition::Skipped : Condition::None; - add_condition(loc, kind, cond_value, conditionRange); + add_condition(loc, kind, cond_value, condition_range); } void add_condition(clang::SourceLocation loc, @@ -51,12 +51,12 @@ private: return; } - if(SM.isWrittenInBuiltinFile(loc) || SM.isWrittenInCommandLineFile(loc) || - SM.isWrittenInScratchSpace(loc)) { + if(sm.isWrittenInBuiltinFile(loc) || sm.isWrittenInCommandLineFile(loc) || + sm.isWrittenInScratchSpace(loc)) { return; } - auto& directive = directives[SM.getFileID(loc)]; + auto& directive = directives[sm.getFileID(loc)]; directive.macros.emplace_back(MacroRef{def, kind, loc}); } @@ -65,62 +65,62 @@ public: /// Rewritten Preprocessor Callbacks /// ============================================================================ - void InclusionDirective(clang::SourceLocation hashLoc, - const clang::Token& includeTok, + void InclusionDirective(clang::SourceLocation hash_loc, + const clang::Token& include_tok, llvm::StringRef, bool, - clang::CharSourceRange filenameRange, + clang::CharSourceRange filename_range, clang::OptionalFileEntryRef, llvm::StringRef, llvm::StringRef, const clang::Module*, bool, clang::SrcMgr::CharacteristicKind) override { - prevFID = SM.getFileID(hashLoc); + prev_fid = sm.getFileID(hash_loc); /// An `IncludeDirective` call is always followed by either a `LexedFileChanged` /// or a `FileSkipped`. so we cannot get the file id of included file here. - directives[prevFID].includes.emplace_back(Include{ + directives[prev_fid].includes.emplace_back(Include{ .fid = {}, - .location = includeTok.getLocation(), - .filename_range = filenameRange.getAsRange(), + .location = include_tok.getLocation(), + .filename_range = filename_range.getAsRange(), }); } - void LexedFileChanged(clang::FileID currFID, + void LexedFileChanged(clang::FileID curr_fid, LexedFileChangeReason reason, clang::SrcMgr::CharacteristicKind, - clang::FileID prevFID, + clang::FileID prev_fid, clang::SourceLocation) override { - if(reason == LexedFileChangeReason::EnterFile && currFID.isValid() && prevFID.isValid() && - this->prevFID.isValid() && prevFID == this->prevFID) { + if(reason == LexedFileChangeReason::EnterFile && curr_fid.isValid() && prev_fid.isValid() && + this->prev_fid.isValid() && prev_fid == this->prev_fid) { /// Once the file has changed, it means that the last include is not skipped. /// Therefore, we initialize its file id with the current file id. - auto& include = directives[prevFID].includes.back(); + auto& include = directives[prev_fid].includes.back(); include.skipped = false; - include.fid = currFID; + include.fid = curr_fid; } } void FileSkipped(const clang::FileEntryRef& file, const clang::Token&, clang::SrcMgr::CharacteristicKind) override { - if(prevFID.isValid()) { + if(prev_fid.isValid()) { /// File with guard will have only one file id in `SourceManager`, use /// `translateFile` to find it. - auto& include = directives[prevFID].includes.back(); + auto& include = directives[prev_fid].includes.back(); include.skipped = true; /// Get the FileID for the given file. If the source file is included multiple /// times, the FileID will be the first inclusion. - include.fid = SM.translateFile(file); + include.fid = sm.translateFile(file); } } void moduleImport(clang::SourceLocation import_location, clang::ModuleIdPath names, const clang::Module*) override { - auto fid = SM.getFileID(SM.getExpansionLoc(import_location)); + auto fid = sm.getFileID(sm.getExpansionLoc(import_location)); auto& import = directives[fid].imports.emplace_back(); import.location = import_location; for(auto& [name, location]: names) { @@ -136,32 +136,32 @@ public: clang::SrcMgr::CharacteristicKind) override { clang::FileID fid; if(file) { - fid = SM.translateFile(*file); + fid = sm.translateFile(*file); } - directives[SM.getFileID(location)].has_includes.emplace_back(fid, location); + directives[sm.getFileID(location)].has_includes.emplace_back(fid, location); } - void PragmaDirective(clang::SourceLocation Loc, - clang::PragmaIntroducerKind Introducer) override { + void PragmaDirective(clang::SourceLocation loc, + clang::PragmaIntroducerKind introducer) override { // Ignore other cases except starts with `#pragma`. - if(Introducer != clang::PragmaIntroducerKind::PIK_HashPragma) + if(introducer != clang::PragmaIntroducerKind::PIK_HashPragma) return; - clang::FileID fid = SM.getFileID(Loc); + clang::FileID fid = sm.getFileID(loc); - llvm::StringRef textToEnd = SM.getBufferData(fid).substr(SM.getFileOffset(Loc)); - llvm::StringRef thatLine = textToEnd.take_until([](char ch) { return ch == '\n'; }); + llvm::StringRef text_to_end = sm.getBufferData(fid).substr(sm.getFileOffset(loc)); + llvm::StringRef that_line = text_to_end.take_until([](char ch) { return ch == '\n'; }); - Pragma::Kind kind = thatLine.contains("endregion") ? Pragma::EndRegion - : thatLine.contains("region") ? Pragma::Region - : Pragma::Other; + Pragma::Kind kind = that_line.contains("endregion") ? Pragma::EndRegion + : that_line.contains("region") ? Pragma::Region + : Pragma::Other; auto& directive = directives[fid]; directive.pragmas.emplace_back(Pragma{ - thatLine, + that_line, kind, - Loc, + loc, }); } @@ -220,16 +220,16 @@ public: add_condition(loc, Condition::Elifndef, Condition::Skipped, cond_range); } - void Else(clang::SourceLocation loc, clang::SourceLocation ifLoc) override { + void Else(clang::SourceLocation loc, clang::SourceLocation if_loc) override { add_condition(loc, Condition::Else, Condition::None, clang::SourceRange()); } - void Endif(clang::SourceLocation loc, clang::SourceLocation ifLoc) override { + void Endif(clang::SourceLocation loc, clang::SourceLocation if_loc) override { add_condition(loc, Condition::EndIf, Condition::None, clang::SourceRange()); } - void MacroDefined(const clang::Token& name, const clang::MacroDirective* MD) override { - if(auto def = MD->getMacroInfo()) { + void MacroDefined(const clang::Token& name, const clang::MacroDirective* md) override { + if(auto def = md->getMacroInfo()) { add_macro(def, MacroRef::Def, name.getLocation()); } } @@ -244,19 +244,19 @@ public: } void MacroUndefined(const clang::Token& name, - const clang::MacroDefinition& MD, + const clang::MacroDefinition& md, const clang::MacroDirective* undef) override { - if(auto def = MD.getMacroInfo()) { + if(auto def = md.getMacroInfo()) { add_macro(def, MacroRef::Undef, name.getLocation()); } } private: - clang::FileID prevFID; - clang::Preprocessor& PP; - clang::SourceManager& SM; + clang::FileID prev_fid; + clang::Preprocessor& pp; + clang::SourceManager& sm; llvm::DenseMap& directives; - llvm::DenseMap macroCache; + llvm::DenseMap macro_cache; }; } // namespace diff --git a/src/Compiler/Module.cpp b/src/Compiler/Module.cpp index e355f03d..69b62cd8 100644 --- a/src/Compiler/Module.cpp +++ b/src/Compiler/Module.cpp @@ -9,9 +9,9 @@ std::string scanModuleName(CompilationParams& params) { /// accepted, the module name in module declaration cannot be a macro now. /// It means that if the module declaration doesn't occur in condition preprocess /// directive, we can determine the module name just by lexing the source file. - clang::LangOptions langOpts; - langOpts.Modules = true; - langOpts.CPlusPlus20 = true; + clang::LangOptions lang_opts; + lang_opts.Modules = true; + lang_opts.CPlusPlus20 = true; /// FIXME: Figure out main file from command line. assert(params.buffers.size() == 1); @@ -19,16 +19,16 @@ std::string scanModuleName(CompilationParams& params) { /// We use raw mode of lexer to avoid the preprocessor. clang::Lexer lexer(clang::SourceLocation(), - langOpts, + lang_opts, content.begin(), content.begin(), content.end()); /// Whether we are in a condition directive. - bool isInDirective = false; + bool is_in_directive = false; /// Whether we need to preprocess the source file. - bool needPreprocess = false; + bool need_preprocess = false; std::string name; clang::Token token; @@ -46,9 +46,9 @@ std::string scanModuleName(CompilationParams& params) { lexer.LexFromRawLexer(token); auto diretive = token.getRawIdentifier(); if(diretive == "if" || diretive == "ifdef" || diretive == "ifndef") { - isInDirective = true; + is_in_directive = true; } else if(diretive == "endif") { - isInDirective = false; + is_in_directive = false; } } else if(token.is(clang::tok::raw_identifier)) { if(token.getRawIdentifier() != "export") [[likely]] { @@ -61,10 +61,10 @@ std::string scanModuleName(CompilationParams& params) { } /// We are after `export module`. - if(isInDirective) { + if(is_in_directive) { /// If the module name occurs in a condition directive, we have /// to preprocess the source file to determine the module name. - needPreprocess = true; + need_preprocess = true; break; } @@ -89,7 +89,7 @@ std::string scanModuleName(CompilationParams& params) { /// If not need to preprocess and the function doesn't return, it means /// that this file is not a module interface unit. - if(!needPreprocess) { + if(!need_preprocess) { return ""; }