本文整理汇总了C++中QualType::getAsString方法的典型用法代码示例。如果您正苦于以下问题:C++ QualType::getAsString方法的具体用法?C++ QualType::getAsString怎么用?C++ QualType::getAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualType
的用法示例。
在下文中一共展示了QualType::getAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TraverseFunctionBody
void TraverseFunctionBody(Stmt *S, Method *m) {
// perform depth first traversal of all children
for (Stmt::child_iterator CI = S->child_begin(),
E = S->child_end(); CI != E; ++CI) {
if (*CI) TraverseFunctionBody(*CI, m);
}
// if it's a function call, register it
if (CallExpr *CE = dyn_cast<CallExpr>(S)) {
FunctionDecl *fd = CE->getDirectCallee();
if (fd != 0) {
QualType type = fd->getResultType();
std::string rtype = type.getAsString();
std::string qname = fd->getQualifiedNameAsString();
std::string param = "";
param += "(";
for (FunctionDecl::param_iterator I = fd->param_begin(),
E = fd->param_end(); I != E; ++I) {
if(ParmVarDecl *PD = dyn_cast<ParmVarDecl>(*I)) {
QualType type = PD->getType();
param += type.getAsString() + ",";
}
else assert(0); // case of interest!
}
if (param != "(") param.erase(param.end() - 1); // remove the last comma
param += ")";
std::string callee = rtype + " " + qname + param;
m->callexprs.insert(callee);
}
}
}
示例2: WriteNode
void InheritanceHierarchyWriter::WriteNode(QualType Type, bool FromVirtual) {
QualType CanonType = Context.getCanonicalType(Type);
if (FromVirtual) {
if (KnownVirtualBases.find(CanonType) != KnownVirtualBases.end())
return;
// We haven't seen this virtual base before, so display it and
// its bases.
KnownVirtualBases.insert(CanonType);
}
// Declare the node itself.
Out << " ";
WriteNodeReference(Type, FromVirtual);
// Give the node a label based on the name of the class.
std::string TypeName = Type.getAsString();
Out << " [ shape=\"box\", label=\"" << DOT::EscapeString(TypeName);
// If the name of the class was a typedef or something different
// from the "real" class name, show the real class name in
// parentheses so we don't confuse ourselves.
if (TypeName != CanonType.getAsString()) {
Out << "\\n(" << CanonType.getAsString() << ")";
}
// Finished describing the node.
Out << " \"];\n";
// Display the base classes.
const CXXRecordDecl *Decl
= static_cast<const CXXRecordDecl *>(Type->getAs<RecordType>()->getDecl());
for (CXXRecordDecl::base_class_const_iterator Base = Decl->bases_begin();
Base != Decl->bases_end(); ++Base) {
QualType CanonBaseType = Context.getCanonicalType(Base->getType());
// If this is not virtual inheritance, bump the direct base
// count for the type.
if (!Base->isVirtual())
++DirectBaseCount[CanonBaseType];
// Write out the node (if we need to).
WriteNode(Base->getType(), Base->isVirtual());
// Write out the edge.
Out << " ";
WriteNodeReference(Type, FromVirtual);
Out << " -> ";
WriteNodeReference(Base->getType(), Base->isVirtual());
// Write out edge attributes to show the kind of inheritance.
if (Base->isVirtual()) {
Out << " [ style=\"dashed\" ]";
}
Out << ";";
}
}
示例3: isNewType
bool FFIBindingsUtils::isNewType(QualType Type) {
if (isInResolvedDecls(Type.getAsString())) {
return false;
}
if (isInUnresolvedDeclarations(Type.getAsString())) {
return false;
}
return true;
}
示例4: VisitDecl
void FunctionArgsByRef::VisitDecl(Decl *decl)
{
FunctionDecl *functionDecl = dyn_cast<FunctionDecl>(decl);
if (functionDecl == nullptr || !functionDecl->hasBody() || shouldIgnoreFunction(functionDecl->getNameAsString())
|| !functionDecl->isThisDeclarationADefinition()) return;
Stmt *body = functionDecl->getBody();
for (auto it = functionDecl->param_begin(), end = functionDecl->param_end(); it != end; ++it) {
const ParmVarDecl *param = *it;
QualType paramQt = param->getType();
const Type *paramType = paramQt.getTypePtrOrNull();
if (paramType == nullptr || paramType->isDependentType())
continue;
const int size_of_T = m_ci.getASTContext().getTypeSize(paramQt) / 8;
const bool isSmall = size_of_T <= 16; // TODO: What about arm ?
CXXRecordDecl *recordDecl = paramType->getAsCXXRecordDecl();
const bool isUserNonTrivial = recordDecl && (recordDecl->hasUserDeclaredCopyConstructor() || recordDecl->hasUserDeclaredDestructor());
const bool isReference = paramType->isLValueReferenceType();
const bool isConst = paramQt.isConstQualified();
if (recordDecl && shouldIgnoreClass(recordDecl->getQualifiedNameAsString()))
continue;
std::string error;
if (isConst && !isReference) {
if (!isSmall) {
error += warningMsgForSmallType(size_of_T, paramQt.getAsString());
} else if (isUserNonTrivial) {
error += "Missing reference on non-trivial type " + recordDecl->getQualifiedNameAsString();
}
} else if (isConst && isReference && !isUserNonTrivial && isSmall) {
//error += "Don't use by-ref on small trivial type";
} else if (!isConst && !isReference && (!isSmall || isUserNonTrivial)) {
if (Utils::containsNonConstMemberCall(body, param) || Utils::containsCallByRef(body, param))
continue;
if (!isSmall) {
error += warningMsgForSmallType(size_of_T, paramQt.getAsString());
} else if (isUserNonTrivial) {
error += "Missing reference on non-trivial type " + recordDecl->getQualifiedNameAsString();
}
}
if (!error.empty()) {
emitWarning(param->getLocStart(), error.c_str());
}
}
}
示例5: VisitFunctionDecl
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
Stmt *FuncBody = f->getBody();
// Type name as string
QualType QT = f->getResultType();
string TypeStr = QT.getAsString();
// Function name
DeclarationName DeclName = f->getNameInfo().getName();
string FuncName = DeclName.getAsString();
// Add comment before
stringstream SSBefore;
SSBefore << "// Begin function " << FuncName << " returning "
<< TypeStr << "\n";
SourceLocation ST = f->getSourceRange().getBegin();
TheRewriter.InsertText(ST, SSBefore.str(), true, true);
// And after
stringstream SSAfter;
SSAfter << "\n// End function " << FuncName << "\n";
ST = FuncBody->getLocEnd().getLocWithOffset(1);
TheRewriter.InsertText(ST, SSAfter.str(), true, true);
}
return true;
}
示例6: HandleRecordDecl
Record* HandleRecordDecl(CXXRecordDecl *D) {
assert(D && "Class missing in HandleRecordDecl");
if (!D->hasDefinition())
return NULL;
// skip duplication
if(records.find(D->getQualifiedNameAsString()) != records.end()) return 0;
Record *r = new Record;
r->qualifiedname = D->getQualifiedNameAsString();
//find all base classes
//we skip all the template classes or there will be Assertion failed
if (!D->getDescribedClassTemplate ()) {
for (CXXRecordDecl::base_class_iterator iter = D->bases_begin();
iter != D->bases_end(); ++iter) {
if (iter) {
QualType type = iter->getType();
std::string tmp = type.getAsString();
//remove "class "
tmp.erase(0, 6);
r->bases.insert(tmp);
}
}
}
return r;
}
示例7: OS
std::shared_ptr<PathDiagnosticPiece>
InnerPointerChecker::InnerPointerBRVisitor::VisitNode(const ExplodedNode *N,
BugReporterContext &BRC,
BugReport &) {
if (!isSymbolTracked(N->getState(), PtrToBuf) ||
isSymbolTracked(N->getFirstPred()->getState(), PtrToBuf))
return nullptr;
const Stmt *S = PathDiagnosticLocation::getStmt(N);
if (!S)
return nullptr;
const MemRegion *ObjRegion =
allocation_state::getContainerObjRegion(N->getState(), PtrToBuf);
const auto *TypedRegion = cast<TypedValueRegion>(ObjRegion);
QualType ObjTy = TypedRegion->getValueType();
SmallString<256> Buf;
llvm::raw_svector_ostream OS(Buf);
OS << "Pointer to inner buffer of '" << ObjTy.getAsString()
<< "' obtained here";
PathDiagnosticLocation Pos(S, BRC.getSourceManager(),
N->getLocationContext());
return std::make_shared<PathDiagnosticEventPiece>(Pos, OS.str(), true,
nullptr);
}
示例8: viewInheritance
/// viewInheritance - Display the inheritance hierarchy of this C++
/// class using GraphViz.
void CXXRecordDecl::viewInheritance(ASTContext& Context) const {
QualType Self = Context.getTypeDeclType(this);
std::string ErrMsg;
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
if (Filename.isEmpty()) {
llvm::errs() << "Error: " << ErrMsg << "\n";
return;
}
Filename.appendComponent(Self.getAsString() + ".dot");
if (Filename.makeUnique(true,&ErrMsg)) {
llvm::errs() << "Error: " << ErrMsg << "\n";
return;
}
llvm::errs() << "Writing '" << Filename.c_str() << "'... ";
llvm::raw_fd_ostream O(Filename.c_str(), ErrMsg);
if (ErrMsg.empty()) {
InheritanceHierarchyWriter Writer(Context, O);
Writer.WriteGraph(Self);
llvm::errs() << " done. \n";
O.close();
// Display the graph
DisplayGraph(Filename);
} else {
llvm::errs() << "error opening file for writing!\n";
}
}
示例9: getPrettyTypeName
/// If type represents a pointer to CXXRecordDecl,
/// and is not a typedef, return the decl name.
/// Otherwise, return the serialization of type.
static std::string getPrettyTypeName(QualType QT) {
QualType PT = QT->getPointeeType();
if (!PT.isNull() && !QT->getAs<TypedefType>())
if (const auto *RD = PT->getAsCXXRecordDecl())
return RD->getName();
return QT.getAsString();
}
示例10: getTypeName
std::string getTypeName(QualType qualType, bool qualifyNames)
{
auto langOptions = clang::LangOptions{};
auto printPolicy = PrintingPolicy{ langOptions };
printPolicy.SuppressSpecifiers = false;
printPolicy.ConstantArraySizeAsWritten = false;
return qualType.getAsString(printPolicy);
}
示例11: getFullyQualifiedName
std::string getFullyQualifiedName(QualType QT,
const ASTContext &Ctx) {
PrintingPolicy Policy(Ctx.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = false;
Policy.PolishForDeclaration = true;
Policy.SuppressUnwrittenScope = true;
QualType FQQT = getFullyQualifiedType(QT, Ctx);
return FQQT.getAsString(Policy);
}
示例12: HandleFunctionDecl
// handle method declaration
Method* HandleFunctionDecl(CXXMethodDecl *MD) {
assert(MD && "method handle missing in HandleFunctionDecl");
if (methods.find(MD->getQualifiedNameAsString()) != methods.end()) return 0;
Method *m = new Method();
m->qualifiedname = MD->getQualifiedNameAsString();
QualType type = MD->getResultType();
m->rtype = type.getAsString();
// get function paramters
for (FunctionDecl::param_iterator I = MD->param_begin(),
E = MD->param_end(); I != E; ++I) {
//llvm::errs() << "Function: " + FD->getNameAsString() <<" params number: " << FD->param_size () << "\"\n";
if(ParmVarDecl *PD = dyn_cast<ParmVarDecl>(*I)) {
QualType type = PD->getType();
m->params.push_back(type.getAsString());
}
else assert(0); // case of interest!
}
//find all function calls and variables declaration in function body
if (MD->hasBody()) {
Stmt* body = MD->getBody();
TraverseFunctionBody(body, m);
}
CXXRecordDecl *RD;
RD = MD->getParent();
m->parentclass = RD->getQualifiedNameAsString();
//check __attribute__ ((annotate("ssf_starting_procedure")))
if (MD->getAttr<AnnotateAttr>()) {
//llvm::errs() << MD->getName() << " has annotate attribute\n";
m->hasAttri = true;
}
m->filename = inFile;
return m;
}
示例13: doConversion
//// \brief Apply the source transformations necessary to migrate the loop!
void LoopFixer::doConversion(ASTContext *Context,
const VarDecl *IndexVar,
const VarDecl *MaybeContainer,
StringRef ContainerString,
const UsageResult &Usages,
const DeclStmt *AliasDecl, const ForStmt *TheLoop,
bool ContainerNeedsDereference) {
std::string VarName;
if (Usages.size() == 1 && AliasDecl) {
const VarDecl *AliasVar = cast<VarDecl>(AliasDecl->getSingleDecl());
VarName = AliasVar->getName().str();
// We keep along the entire DeclStmt to keep the correct range here.
const SourceRange &ReplaceRange = AliasDecl->getSourceRange();
if (!CountOnly)
Replace->insert(
Replacement(Context->getSourceManager(),
CharSourceRange::getTokenRange(ReplaceRange), ""));
// No further replacements are made to the loop, since the iterator or index
// was used exactly once - in the initialization of AliasVar.
} else {
VariableNamer Namer(GeneratedDecls, &ParentFinder->getStmtToParentStmtMap(),
TheLoop, IndexVar, MaybeContainer);
VarName = Namer.createIndexName();
// First, replace all usages of the array subscript expression with our new
// variable.
for (UsageResult::const_iterator I = Usages.begin(), E = Usages.end();
I != E; ++I) {
std::string ReplaceText = I->IsArrow ? VarName + "." : VarName;
ReplacedVarRanges->insert(std::make_pair(TheLoop, IndexVar));
if (!CountOnly)
Replace->insert(
Replacement(Context->getSourceManager(),
CharSourceRange::getTokenRange(I->Range),
ReplaceText));
}
}
// Now, we need to construct the new range expresion.
SourceRange ParenRange(TheLoop->getLParenLoc(), TheLoop->getRParenLoc());
QualType AutoRefType =
Context->getLValueReferenceType(Context->getAutoDeductType());
std::string MaybeDereference = ContainerNeedsDereference ? "*" : "";
std::string TypeString = AutoRefType.getAsString();
std::string Range = ("(" + TypeString + " " + VarName + " : "
+ MaybeDereference + ContainerString + ")").str();
if (!CountOnly)
Replace->insert(Replacement(Context->getSourceManager(),
CharSourceRange::getTokenRange(ParenRange),
Range));
GeneratedDecls->insert(make_pair(TheLoop, VarName));
}
示例14: PrevTy
/// \brief Convert the given type to a string suitable for printing as part of
/// a diagnostic.
///
/// There are three main criteria when determining whether we should have an
/// a.k.a. clause when pretty-printing a type:
///
/// 1) Some types provide very minimal sugar that doesn't impede the
/// user's understanding --- for example, elaborated type
/// specifiers. If this is all the sugar we see, we don't want an
/// a.k.a. clause.
/// 2) Some types are technically sugared but are much more familiar
/// when seen in their sugared form --- for example, va_list,
/// vector types, and the magic Objective C types. We don't
/// want to desugar these, even if we do produce an a.k.a. clause.
/// 3) Some types may have already been desugared previously in this diagnostic.
/// if this is the case, doing another "aka" would just be clutter.
///
/// \param Context the context in which the type was allocated
/// \param Ty the type to print
static std::string
ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty,
const Diagnostic::ArgumentValue *PrevArgs,
unsigned NumPrevArgs) {
// FIXME: Playing with std::string is really slow.
std::string S = Ty.getAsString(Context.PrintingPolicy);
// Check to see if we already desugared this type in this
// diagnostic. If so, don't do it again.
bool Repeated = false;
for (unsigned i = 0; i != NumPrevArgs; ++i) {
// TODO: Handle ak_declcontext case.
if (PrevArgs[i].first == Diagnostic::ak_qualtype) {
void *Ptr = (void*)PrevArgs[i].second;
QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
if (PrevTy == Ty) {
Repeated = true;
break;
}
}
}
// Consider producing an a.k.a. clause if removing all the direct
// sugar gives us something "significantly different".
if (!Repeated) {
bool ShouldAKA = false;
QualType DesugaredTy = Desugar(Context, Ty, ShouldAKA);
if (ShouldAKA) {
std::string D = DesugaredTy.getAsString(Context.PrintingPolicy);
if (D != S) {
S = "'" + S + "' (aka '";
S += D;
S += "')";
return S;
}
}
}
S = "'" + S + "'";
return S;
}
示例15:
/// \brief Convert the given type to a string suitable for printing as part of
/// a diagnostic.
///
/// \param Context the context in which the type was allocated
/// \param Ty the type to print
static std::string
ConvertTypeToDiagnosticString(ASTContext &Context, QualType Ty,
const Diagnostic::ArgumentValue *PrevArgs,
unsigned NumPrevArgs) {
// FIXME: Playing with std::string is really slow.
std::string S = Ty.getAsString(Context.PrintingPolicy);
// Consider producing an a.k.a. clause if removing all the direct
// sugar gives us something "significantly different".
QualType DesugaredTy;
if (ShouldAKA(Context, Ty, PrevArgs, NumPrevArgs, DesugaredTy)) {
S = "'"+S+"' (aka '";
S += DesugaredTy.getAsString(Context.PrintingPolicy);
S += "')";
return S;
}
S = "'" + S + "'";
return S;
}