diff options
author | Kim Grasman <kim.grasman@gmail.com> | 2016-08-16 20:56:28 +0200 |
---|---|---|
committer | Kim Grasman <kim.grasman@gmail.com> | 2016-09-04 17:06:41 +0200 |
commit | bb61a5040811e71d8c04438fdb2ea8e0022cd895 (patch) | |
tree | baaf0fbc066f49eb764abede972fca2138821035 | |
parent | 0097735a7fe2461a53344eb469f7e3cb89474c40 (diff) |
Terminology: as-typed -> as-written
Clang uses mostly "as-written" in its APIs. Follow that convention
more consistently.
-rw-r--r-- | iwyu.cc | 2 | ||||
-rw-r--r-- | iwyu_ast_util.cc | 4 | ||||
-rw-r--r-- | iwyu_include_picker.cc | 12 | ||||
-rw-r--r-- | iwyu_include_picker.h | 5 | ||||
-rw-r--r-- | iwyu_lexer_utils.cc | 5 | ||||
-rw-r--r-- | iwyu_lexer_utils.h | 4 | ||||
-rw-r--r-- | iwyu_preprocessor.cc | 55 | ||||
-rw-r--r-- | iwyu_preprocessor.h | 6 | ||||
-rw-r--r-- | more_tests/iwyu_lexer_utils_test.cc | 12 |
9 files changed, 54 insertions, 51 deletions
@@ -3088,7 +3088,7 @@ class InstantiatedTemplateVisitor const Type* class_type = GetTypeOf(expr); if (CanIgnoreType(class_type)) return true; - // If the ctor type is a SubstTemplateTypeParmType, get the type-as-typed. + // If the ctor type is a SubstTemplateTypeParmType, get the type-as-written. const Type* actual_type = ResugarType(class_type); CHECK_(actual_type && "If !CanIgnoreType(), we should be resugar-able"); ReportTypeUse(caller_loc(), actual_type); diff --git a/iwyu_ast_util.cc b/iwyu_ast_util.cc index 2979e21..11a4e84 100644 --- a/iwyu_ast_util.cc +++ b/iwyu_ast_util.cc @@ -508,7 +508,7 @@ static const Type* GetTemplateArgAsType(const TemplateArgument& tpl_arg) { // VarDecl 'vector<int(*)(const MyClass&)> x', it would return // (vector<int(*)(const MyClass&)>, int(*)(const MyClass&), // int(const MyClass&), int, const MyClass&, MyClass). Note that -// this function only returns types-as-typed, so it does *not* return +// this function only returns types-as-written, so it does *not* return // alloc<int(*)(const MyClass&)>, even though it's part of vector. class TypeEnumerator : public RecursiveASTVisitor<TypeEnumerator> { public: @@ -666,7 +666,7 @@ set<FunctionDecl*> GetLateParsedFunctionDecls(TranslationUnitDecl* decl) { // contains the original map elements plus mapping for the components. // This is because when a type is 'owned' by the template // instantiator, all parts of the type are owned. We only consider -// type-components as typed. +// type-components as written. static map<const Type*, const Type*> ResugarTypeComponents( const map<const Type*, const Type*>& resugar_map) { map<const Type*, const Type*> retval = resugar_map; diff --git a/iwyu_include_picker.cc b/iwyu_include_picker.cc index 10a7ca3..e43adc9 100644 --- a/iwyu_include_picker.cc +++ b/iwyu_include_picker.cc @@ -1007,7 +1007,7 @@ void IncludePicker::AddDirectInclude(const string& includer_filepath, quoted_includes_to_quoted_includers_[quoted_includee].insert(quoted_includer); const pair<string, string> key(includer_filepath, includee_filepath); - includer_and_includee_to_include_as_typed_[key] = quoted_include_as_written; + includer_and_includee_to_include_as_written_[key] = quoted_include_as_written; // Mark the clang fake-file "<built-in>" as private, so we never try // to map anything to it. @@ -1265,7 +1265,7 @@ string IncludePicker::MaybeGetIncludeNameAsWritten( const string& includer_filepath, const string& includee_filepath) const { const pair<string, string> key(includer_filepath, includee_filepath); // I want to use GetOrDefault here, but it has trouble deducing tpl args. - const string* value = FindInMap(&includer_and_includee_to_include_as_typed_, + const string* value = FindInMap(&includer_and_includee_to_include_as_written_, key); return value ? *value : ""; } @@ -1323,17 +1323,17 @@ vector<string> IncludePicker::GetCandidateHeadersForFilepathIncludedFrom( // We'll have called ConvertToQuotedInclude on members of retval, // but sometimes we can do better -- if included_filepath is in // retval, the iwyu-preprocessor may have stored the quoted-include - // as typed in including_filepath. This is better to use than + // as written in including_filepath. This is better to use than // ConvertToQuotedInclude because it avoids trouble when the same // file is accessible via different include search-paths, or is // accessed via a symlink. - const string& quoted_include_as_typed + const string& quoted_include_as_written = MaybeGetIncludeNameAsWritten(including_filepath, included_filepath); - if (!quoted_include_as_typed.empty()) { + if (!quoted_include_as_written.empty()) { vector<string>::iterator it = std::find(retval.begin(), retval.end(), quoted_includee); if (it != retval.end()) - *it = quoted_include_as_typed; + *it = quoted_include_as_written; } return retval; } diff --git a/iwyu_include_picker.h b/iwyu_include_picker.h index 145db90..3ab72c2 100644 --- a/iwyu_include_picker.h +++ b/iwyu_include_picker.h @@ -203,7 +203,7 @@ class IncludePicker { vector<string> GetPublicValues(const IncludeMap& m, const string& key) const; // Given an includer-pathname and includee-pathname, return the - // quoted-include of the includee, as typed in the includer, or + // quoted-include of the includee, as written in the includer, or // "" if it's not found for some reason. string MaybeGetIncludeNameAsWritten(const string& includer_filepath, const string& includee_filepath) const; @@ -231,7 +231,8 @@ class IncludePicker { // include-as-written (including <>'s or ""'s) that the includer // used to refer to the includee. We use this to return includes as // they were written in the source, when possible. - map<pair<string, string>, string> includer_and_includee_to_include_as_typed_; + map<pair<string, string>, string> + includer_and_includee_to_include_as_written_; // Maps from a quoted filepath pattern to the set of files that used // a pragma declaring it as a friend. That is, if foo/bar/x.h has a diff --git a/iwyu_lexer_utils.cc b/iwyu_lexer_utils.cc index 07ccaad..c0bf67c 100644 --- a/iwyu_lexer_utils.cc +++ b/iwyu_lexer_utils.cc @@ -69,8 +69,9 @@ SourceLocation GetLocationAfter( return start_loc.getLocWithOffset(needle_loc - data + needle.length()); } -string GetIncludeNameAsTyped(SourceLocation include_loc, - const CharacterDataGetterInterface& data_getter) { +string GetIncludeNameAsWritten( + SourceLocation include_loc, + const CharacterDataGetterInterface& data_getter) { const string data = GetSourceTextUntilEndOfLine(include_loc, data_getter); if (data.empty()) return data; diff --git a/iwyu_lexer_utils.h b/iwyu_lexer_utils.h index a9b0b0e..3253036 100644 --- a/iwyu_lexer_utils.h +++ b/iwyu_lexer_utils.h @@ -57,12 +57,12 @@ clang::SourceLocation GetLocationAfter( clang::SourceLocation start_loc, const string& needle, const CharacterDataGetterInterface& data_getter); -// Returns the include-name as typed, including <>'s and ""'s. +// Returns the include-name as written, including <>'s and ""'s. // Resolved computed includes first, so given // #define INC <stdio.h> // #include INC // If include_loc points to the second INC, we'll return '<stdio.h>'. -string GetIncludeNameAsTyped( +string GetIncludeNameAsWritten( clang::SourceLocation include_loc, const CharacterDataGetterInterface& data_getter); diff --git a/iwyu_preprocessor.cc b/iwyu_preprocessor.cc index 7cb6815..bba143f 100644 --- a/iwyu_preprocessor.cc +++ b/iwyu_preprocessor.cc @@ -85,11 +85,12 @@ string NormalizeNamespaces(string symbol) { // Utilities for examining source files. // For a particular #include line that include_loc points to, -// returns the include as typed by the user, including <> or "". +// returns the include as written by the user, including <> or "". // This works even for computed #includes ('#include MACRO'): we // point to the string the macro expands to. -static string GetIncludeNameAsTyped(SourceLocation include_loc) { - return GetIncludeNameAsTyped(include_loc, DefaultDataGetter()); // iwyu_lexer +// Simplifying wrapper around the iwyu_lexer function. +static string GetIncludeNameAsWritten(SourceLocation include_loc) { + return GetIncludeNameAsWritten(include_loc, DefaultDataGetter()); } // For a particular #include line that include_loc points to, @@ -375,7 +376,7 @@ void IwyuPreprocessorInfo::InsertIntoFileInfoMap( // instance, if it has an IWYU pragma saying to keep it. void IwyuPreprocessorInfo::MaybeProtectInclude( SourceLocation includer_loc, const FileEntry* includee, - const string& include_name_as_typed) { + const string& include_name_as_written) { const FileEntry* includer = GetFileEntry(includer_loc); if (IsBuiltinOrCommandLineFile(includer)) return; @@ -396,10 +397,10 @@ void IwyuPreprocessorInfo::MaybeProtectInclude( protect_reason = "pragma_export"; const string quoted_includer = ConvertToQuotedInclude(GetFilePath(includer)); - MutableGlobalIncludePicker()->AddMapping(include_name_as_typed, + MutableGlobalIncludePicker()->AddMapping(include_name_as_written, quoted_includer); ERRSYM(includer) << "Adding pragma-export mapping: " - << include_name_as_typed << " -> " << quoted_includer + << include_name_as_written << " -> " << quoted_includer << "\n"; // We also always keep #includes of .c files: iwyu doesn't touch those. @@ -422,9 +423,9 @@ void IwyuPreprocessorInfo::MaybeProtectInclude( if (!protect_reason.empty()) { CHECK_(ContainsKey(iwyu_file_info_map_, includer)); GetFromFileInfoMap(includer)->ReportIncludeFileUse(includee, - include_name_as_typed); + include_name_as_written); ERRSYM(includer) << "Marked dep: " << GetFilePath(includer) - << " needs to keep " << include_name_as_typed + << " needs to keep " << include_name_as_written << " (reason: " << protect_reason << ")\n"; } } @@ -453,14 +454,14 @@ static void ProtectReexportIncludes( // 1) iwyu_file_info_map_ maps the includer as a FileEntry* to the // includee both as the literal name used and as a FileEntry*. // 2) include_to_fileentry_map_ maps the includee's literal name -// as typed to the FileEntry* used. This can be used (in a +// as written to the FileEntry* used. This can be used (in a // limited way, due to non-uniqueness concerns) to map between // names and FileEntries. // We also tell this #include to the include-picker, which may // use it to fine-tune its include-picking algorithms. void IwyuPreprocessorInfo::AddDirectInclude( SourceLocation includer_loc, const FileEntry* includee, - const string& include_name_as_typed) { + const string& include_name_as_written) { if (IsBuiltinOrCommandLineFile(includee)) return; @@ -470,14 +471,14 @@ void IwyuPreprocessorInfo::AddDirectInclude( const FileEntry* includer = GetFileEntry(includer_loc); if (ShouldReportIWYUViolationsFor(includer)) { CHECK_(includee != nullptr); - CHECK_(!include_name_as_typed.empty()); + CHECK_(!include_name_as_written.empty()); } ++num_includes_seen_[includer]; GetFromFileInfoMap(includer)->AddInclude( - includee, include_name_as_typed, GetLineNumber(includer_loc)); + includee, include_name_as_written, GetLineNumber(includer_loc)); // Make sure the includee has a file-info-map entry too. - InsertIntoFileInfoMap(includee, include_name_as_typed); + InsertIntoFileInfoMap(includee, include_name_as_written); // The first #include in every translation unit might be a precompiled header // and we need to mark it as such for later analysis. @@ -512,20 +513,20 @@ void IwyuPreprocessorInfo::AddDirectInclude( // Because we use #include-next, the same include-name can map to // several files; we use the first such mapping we see, which is the // top of the #include-next chain. - if (!include_name_as_typed.empty()) { - if (!ContainsKey(include_to_fileentry_map_, include_name_as_typed)) { - include_to_fileentry_map_[include_name_as_typed] = includee; + if (!include_name_as_written.empty()) { + if (!ContainsKey(include_to_fileentry_map_, include_name_as_written)) { + include_to_fileentry_map_[include_name_as_written] = includee; } } // Tell the include-picker about this new include. MutableGlobalIncludePicker()->AddDirectInclude( - GetFilePath(includer), GetFilePath(includee), include_name_as_typed); + GetFilePath(includer), GetFilePath(includee), include_name_as_written); - MaybeProtectInclude(includer_loc, includee, include_name_as_typed); + MaybeProtectInclude(includer_loc, includee, include_name_as_written); ERRSYM(includer) << "Added an #include: " << GetFilePath(includer) - << " -> " << include_name_as_typed << "\n"; + << " -> " << include_name_as_written << "\n"; } //------------------------------------------------------------ @@ -663,15 +664,15 @@ void IwyuPreprocessorInfo::FileSkipped(const FileEntry& file, SrcMgr::CharacteristicKind file_type) { CHECK_(include_filename_loc_.isValid() && "Must skip file only for actual inclusion directive"); - const string include_name_as_typed = - GetIncludeNameAsTyped(include_filename_loc_); + const string include_name_as_written = + GetIncludeNameAsWritten(include_filename_loc_); const SourceLocation include_loc = GetInstantiationLoc(filename.getLocation()); ERRSYM(GetFileEntry(include_loc)) - << "[ (#include) ] " << include_name_as_typed + << "[ (#include) ] " << include_name_as_written << " (" << GetFilePath(&file) << ")\n"; - AddDirectInclude(include_loc, &file, include_name_as_typed); + AddDirectInclude(include_loc, &file, include_name_as_written); } // Called when a file is #included. @@ -681,19 +682,19 @@ void IwyuPreprocessorInfo::FileChanged_EnterFile( // include of the file that file_beginning is in. const SourceLocation include_loc = GlobalSourceManager()->getIncludeLoc( GlobalSourceManager()->getFileID(file_beginning)); - string include_name_as_typed; + string include_name_as_written; if (!IsBuiltinOrCommandLineFile(GetFileEntry(include_loc))) { CHECK_(include_filename_loc_.isValid() && "Include from not built-in file must have inclusion directive"); - include_name_as_typed = GetIncludeNameAsTyped(include_filename_loc_); + include_name_as_written = GetIncludeNameAsWritten(include_filename_loc_); } ERRSYM(GetFileEntry(include_loc)) - << "[ #include ] " << include_name_as_typed + << "[ #include ] " << include_name_as_written << " (" << GetFilePath(file_beginning) << ")\n"; const FileEntry* const new_file = GetFileEntry(file_beginning); if (new_file) - AddDirectInclude(include_loc, new_file, include_name_as_typed); + AddDirectInclude(include_loc, new_file, include_name_as_written); if (IsBuiltinOrCommandLineFile(new_file)) return; diff --git a/iwyu_preprocessor.h b/iwyu_preprocessor.h index f44624f..1835bc3 100644 --- a/iwyu_preprocessor.h +++ b/iwyu_preprocessor.h @@ -243,12 +243,12 @@ class IwyuPreprocessorInfo : public clang::PPCallbacks, // #include from iwyu removal. void MaybeProtectInclude(clang::SourceLocation includer_loc, const clang::FileEntry* includee, - const string& include_name_as_typed); + const string& include_name_as_written); // Called whenever an #include is seen in the preprocessor output. void AddDirectInclude(clang::SourceLocation includer_loc, const clang::FileEntry* includee, - const string& include_name_as_typed); + const string& include_name_as_written); // Report a "begin_exports"/"end_exports" pragma pair. // begin_line is first line, end_line is just after the last line. @@ -304,7 +304,7 @@ class IwyuPreprocessorInfo : public clang::PPCallbacks, // which we don't have. Luckily, a vector works just as well. vector<clang::Token> macros_called_from_macros_; - // This maps from the include-name as typed in the program + // This maps from the include-name as written in the program // (including <>'s or ""'s) to the FileEntry we loaded for that // #include. map<string, const clang::FileEntry*> include_to_fileentry_map_; diff --git a/more_tests/iwyu_lexer_utils_test.cc b/more_tests/iwyu_lexer_utils_test.cc index 1e52fdd..2669af0 100644 --- a/more_tests/iwyu_lexer_utils_test.cc +++ b/more_tests/iwyu_lexer_utils_test.cc @@ -240,31 +240,31 @@ TEST(GetLocationAfter, BeginAfterStartOfText) { GetSourceTextUntilEndOfLine(after_loc, data_getter)); } -TEST(GetIncludeNameAsTyped, SystemInclude) { +TEST(GetIncludeNameAsWritten, SystemInclude) { const char text[] = "#include <stdio.h>\n"; StringCharacterDataGetter data_getter(text); SourceLocation begin_loc = data_getter.BeginningOfString(); SourceLocation inc_loc = CreateSourceLocationFromOffset(begin_loc, 9); EXPECT_EQ("<stdio.h>", - GetIncludeNameAsTyped(inc_loc, data_getter)); + GetIncludeNameAsWritten(inc_loc, data_getter)); } -TEST(GetIncludeNameAsTyped, NonsysytemInclude) { +TEST(GetIncludeNameAsWritten, NonsysytemInclude) { const char text[] = "#include \"ads/util.h\"\n"; StringCharacterDataGetter data_getter(text); SourceLocation begin_loc = data_getter.BeginningOfString(); SourceLocation inc_loc = CreateSourceLocationFromOffset(begin_loc, 9); EXPECT_EQ("\"ads/util.h\"", - GetIncludeNameAsTyped(inc_loc, data_getter)); + GetIncludeNameAsWritten(inc_loc, data_getter)); } -TEST(GetIncludeNameAsTyped, WithComments) { +TEST(GetIncludeNameAsWritten, WithComments) { const char text[] = "#include <stdio.h> // for printf\n"; StringCharacterDataGetter data_getter(text); SourceLocation begin_loc = data_getter.BeginningOfString(); SourceLocation inc_loc = CreateSourceLocationFromOffset(begin_loc, 9); EXPECT_EQ("<stdio.h>", - GetIncludeNameAsTyped(inc_loc, data_getter)); + GetIncludeNameAsWritten(inc_loc, data_getter)); } } // namespace |