]> granicus.if.org Git - clang/commitdiff
Fix layering violation: include/clang/Basic/PlistSupport.h should not include
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 28 Jan 2015 20:14:54 +0000 (20:14 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 28 Jan 2015 20:14:54 +0000 (20:14 +0000)
files from include/clang/Lex. Clean up module map.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227361 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/PlistSupport.h
include/clang/Basic/SourceManager.h
include/clang/Lex/Lexer.h
include/clang/module.modulemap
lib/ARCMigrate/PlistReporter.cpp
lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
test/Analysis/diagnostics/report-issues-within-main-file.cpp
test/Analysis/plist-macros.cpp

index 081f22d48d4aa8f6a5da7f4231bd03a4ae2eff81..84dd29138a805f28c5e24e4c533d6bdc775a3cac 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
-#include "clang/Lex/Lexer.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -89,31 +88,29 @@ inline raw_ostream &EmitString(raw_ostream &o, StringRef s) {
 }
 
 inline void EmitLocation(raw_ostream &o, const SourceManager &SM,
-                         const LangOptions &LangOpts, SourceLocation L,
-                         const FIDMap &FM, unsigned indent,
-                         bool extend = false) {
-  FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
+                         SourceLocation L, const FIDMap &FM, unsigned indent) {
+  if (L.isInvalid()) return;
 
-  // Add in the length of the token, so that we cover multi-char tokens.
-  unsigned offset =
-      extend ? Lexer::MeasureTokenLength(Loc, SM, LangOpts) - 1 : 0;
+  FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
 
   Indent(o, indent) << "<dict>\n";
   Indent(o, indent) << " <key>line</key>";
   EmitInteger(o, Loc.getExpansionLineNumber()) << '\n';
   Indent(o, indent) << " <key>col</key>";
-  EmitInteger(o, Loc.getExpansionColumnNumber() + offset) << '\n';
+  EmitInteger(o, Loc.getExpansionColumnNumber()) << '\n';
   Indent(o, indent) << " <key>file</key>";
   EmitInteger(o, GetFID(FM, SM, Loc)) << '\n';
   Indent(o, indent) << "</dict>\n";
 }
 
 inline void EmitRange(raw_ostream &o, const SourceManager &SM,
-                      const LangOptions &LangOpts, CharSourceRange R,
-                      const FIDMap &FM, unsigned indent) {
+                      CharSourceRange R, const FIDMap &FM, unsigned indent) {
+  if (R.isInvalid()) return;
+
+  assert(R.isCharRange() && "cannot handle a token range");
   Indent(o, indent) << "<array>\n";
-  EmitLocation(o, SM, LangOpts, R.getBegin(), FM, indent + 1);
-  EmitLocation(o, SM, LangOpts, R.getEnd(), FM, indent + 1, R.isTokenRange());
+  EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
+  EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
   Indent(o, indent) << "</array>\n";
 }
 }
index 717258ddcf0453e1716b0a475e9bb40e22398254..d17fdd51bbb7f46bab058b1690cd1b5bc8a9db93 100644 (file)
@@ -1057,10 +1057,16 @@ public:
   getImmediateExpansionRange(SourceLocation Loc) const;
 
   /// \brief Given a SourceLocation object, return the range of
-  /// tokens covered by the expansion the ultimate file.
+  /// tokens covered by the expansion in the ultimate file.
   std::pair<SourceLocation,SourceLocation>
   getExpansionRange(SourceLocation Loc) const;
 
+  /// \brief Given a SourceRange object, return the range of
+  /// tokens covered by the expansion in the ultimate file.
+  SourceRange getExpansionRange(SourceRange Range) const {
+    return SourceRange(getExpansionRange(Range.getBegin()).first,
+                       getExpansionRange(Range.getEnd()).second);
+  }
 
   /// \brief Given a SourceLocation object, return the spelling
   /// location referenced by the ID.
index c1f968be558451f989ae5af735aeeda76e87ec01..42fe0207626325d0d7ec90a7219bc6b944447670 100644 (file)
@@ -323,6 +323,26 @@ public:
                                             const SourceManager &SM,
                                             const LangOptions &LangOpts);
 
+  /// \brief Given a token range, produce a corresponding CharSourceRange that
+  /// is not a token range. This allows the source range to be used by
+  /// components that don't have access to the lexer and thus can't find the
+  /// end of the range for themselves.
+  static CharSourceRange getAsCharRange(SourceRange Range,
+                                        const SourceManager &SM,
+                                        const LangOptions &LangOpts) {
+    SourceLocation End = getLocForEndOfToken(Range.getEnd(), 0, SM, LangOpts);
+    return End.isInvalid() ? CharSourceRange()
+                           : CharSourceRange::getCharRange(
+                                 Range.getBegin(), End.getLocWithOffset(-1));
+  }
+  static CharSourceRange getAsCharRange(CharSourceRange Range,
+                                        const SourceManager &SM,
+                                        const LangOptions &LangOpts) {
+    return Range.isTokenRange()
+               ? getAsCharRange(Range.getAsRange(), SM, LangOpts)
+               : Range;
+  }
+
   /// \brief Returns true if the given MacroID location points at the first
   /// token of the macro expansion.
   ///
index 5058d15025d88354759bb22452693e90313e9250..9e4dac17a43a468a301c2fd232c371f21f9c5379 100644 (file)
@@ -2,8 +2,7 @@ module Clang_Analysis {
   requires cplusplus
   umbrella "Analysis"
 
-  // This file is intended for repeated textual inclusion.
-  exclude header "Analysis/Analyses/ThreadSafetyOps.def"
+  textual header "Analysis/Analyses/ThreadSafetyOps.def"
 
   module * { export * }
 }
@@ -12,10 +11,9 @@ module Clang_AST {
   requires cplusplus
   umbrella "AST"
 
-  // These files are intended for repeated textual inclusion.
-  exclude header "AST/BuiltinTypes.def"
-  exclude header "AST/TypeLocNodes.def"
-  exclude header "AST/TypeNodes.def"
+  textual header "AST/BuiltinTypes.def"
+  textual header "AST/TypeLocNodes.def"
+  textual header "AST/TypeNodes.def"
 
   module * { export * }
 }
@@ -26,33 +24,26 @@ module Clang_Basic {
   requires cplusplus
   umbrella "Basic"
 
-  // These files are intended for repeated textual inclusion.
-  exclude header "Basic/BuiltinsAArch64.def"
-  exclude header "Basic/BuiltinsARM64.def"
-  exclude header "Basic/BuiltinsARM.def"
-  exclude header "Basic/Builtins.def"
-  exclude header "Basic/BuiltinsHexagon.def"
-  exclude header "Basic/BuiltinsMips.def"
-  exclude header "Basic/BuiltinsNEON.def"
-  exclude header "Basic/BuiltinsNVPTX.def"
-  exclude header "Basic/BuiltinsPPC.def"
-  exclude header "Basic/BuiltinsR600.def"
-  exclude header "Basic/BuiltinsX86.def"
-  exclude header "Basic/BuiltinsXCore.def"
-  exclude header "Basic/BuiltinsLe64.def"
-  exclude header "Basic/DiagnosticOptions.def"
-  exclude header "Basic/LangOptions.def"
-  exclude header "Basic/OpenCLExtensions.def"
-  exclude header "Basic/OpenMPKinds.def"
-  exclude header "Basic/OperatorKinds.def"
-  exclude header "Basic/Sanitizers.def"
-  exclude header "Basic/TokenKinds.def"
-
-  // This file includes a header from Lex.
-  exclude header "Basic/PlistSupport.h"
-
-  // FIXME: This is logically a part of Basic, but has been put in the wrong place.
-  header "StaticAnalyzer/Core/AnalyzerOptions.h"
+  textual header "Basic/BuiltinsAArch64.def"
+  textual header "Basic/BuiltinsARM64.def"
+  textual header "Basic/BuiltinsARM.def"
+  textual header "Basic/Builtins.def"
+  textual header "Basic/BuiltinsHexagon.def"
+  textual header "Basic/BuiltinsMips.def"
+  textual header "Basic/BuiltinsNEON.def"
+  textual header "Basic/BuiltinsNVPTX.def"
+  textual header "Basic/BuiltinsPPC.def"
+  textual header "Basic/BuiltinsR600.def"
+  textual header "Basic/BuiltinsX86.def"
+  textual header "Basic/BuiltinsXCore.def"
+  textual header "Basic/BuiltinsLe64.def"
+  textual header "Basic/DiagnosticOptions.def"
+  textual header "Basic/LangOptions.def"
+  textual header "Basic/OpenCLExtensions.def"
+  textual header "Basic/OpenMPKinds.def"
+  textual header "Basic/OperatorKinds.def"
+  textual header "Basic/Sanitizers.def"
+  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
@@ -82,8 +73,7 @@ module Clang_Driver {
   requires cplusplus
   umbrella "Driver"
 
-  // This file is intended for repeated textual inclusion.
-  exclude header "Driver/Types.def"
+  textual header "Driver/Types.def"
 
   module * { export * }
 }
@@ -95,9 +85,8 @@ module Clang_Frontend {
   requires cplusplus
   umbrella "Frontend"
 
-  // These files are intended for repeated textual inclusion.
-  exclude header "Frontend/CodeGenOptions.def"
-  exclude header "Frontend/LangStandards.def"
+  textual header "Frontend/CodeGenOptions.def"
+  textual header "Frontend/LangStandards.def"
 
   module * { export * }
 }
@@ -114,8 +103,7 @@ module Clang_StaticAnalyzer {
   requires cplusplus
   umbrella "StaticAnalyzer"
 
-  // This file is intended for repeated textual inclusion.
-  exclude header "StaticAnalyzer/Core/Analyses.def"
+  textual header "StaticAnalyzer/Core/Analyses.def"
 
   module * { export * }
 }
index 53398b27af499ff3a947f8bd2872fdad7aee3f37..9a51690c0ce7bb4cd3af30adb022844b5fe535d1 100644 (file)
@@ -100,16 +100,18 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath,
 
     // Output the location of the bug.
     o << "  <key>location</key>\n";
-    EmitLocation(o, SM, LangOpts, D.getLocation(), FM, 2);
+    EmitLocation(o, SM, D.getLocation(), FM, 2);
 
     // Output the ranges (if any).
-    StoredDiagnostic::range_iterator RI = D.range_begin(), RE = D.range_end();
-
-    if (RI != RE) {
+    if (!D.getRanges().empty()) {
       o << "   <key>ranges</key>\n";
       o << "   <array>\n";
-      for (; RI != RE; ++RI)
-        EmitRange(o, SM, LangOpts, *RI, FM, 4);
+      for (auto &R : D.getRanges()) {
+        CharSourceRange ExpansionRange(SM.getExpansionRange(R.getAsRange()),
+                                       R.isTokenRange());
+        EmitRange(o, SM, Lexer::getAsCharRange(ExpansionRange, SM, LangOpts),
+                  FM, 4);
+      }
       o << "   </array>\n";
     }
 
index a2c66f881482c4a0b81dd17d226caf8a5c155781..11bd254b7806544efa6e93d37f168efdf21ef062 100644 (file)
@@ -106,13 +106,14 @@ static void ReportControlFlow(raw_ostream &o,
     // by forcing to use only the beginning of the range.  This simplifies the layout
     // logic for clients.
     Indent(o, indent) << "<key>start</key>\n";
-    SourceLocation StartEdge = I->getStart().asRange().getBegin();
-    EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(StartEdge), FM,
+    SourceRange StartEdge(
+        SM.getExpansionLoc(I->getStart().asRange().getBegin()));
+    EmitRange(o, SM, Lexer::getAsCharRange(StartEdge, SM, LangOpts), FM,
               indent + 1);
 
     Indent(o, indent) << "<key>end</key>\n";
-    SourceLocation EndEdge = I->getEnd().asRange().getBegin();
-    EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(EndEdge), FM,
+    SourceRange EndEdge(SM.getExpansionLoc(I->getEnd().asRange().getBegin()));
+    EmitRange(o, SM, Lexer::getAsCharRange(EndEdge, SM, LangOpts), FM,
               indent + 1);
 
     --indent;
@@ -154,7 +155,7 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
   FullSourceLoc L = P.getLocation().asLocation();
 
   Indent(o, indent) << "<key>location</key>\n";
-  EmitLocation(o, SM, LangOpts, L, FM, indent);
+  EmitLocation(o, SM, L, FM, indent);
 
   // Output the ranges (if any).
   ArrayRef<SourceRange> Ranges = P.getRanges();
@@ -163,11 +164,10 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
     Indent(o, indent) << "<key>ranges</key>\n";
     Indent(o, indent) << "<array>\n";
     ++indent;
-    for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
-         I != E; ++I) {
-      EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(*I), FM,
-                indent + 1);
-    }
+    for (auto &R : Ranges)
+      EmitRange(o, SM,
+                Lexer::getAsCharRange(SM.getExpansionRange(R), SM, LangOpts),
+                FM, indent + 1);
     --indent;
     Indent(o, indent) << "</array>\n";
   }
@@ -453,7 +453,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
 
     // Output the location of the bug.
     o << "  <key>location</key>\n";
-    EmitLocation(o, *SM, LangOpts, D->getLocation().asLocation(), FM, 2);
+    EmitLocation(o, *SM, D->getLocation().asLocation(), FM, 2);
 
     // Output the diagnostic to the sub-diagnostic client, if any.
     if (!filesMade->empty()) {
index ec8106f6000a99390bc4e98237f454896915ef66..bba15f5e4403795ceea4cc8dc10439cf0ac69ffc 100644 (file)
@@ -542,7 +542,7 @@ void callInMacroArg() {
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:         <dict>
 // CHECK-NEXT:          <key>line</key><integer>69</integer>
-// CHECK-NEXT:          <key>col</key><integer>18</integer>
+// CHECK-NEXT:          <key>col</key><integer>51</integer>
 // CHECK-NEXT:          <key>file</key><integer>0</integer>
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:        </array>
index 0e8518a6f59c886ca254e09daa366c7443b40252..58df5694bedf2f3204a7fdccc8689d59f81fe41c 100644 (file)
@@ -903,7 +903,7 @@ void test2(int *p) {
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:         <dict>
 // CHECK-NEXT:          <key>line</key><integer>45</integer>
-// CHECK-NEXT:          <key>col</key><integer>18</integer>
+// CHECK-NEXT:          <key>col</key><integer>21</integer>
 // CHECK-NEXT:          <key>file</key><integer>0</integer>
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:        </array>
@@ -1395,7 +1395,7 @@ void test2(int *p) {
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:         <dict>
 // CHECK-NEXT:          <key>line</key><integer>82</integer>
-// CHECK-NEXT:          <key>col</key><integer>9</integer>
+// CHECK-NEXT:          <key>col</key><integer>12</integer>
 // CHECK-NEXT:          <key>file</key><integer>0</integer>
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:        </array>
@@ -1424,7 +1424,7 @@ void test2(int *p) {
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:         <dict>
 // CHECK-NEXT:          <key>line</key><integer>82</integer>
-// CHECK-NEXT:          <key>col</key><integer>9</integer>
+// CHECK-NEXT:          <key>col</key><integer>12</integer>
 // CHECK-NEXT:          <key>file</key><integer>0</integer>
 // CHECK-NEXT:         </dict>
 // CHECK-NEXT:        </array>