本文整理汇总了C++中QualType::getAsStringInternal方法的典型用法代码示例。如果您正苦于以下问题:C++ QualType::getAsStringInternal方法的具体用法?C++ QualType::getAsStringInternal怎么用?C++ QualType::getAsStringInternal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualType
的用法示例。
在下文中一共展示了QualType::getAsStringInternal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeLocalAsGlobalVar
bool LToGASTVisitor::makeLocalAsGlobalVar(FunctionDecl *FD,
VarDecl *LV)
{
std::string GlobalVarStr;
std::string NewName = ConsumerInstance->getNewName();
QualType T = LV->getType();
T.getAsStringInternal(NewName,
ConsumerInstance->Context->getPrintingPolicy());
GlobalVarStr = NewName;
if (LV->hasInit()) {
const Expr *InitExpr = LV->getInit();
std::string InitStr("");
ConsumerInstance->RewriteHelper->getExprString(InitExpr,
InitStr);
GlobalVarStr += " = ";
GlobalVarStr += InitStr;
}
GlobalVarStr += ";\n";
return ConsumerInstance->RewriteHelper->
insertStringBeforeFunc(FD, GlobalVarStr);
}
示例2: replaceCallExpr
void CallExprToValue::replaceCallExpr(void)
{
std::string CommaStr = "";
QualType RVQualType = TheCallExpr->getType();
const Type *RVType = RVQualType.getTypePtr();
if (RVType->isVoidType()) {
// Nothing to do
}
else if (RVType->isUnionType() || RVType->isStructureType()) {
std::string RVStr("");
RewriteHelper->getTmpTransName(NamePostfix, RVStr);
NamePostfix++;
CommaStr = RVStr;
RVQualType.getAsStringInternal(RVStr, Context->getPrintingPolicy());
RVStr += ";\n";
RewriteHelper->insertStringBeforeFunc(CurrentFD, RVStr);
}
else {
CommaStr = "0";
}
RewriteHelper->replaceExpr(TheCallExpr, CommaStr);
}
示例3: getTypeString
bool InstantiateTemplateParam::getTypeString(
const QualType &QT, std::string &Str, std::string &ForwardStr)
{
const Type *Ty = QT.getTypePtr();
Type::TypeClass TC = Ty->getTypeClass();
switch (TC) {
case Type::Elaborated: {
const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Ty);
return getTypeString(ETy->getNamedType(), Str, ForwardStr);
}
case Type::Typedef: {
const TypedefType *TdefTy = dyn_cast<TypedefType>(Ty);
const TypedefNameDecl *TdefD = TdefTy->getDecl();
return getTypeString(TdefD->getUnderlyingType(), Str, ForwardStr);
}
case Type::Record: {
RecordDeclSet TempAvailableRecordDecls;
getForwardDeclStr(Ty, ForwardStr, TempAvailableRecordDecls);
QT.getAsStringInternal(Str, Context->getPrintingPolicy());
return true;
}
case Type::Builtin: {
QT.getAsStringInternal(Str, Context->getPrintingPolicy());
return true;
}
default:
return false;
}
TransAssert(0 && "Unreachable code!");
return false;
}
示例4: addNewTmpVariable
bool BinOpSimplification::addNewTmpVariable(void)
{
QualType QT = TheBinOp->getType();
std::string VarStr;
std::stringstream SS;
unsigned int NamePostfix = NameQueryWrap->getMaxNamePostfix();
SS << RewriteHelper->getTmpVarNamePrefix() << (NamePostfix + 1);
VarStr = SS.str();
setTmpVarName(VarStr);
QT.getAsStringInternal(VarStr,
Context->getPrintingPolicy());
VarStr += ";";
return RewriteHelper->addLocalVarToFunc(VarStr, TheFuncDecl);
}
示例5: replaceCallExpr
void SimplifyCallExpr::replaceCallExpr(void)
{
std::string CommaStr("");
unsigned int NumArg = TheCallExpr->getNumArgs();
if (NumArg == 0) {
RewriteHelper->replaceExpr(TheCallExpr, CommaStr);
return;
}
const Expr *Arg = TheCallExpr->getArg(0);
std::string ArgStr;
handleOneArgStr(Arg, ArgStr);
CommaStr += ("(" + ArgStr);
for (unsigned int I = 1; I < NumArg; ++I) {
Arg = TheCallExpr->getArg(I);
handleOneArgStr(Arg, ArgStr);
CommaStr += ("," + ArgStr);
}
QualType RVQualType = TheCallExpr->getType();
const Type *RVType = RVQualType.getTypePtr();
if (RVType->isVoidType()) {
// Nothing to do
}
else if (RVType->isUnionType() || RVType->isStructureType()) {
std::string RVStr("");
RewriteHelper->getTmpTransName(NamePostfix, RVStr);
NamePostfix++;
CommaStr += ("," + RVStr);
RVQualType.getAsStringInternal(RVStr, Context->getPrintingPolicy());
RVStr += ";\n";
RewriteHelper->insertStringBeforeFunc(CurrentFD, RVStr);
}
else {
CommaStr += ",0";
}
CommaStr += ")";
RewriteHelper->replaceExpr(TheCallExpr, CommaStr);
}
示例6: addTmpVar
bool AggregateToScalar::addTmpVar(const Expr *RefE,
const std::string &VarName,
const std::string *InitStr)
{
std::string VarStr(VarName);
QualType QT = RefE->getType();
QT.getAsStringInternal(VarStr, Context->getPrintingPolicy());
if (InitStr) {
VarStr += " = ";
VarStr += (*InitStr);
}
VarStr += ";";
if (TheVarDecl->getStorageClass() == SC_Static)
VarStr = "static " + VarStr;
TransAssert(!dyn_cast<ParmVarDecl>(TheVarDecl) &&
"We don't handle ParmVarDecl!");
if (TheVarDecl->isLocalVarDecl()) {
DeclStmt *TheDeclStmt = VarDeclToDeclStmtMap[TheVarDecl];
TransAssert(TheDeclStmt && "NULL TheDeclStmt");
return RewriteHelper->addStringAfterStmt(TheDeclStmt, VarStr);
}
else {
llvm::DenseMap<const VarDecl *, DeclGroupRef>::iterator DI =
VarDeclToDeclGroupMap.find(TheVarDecl);
TransAssert((DI != VarDeclToDeclGroupMap.end()) &&
"Cannot find VarDeclGroup!");
VarDecl *LastVD = NULL;
DeclGroupRef DR = (*DI).second;
for (DeclGroupRef::iterator I = DR.begin(), E = DR.end(); I != E; ++I) {
LastVD = dyn_cast<VarDecl>(*I);
}
TransAssert(LastVD && "Bad LastVD!");
return RewriteHelper->addStringAfterVarDecl(LastVD, VarStr);
}
}
示例7: getNewTmpVariableStr
//.........这里部分代码省略.........
QT = FD->getReturnType();
return getNewTmpVariable(QT, VarStr);
}
// handle other cases where lookupDeclContext is different from
// the current CXXRecord, e.g.,
const Type *Ty = ME->getBaseType().getTypePtr();
if (const DeclContext *Ctx = getBaseDeclFromType(Ty)) {
DeclContextSet VisitedCtxs;
const FunctionDecl *FD = lookupFunctionDecl(DName, Ctx, VisitedCtxs);
if (!FD) {
return getNewTmpVariable(QT, VarStr);
}
QT = FD->getReturnType();
const Type *RVTy = QT.getTypePtr();
if (RVTy->getAs<InjectedClassNameType>()) {
// handle cases like:
// template <typename> struct D {
// D f();
// };
// template <typename T> void foo(D<T>);
// template <typename T > void bar () {
// D<T> G;
// foo(G.f());
// }
// in this case, seems it's hard to retrieve the instantiated type
// of f's return type, because `D<T> G' is dependent. I tried
// findSpecialization from ClassTemplateDecl, but it didn't work.
// So use a really ugly way, i.e., manipulating strings...
const TemplateSpecializationType *TST =
Ty->getAs<TemplateSpecializationType>();
TransAssert(TST && "Invalid TemplateSpecialization Type!");
QT.getAsStringInternal(VarStr,
Context->getPrintingPolicy());
return getVarStrForTemplateSpecialization(VarStr, TST);
}
else {
// other cases:
// template <typename> struct D {
// int f();
// };
// void foo(int);
// template <typename T > void bar () {
// D<T> G;
// foo(G.f());
// }
return getNewTmpVariable(QT, VarStr);
}
}
else {
// template <typename> struct D {
// D f();
// D operator[] (int);
// };
// template <typename T> void foo(D<T>);
// template <typename T > void bar () {
// D<T> G;
// foo(G[0].f());
// }
// In this case, G[0] is of BuiltinType.
// But why does clang represent a dependent type as BuiltinType here?
TransAssert((Ty->getAs<BuiltinType>() ||
Ty->getAs<TemplateTypeParmType>() ||
Ty->getAs<TypedefType>() ||
示例8: getNewTmpVariable
void RemoveNestedFunction::getNewTmpVariable(const QualType &QT,
std::string &VarStr)
{
QT.getAsStringInternal(VarStr, Context->getPrintingPolicy());
}