r227361 - Fix layering violation: include/clang/Basic/PlistSupport.h should not include

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 28 12:14:54 PST 2015


Author: rsmith
Date: Wed Jan 28 14:14:54 2015
New Revision: 227361

URL: http://llvm.org/viewvc/llvm-project?rev=227361&view=rev
Log:
Fix layering violation: include/clang/Basic/PlistSupport.h should not include
files from include/clang/Lex. Clean up module map.

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

Modified: cfe/trunk/include/clang/Basic/PlistSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PlistSupport.h?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/PlistSupport.h (original)
+++ cfe/trunk/include/clang/Basic/PlistSupport.h Wed Jan 28 14:14:54 2015
@@ -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_ostre
 }
 
 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";
 }
 }

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Wed Jan 28 14:14:54 2015
@@ -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.

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Jan 28 14:14:54 2015
@@ -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.
   ///

Modified: cfe/trunk/include/clang/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/module.modulemap?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/include/clang/module.modulemap (original)
+++ cfe/trunk/include/clang/module.modulemap Wed Jan 28 14:14:54 2015
@@ -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 * }
 }

Modified: cfe/trunk/lib/ARCMigrate/PlistReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/PlistReporter.cpp?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/PlistReporter.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/PlistReporter.cpp Wed Jan 28 14:14:54 2015
@@ -100,16 +100,18 @@ void arcmt::writeARCDiagsToPlist(const s
 
     // 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";
     }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Wed Jan 28 14:14:54 2015
@@ -106,13 +106,14 @@ static void ReportControlFlow(raw_ostrea
     // 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,
   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,
     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::FlushDiagnosticsI
 
     // 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()) {

Modified: cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/report-issues-within-main-file.cpp Wed Jan 28 14:14:54 2015
@@ -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>

Modified: cfe/trunk/test/Analysis/plist-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plist-macros.cpp?rev=227361&r1=227360&r2=227361&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/plist-macros.cpp (original)
+++ cfe/trunk/test/Analysis/plist-macros.cpp Wed Jan 28 14:14:54 2015
@@ -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>





More information about the cfe-commits mailing list