/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * Based on LLVM/Clang. * * This file is distributed under the University of Illinois Open Source * License. See LICENSE.TXT for details. *
*/
/* This is a rewriter.
Remove uses of the macro RTL_CONSTASCII_USTRINGPARAM. One run is for one specific use (see below), modify source to remove other uses.
*/
/* Remove use with the following ctor: OUString( const char * value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS ) This means searching for CXXConstructExpr. For removal when used with functions it should check e.g. for CallExpr.
*/ bool RtlConstAsciiMacro::VisitCXXConstructExpr( CXXConstructExpr* expr )
{ if( ignoreLocation( expr )) returntrue; if( expr->getNumArgs() != 4 ) returntrue; // The last argument should be the default one when the macro is used. if( dyn_cast< CXXDefaultArgExpr >( expr->getArg( 3 )) == NULL ) returntrue; if( expr->getConstructor()->getQualifiedNameAsString() != "rtl::OUString::OUString" ) returntrue; const SourceManager& src = compiler.getSourceManager();
SourceLocation start = src.getExpansionLoc( expr->getArg( 0 )->getLocStart()); // Macro fills in the first 3 arguments, so they must all come from the same expansion. if( start != src.getExpansionLoc( expr->getArg( 2 )->getLocEnd())) returntrue; if( expansions.find( start ) == expansions.end()) returntrue;
SourceLocation end = expansions[ start ]; // Remove the location, since sometimes the same code may be processed more than once // (e.g. non-trivial default arguments).
expansions.erase( start ); // Check if the string argument to the macro is suitable.
searchingForString = true;
suitableString = false;
TraverseStmt( expr->getArg( 0 ));
searchingForString = false; if( !suitableString ) returntrue; // Search for '(' (don't just remove a given length to handle possible whitespace). constchar* text = compiler.getSourceManager().getCharacterData( start ); constchar* pos = text; while( *pos != '(' )
++pos;
++pos; if( text[ -1 ] == ' ' && *pos == ' ' )
++pos; // do not leave two spaces
removeText( start, pos - text, RemoveLineIfEmpty ); constchar* textend = compiler.getSourceManager().getCharacterData( end ); if( textend[ -1 ] == ' ' && textend[ 1 ] == ' ' )
removeText( end, 2, RemoveLineIfEmpty ); // Remove ') '. else
removeText( end, 1, RemoveLineIfEmpty ); // Remove ')'. returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.