/* -*- 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.
Replaces all calls to the deprecated O(U)String::valueOf() .
bool ConvertValueOf::VisitCallExpr( const CallExpr* call )
{ if( ignoreLocation( call )) returntrue; // Using getDirectCallee() here means that we find only calls // that call the function directly (i.e. not using a pointer, for example). // Use getCallee() to include also those : // if( const FunctionDecl* func = dyn_cast_or_null< FunctionDecl >( call->getCalleeDecl())) if( const FunctionDecl* func = call->getDirectCallee())
{ // Optimize, getQualifiedNameAsString() is reportedly expensive, // so first check fast details like number of arguments or the (unqualified) // name before checking the fully qualified name. // See FunctionDecl for all the API about the function. if( func->getIdentifier() != NULL
&& ( func->getName() == "valueOf" ))
{
string qualifiedName = func->getQualifiedNameAsString(); if( qualifiedName == "rtl::OString::valueOf" )
{ // Further checks about arguments. Check mainly ParmVarDecl, VarDecl, // ValueDecl and QualType for Clang API details.
string arg0 = func->getParamDecl( 0 )->getType().getAsString(); if( arg0 == "sal_Bool" )
replaceText( call->getCallee()->getSourceRange(), "OString::boolean" ); else
{
replaceText( call->getCallee()->getSourceRange(), "OString::number" );
removeCast( call->getArg( 0 ));
}
} if( qualifiedName == "rtl::OUString::valueOf" )
{ // Further checks about arguments. Check mainly ParmVarDecl, VarDecl, // ValueDecl and QualType for Clang API details.
string arg0 = func->getParamDecl( 0 )->getType().getAsString(); if( arg0 == "sal_Bool" )
replaceText( call->getCallee()->getSourceRange(), "OUString::boolean" ); elseif( arg0 == "sal_Unicode" )
replaceText( call->getCallee()->getSourceRange(), "OUString" ); else
{
replaceText( call->getCallee()->getSourceRange(), "OUString::number" );
removeCast( call->getArg( 0 ));
}
}
}
} 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.