[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang include/tools svl/source tools/source

Stephan Bergmann sbergman at redhat.com
Thu Feb 20 10:52:08 PST 2014


 compilerplugins/clang/plugin.cxx        |   26 +++++++++++++++++---------
 compilerplugins/clang/plugin.hxx        |    4 +---
 compilerplugins/clang/pluginhandler.cxx |    5 +++++
 compilerplugins/clang/pluginhandler.hxx |    4 ++++
 include/tools/stream.hxx                |    1 +
 svl/source/items/cenumitm.cxx           |    4 ++--
 svl/source/items/ctypeitm.cxx           |    4 ++--
 svl/source/items/visitem.cxx            |    4 ++--
 svl/source/numbers/zformat.cxx          |   10 +++++-----
 tools/source/stream/stream.cxx          |   24 ++++++++++++++++++++++++
 10 files changed, 63 insertions(+), 23 deletions(-)

New commits:
commit 9c9e4b1942b2bb7bb80d0317f40488a4cf1f9b9a
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Feb 20 19:51:04 2014 +0100

    Add SvStream::ReadCharAsBool
    
    Change-Id: I9dc0525e04de5ae79205872b779dcd0115a9cc14

diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index 4f8085d..d04109f 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -308,6 +308,7 @@ public:
     SvStream&       ReadSChar( signed char& rChar );
     SvStream&       ReadChar( char& rChar );
     SvStream&       ReadUChar( unsigned char& rChar );
+    SvStream&       ReadCharAsBool( bool& rBool );
     SvStream&       ReadFloat( float& rFloat );
     SvStream&       ReadDouble( double& rDouble );
     SvStream&       ReadStream( SvStream& rStream );
diff --git a/svl/source/items/cenumitm.cxx b/svl/source/items/cenumitm.cxx
index 74a6314..bf13761 100644
--- a/svl/source/items/cenumitm.cxx
+++ b/svl/source/items/cenumitm.cxx
@@ -169,8 +169,8 @@ TYPEINIT1_AUTOFACTORY(SfxBoolItem, SfxPoolItem);
 SfxBoolItem::SfxBoolItem(sal_uInt16 const nWhich, SvStream & rStream)
     : SfxPoolItem(nWhich)
 {
-    unsigned char tmp = 0;
-    rStream.ReadUChar( tmp );
+    bool tmp = false;
+    rStream.ReadCharAsBool( tmp );
     m_bValue = tmp;
 }
 
diff --git a/svl/source/items/ctypeitm.cxx b/svl/source/items/ctypeitm.cxx
index d2299ae..16a8bf8 100644
--- a/svl/source/items/ctypeitm.cxx
+++ b/svl/source/items/ctypeitm.cxx
@@ -71,8 +71,8 @@ SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream,
     rStream.ReadUInt32( nMagic );
     if (nMagic == CNTSTRINGITEM_STREAM_MAGIC)
     {
-        unsigned char bEncrypted = sal_False;
-        rStream.ReadUChar( bEncrypted );
+        bool bEncrypted = false;
+        rStream.ReadCharAsBool( bEncrypted );
         DBG_ASSERT(!bEncrypted,
                    "CntContentTypeItem::Create() reads encrypted data");
     }
diff --git a/svl/source/items/visitem.cxx b/svl/source/items/visitem.cxx
index dbd8ec5..8adc762 100644
--- a/svl/source/items/visitem.cxx
+++ b/svl/source/items/visitem.cxx
@@ -33,8 +33,8 @@ SfxVisibilityItem::SfxVisibilityItem(sal_uInt16 which, SvStream & rStream):
     SfxPoolItem(which)
 {
     DBG_CTOR(SfxVisibilityItem, 0);
-    unsigned char bValue = 0;
-    rStream.ReadUChar( bValue );
+    bool bValue = false;
+    rStream.ReadCharAsBool( bValue );
     m_nValue.bVisible = bValue;
 }
 
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 73072a3..6bf72257 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -184,8 +184,8 @@ void ImpSvNumberformatInfo::Load(SvStream& rStream, sal_uInt16 nAnz)
         sStrArray[i] = SvNumberformat::LoadString( rStream );
         rStream.ReadInt16( nTypeArray[i] );
     }
-    unsigned char bStreamThousand;
-    rStream.ReadInt16( eScannedType ).ReadUChar( bStreamThousand ).ReadUInt16( nThousand )
+    bool bStreamThousand;
+    rStream.ReadInt16( eScannedType ).ReadCharAsBool( bStreamThousand ).ReadUInt16( nThousand )
            .ReadUInt16( nCntPre ).ReadUInt16( nCntPost ).ReadUInt16( nCntExp );
     bThousand = bStreamThousand;
 }
@@ -1702,9 +1702,9 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
     rHdr.StartEntry();
     sal_uInt16 nOp1, nOp2;
     sFormatstring = SvNumberformat::LoadString( rStream );
-    unsigned char bStreamStandard, bStreamUsed;
+    bool bStreamStandard, bStreamUsed;
     rStream.ReadInt16( eType ).ReadDouble( fLimit1 ).ReadDouble( fLimit2 )
-           .ReadUInt16( nOp1 ).ReadUInt16( nOp2 ).ReadUChar( bStreamStandard ).ReadUChar( bStreamUsed );
+           .ReadUInt16( nOp1 ).ReadUInt16( nOp2 ).ReadCharAsBool( bStreamStandard ).ReadCharAsBool( bStreamUsed );
     bStandard = bStreamStandard;
     bIsUsed = bStreamUsed;
     NfHackConversion eHackConversion = NF_CONVERT_NONE;
@@ -1795,7 +1795,7 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
             }
             break;
         case nNewStandardFlagVersionId :
-            rStream.ReadUChar( bStreamStandard ); // the real standard flag
+            rStream.ReadCharAsBool( bStreamStandard ); // the real standard flag
             bStandard = bStreamStandard;
             break;
         default:
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index ea34d30..acd48dd 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1004,6 +1004,30 @@ SvStream& SvStream::ReadUChar( unsigned char& r )
     return *this;
 }
 
+SvStream& SvStream::ReadCharAsBool( bool& r )
+{
+    if( (bIoRead || !bIsConsistent) &&
+        sizeof(char) <= nBufFree )
+    {
+        SAL_WARN_IF(
+            *pBufPos > 1, "tools.stream", unsigned(*pBufPos) << " not 0/1");
+        r = *pBufPos != 0;
+        nBufActualPos += sizeof(char);
+        pBufPos += sizeof(char);
+        nBufFree -= sizeof(char);
+    }
+    else
+    {
+        unsigned char c;
+        if (Read(&c, 1) == 1)
+        {
+            SAL_WARN_IF(c > 1, "tools.stream", unsigned(c) << " not 0/1");
+            r = c != 0;
+        }
+    }
+    return *this;
+}
+
 SvStream& SvStream::ReadFloat(float& r)
 {
     float n = 0;
commit 5dcb634dcbc5816e4b61e14ce2f05395e52ac5bf
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Feb 20 19:47:01 2014 +0100

    Don't attempt to actually do double code removals
    
    ...that easily works around the problem that in a rewriter rewriting types of
    VarDecls like
    
       T x, y;
    
    it would try to replace T twice.  Also, keep the list of removals globally with
    the (global) rewriter.
    
    Change-Id: I55b8d11986c2a29e09ff40132fd114a0cc48dc90

diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 626e55a..88841ea 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -25,7 +25,7 @@ namespace loplugin
 {
 
 Plugin::Plugin( const InstantiationData& data )
-    : compiler( data.compiler ), name( data.name ), handler( data.handler )
+    : compiler( data.compiler ), handler( data.handler ), name( data.name )
     {
     }
 
@@ -192,9 +192,11 @@ bool RewritePlugin::removeText( CharSourceRange range, RewriteOptions opts )
     assert( rewriter );
     if( rewriter->getRangeSize( range, opts ) == -1 )
         return reportEditFailure( range.getBegin());
-    if( removals.find( range.getBegin()) != removals.end())
+    if( !handler.addRemoval( range.getBegin() ) )
+        {
         report( DiagnosticsEngine::Warning, "double code removal, possible plugin error", range.getBegin());
-    removals.insert( range.getBegin());
+        return true;
+        }
     if( opts.flags & RemoveWholeStatement || opts.flags & RemoveAllWhitespace )
         {
         if( !adjustRangeForOptions( &range, opts ))
@@ -249,9 +251,11 @@ bool RewritePlugin::adjustRangeForOptions( CharSourceRange* range, RewriteOption
 bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr )
     {
     assert( rewriter );
-    if( OrigLength != 0 && removals.find( Start ) != removals.end())
+    if( OrigLength != 0 && !handler.addRemoval( Start ) )
+        {
         report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", Start );
-    removals.insert( Start );
+        return true;
+        }
     if( rewriter->ReplaceText( Start, OrigLength, NewStr ))
         return reportEditFailure( Start );
     return true;
@@ -262,9 +266,11 @@ bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr )
     assert( rewriter );
     if( rewriter->getRangeSize( range ) == -1 )
         return reportEditFailure( range.getBegin());
-    if( removals.find( range.getBegin()) != removals.end())
+    if( !handler.addRemoval( range.getBegin() ) )
+        {
         report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin());
-    removals.insert( range.getBegin());
+        return true;
+        }
     if( rewriter->ReplaceText( range, NewStr ))
         return reportEditFailure( range.getBegin());
     return true;
@@ -275,9 +281,11 @@ bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange
     assert( rewriter );
     if( rewriter->getRangeSize( range ) == -1 )
         return reportEditFailure( range.getBegin());
-    if( removals.find( range.getBegin()) != removals.end())
+    if( !handler.addRemoval( range.getBegin() ) )
+        {
         report( DiagnosticsEngine::Warning, "double code replacement, possible plugin error", range.getBegin());
-    removals.insert( range.getBegin());
+        return true;
+        }
     if( rewriter->ReplaceText( range, replacementRange ))
         return reportEditFailure( range.getBegin());
     return true;
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index ff868bf..796ebef 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -20,7 +20,6 @@
 #include <clang/Basic/SourceManager.h>
 #include <clang/Frontend/CompilerInstance.h>
 #include <clang/Lex/Preprocessor.h>
-#include <set>
 #include <unordered_map>
 
 #if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 2
@@ -67,6 +66,7 @@ class Plugin
         bool ignoreLocation( const Decl* decl );
         bool ignoreLocation( const Stmt* stmt );
         CompilerInstance& compiler;
+        PluginHandler& handler;
         /**
          Returns the parent of the given AST node. Clang's internal AST representation doesn't provide this information,
          it can only provide children, but getting the parent is often useful for inspecting a part of the AST.
@@ -78,7 +78,6 @@ class Plugin
         template< typename T > static Plugin* createHelper( const InstantiationData& data );
         enum { isRewriter = false };
         const char* name;
-        PluginHandler& handler;
         static unordered_map< const Stmt*, const Stmt* > parents;
         static void buildParents( CompilerInstance& compiler );
     };
@@ -139,7 +138,6 @@ class RewritePlugin
         enum { isRewriter = true };
         bool reportEditFailure( SourceLocation loc );
         bool adjustRangeForOptions( CharSourceRange* range, RewriteOptions options );
-        set< SourceLocation > removals;
     };
 
 /**
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index d6595a3..4518dd5 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -159,6 +159,11 @@ DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringR
     return report( level, nullptr, message, compiler, loc );
     }
 
+bool PluginHandler::addRemoval( SourceLocation loc )
+    {
+    return removals.insert( loc ).second;
+    }
+
 void PluginHandler::HandleTranslationUnit( ASTContext& context )
     {
     if( context.getDiagnostics().hasErrorOccurred())
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index dcfac71..48cee8e 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -14,6 +14,8 @@
 
 #include "plugin.hxx"
 
+#include <set>
+
 #include <clang/AST/ASTConsumer.h>
 #include <clang/Frontend/FrontendAction.h>
 
@@ -33,12 +35,14 @@ class PluginHandler
         static void registerPlugin( Plugin* (*create)( const Plugin::InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
         DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
             CompilerInstance& compiler, SourceLocation loc = SourceLocation());
+        bool addRemoval( SourceLocation loc );
     private:
         void handleOption( const string& option );
         void createPlugins( set< string > rewriters );
         DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
         CompilerInstance& compiler;
         Rewriter rewriter;
+        set< SourceLocation > removals;
         string scope;
         string warningsOnly;
     };


More information about the Libreoffice-commits mailing list