• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TypeLoc类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中TypeLoc的典型用法代码示例。如果您正苦于以下问题:C++ TypeLoc类的具体用法?C++ TypeLoc怎么用?C++ TypeLoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TypeLoc类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: TransAssert

bool RemoveNamespaceRewriteVisitor::VisitClassTemplatePartialSpecializationDecl(
       ClassTemplatePartialSpecializationDecl *D)
{
  const Type *Ty = D->getInjectedSpecializationType().getTypePtr();
  TransAssert(Ty && "Bad TypePtr!");
  const TemplateSpecializationType *TST =
    dyn_cast<TemplateSpecializationType>(Ty);
  TransAssert(TST && "Bad TemplateSpecializationType!");

  TemplateName TplName = TST->getTemplateName();
  const TemplateDecl *TplD = TplName.getAsTemplateDecl();
  TransAssert(TplD && "Invalid TemplateDecl!");
  NamedDecl *ND = TplD->getTemplatedDecl();
  TransAssert(ND && "Invalid NamedDecl!");

  const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(ND);
  TransAssert(CXXRD && "Invalid CXXRecordDecl!");

  std::string Name;
  if (ConsumerInstance->getNewName(CXXRD, Name)) {
    const TypeSourceInfo *TyInfo = D->getTypeAsWritten();
    if (!TyInfo)
      return true;
    TypeLoc TyLoc = TyInfo->getTypeLoc();
    SourceLocation LocStart = TyLoc.getBeginLoc();
    TransAssert(LocStart.isValid() && "Invalid Location!");
    ConsumerInstance->TheRewriter.ReplaceText(
      LocStart, CXXRD->getNameAsString().size(), Name);
  }
  return true;
}
开发者ID:csmith-project,项目名称:creduce,代码行数:31,代码来源:RemoveNamespace.cpp


示例2: while

SourceLocation TypeLoc::getEndLoc() const {
  TypeLoc Cur = *this;
  TypeLoc Last;
  while (true) {
    switch (Cur.getTypeLocClass()) {
    default:
      if (!Last)
	Last = Cur;
      return Last.getLocalSourceRange().getEnd();
    case Paren:
    case ConstantArray:
    case DependentSizedArray:
    case IncompleteArray:
    case VariableArray:
    case FunctionProto:
    case FunctionNoProto:
      Last = Cur;
      break;
    case Pointer:
    case BlockPointer:
    case MemberPointer:
    case LValueReference:
    case RValueReference:
    case PackExpansion:
      if (!Last)
	Last = Cur;
      break;
    case Qualified:
    case Elaborated:
      break;
    }
    Cur = Cur.getNextTypeLoc();
  }
}
开发者ID:avakar,项目名称:clang,代码行数:34,代码来源:TypeLoc.cpp


示例3: isEnumRawType

 static bool isEnumRawType(const Decl* D, TypeLoc TL) {
   assert (TL.getType());
   if (auto ED = dyn_cast<EnumDecl>(D)) {
     return ED->hasRawType() && ED->getRawType()->isEqual(TL.getType());
   }
   return false;
 }
开发者ID:frsoares,项目名称:swift,代码行数:7,代码来源:IDETypeChecking.cpp


示例4: isNonVoidReturnFunction

bool ReturnVoid::isNonVoidReturnFunction(FunctionDecl *FD)
{
  // Avoid duplications
  if (std::find(ValidFuncDecls.begin(), 
                ValidFuncDecls.end(), FD) != 
      ValidFuncDecls.end())
    return false;

  // this function happen to have a library function, e.g. strcpy,
  // then the type source info won't be available, let's try to
  // get one from the one which is in the source
  if (!FD->getTypeSourceInfo()) {
    const FunctionDecl *FirstFD = FD->getFirstDeclaration();
    FD = NULL;
    for (FunctionDecl::redecl_iterator I = FirstFD->redecls_begin(), 
         E = FirstFD->redecls_end(); I != E; ++I) {
      if ((*I)->getTypeSourceInfo()) {
        FD = (*I);
        break;
      }
    }
    if (!FD)
      return false;
  }
  TypeLoc TLoc = FD->getTypeSourceInfo()->getTypeLoc();
  SourceLocation SLoc = TLoc.getBeginLoc();
  if (SLoc.isInvalid())
    return false;
  QualType RVType = FD->getResultType();
  return !(RVType.getTypePtr()->isVoidType());
}
开发者ID:grimreaper,项目名称:creduce,代码行数:31,代码来源:ReturnVoid.cpp


示例5: assert

TemplateArgumentLoc
Sema::getTemplateArgumentPackExpansionPattern(
      TemplateArgumentLoc OrigLoc,
      SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
  const TemplateArgument &Argument = OrigLoc.getArgument();
  assert(Argument.isPackExpansion());
  switch (Argument.getKind()) {
  case TemplateArgument::Type: {
    // FIXME: We shouldn't ever have to worry about missing
    // type-source info!
    TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
    if (!ExpansionTSInfo)
      ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
                                                         Ellipsis);
    PackExpansionTypeLoc Expansion =
        ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
    Ellipsis = Expansion.getEllipsisLoc();

    TypeLoc Pattern = Expansion.getPatternLoc();
    NumExpansions = Expansion.getTypePtr()->getNumExpansions();

    // We need to copy the TypeLoc because TemplateArgumentLocs store a
    // TypeSourceInfo.
    // FIXME: Find some way to avoid the copy?
    TypeLocBuilder TLB;
    TLB.pushFullCopy(Pattern);
    TypeSourceInfo *PatternTSInfo =
        TLB.getTypeSourceInfo(Context, Pattern.getType());
    return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
                               PatternTSInfo);
  }

  case TemplateArgument::Expression: {
    PackExpansionExpr *Expansion
      = cast<PackExpansionExpr>(Argument.getAsExpr());
    Expr *Pattern = Expansion->getPattern();
    Ellipsis = Expansion->getEllipsisLoc();
    NumExpansions = Expansion->getNumExpansions();
    return TemplateArgumentLoc(Pattern, Pattern);
  }

  case TemplateArgument::TemplateExpansion:
    Ellipsis = OrigLoc.getTemplateEllipsisLoc();
    NumExpansions = Argument.getNumTemplateExpansions();
    return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
                               OrigLoc.getTemplateQualifierLoc(),
                               OrigLoc.getTemplateNameLoc());

  case TemplateArgument::Declaration:
  case TemplateArgument::NullPtr:
  case TemplateArgument::Template:
  case TemplateArgument::Integral:
  case TemplateArgument::Pack:
  case TemplateArgument::Null:
    return TemplateArgumentLoc();
  }

  llvm_unreachable("Invalid TemplateArgument Kind!");
}
开发者ID:hsorby,项目名称:opencor,代码行数:59,代码来源:SemaTemplateVariadic.cpp


示例6: processLambdaExpr

void RedundantVoidArgCheck::processLambdaExpr(
    const MatchFinder::MatchResult &Result, const LambdaExpr *Lambda) {
  if (Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0 &&
      Lambda->hasExplicitParameters()) {
    SourceManager *SM = Result.SourceManager;
    TypeLoc TL = Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
    removeVoidArgumentTokens(Result,
                             {SM->getSpellingLoc(TL.getBeginLoc()),
                              SM->getSpellingLoc(TL.getEndLoc())},
                             "lambda expression");
  }
}
开发者ID:llvm-mirror,项目名称:clang-tools-extra,代码行数:12,代码来源:RedundantVoidArgCheck.cpp


示例7: extendedTypeIsPrivate

static bool extendedTypeIsPrivate(TypeLoc inheritedType) {
  if (!inheritedType.getType())
    return true;

  SmallVector<ProtocolDecl *, 2> protocols;
  if (!inheritedType.getType()->isAnyExistentialType(protocols)) {
    // Be conservative. We don't know how to deal with other extended types.
    return false;
  }

  return std::all_of(protocols.begin(), protocols.end(), declIsPrivate);
}
开发者ID:AaronPelzer,项目名称:swift,代码行数:12,代码来源:frontend_main.cpp


示例8: revertDependentTypeLoc

static void revertDependentTypeLoc(TypeLoc &tl) {
  // If there's no type representation, there's nothing to revert.
  if (!tl.getTypeRepr())
    return;

  // Don't revert an error type; we've already complained.
  if (tl.wasValidated() && tl.isError())
    return;

  // Make sure we validate the type again.
  tl.setType(Type());
}
开发者ID:frsoares,项目名称:swift,代码行数:12,代码来源:TypeCheckGeneric.cpp


示例9: VisitValueDecl

void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
  VisitValueDecl(DD);
  QualType InfoTy = Reader.GetType(Record[Idx++]);
  if (InfoTy.isNull())
    return;

  DeclaratorInfo *DInfo = Reader.getContext()->CreateDeclaratorInfo(InfoTy);
  TypeLocReader TLR(Reader, Record, Idx);
  for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
    TLR.Visit(TL);
  DD->setDeclaratorInfo(DInfo);
}
开发者ID:Killfrra,项目名称:llvm-kernel,代码行数:12,代码来源:PCHReaderDecl.cpp


示例10: Extend

void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context, 
                                           SourceLocation TemplateKWLoc, 
                                           TypeLoc TL, 
                                           SourceLocation ColonColonLoc) {
  Representation = NestedNameSpecifier::Create(Context, Representation, 
                                               TemplateKWLoc.isValid(), 
                                               TL.getTypePtr());
  
  // Push source-location info into the buffer.
  SavePointer(TL.getOpaqueData(), Buffer, BufferSize, BufferCapacity);
  SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
}
开发者ID:gwelymernans,项目名称:lfort,代码行数:12,代码来源:NestedNameSpecifier.cpp


示例11: diag

void PassByValueCheck::check(const MatchFinder::MatchResult &Result) {
  const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("Ctor");
  const auto *ParamDecl = Result.Nodes.getNodeAs<ParmVarDecl>("Param");
  const auto *Initializer =
      Result.Nodes.getNodeAs<CXXCtorInitializer>("Initializer");
  SourceManager &SM = *Result.SourceManager;

  // If the parameter is used or anything other than the copy, do not apply
  // the changes.
  if (!paramReferredExactlyOnce(Ctor, ParamDecl))
    return;

  // If the parameter is trivial to copy, don't move it. Moving a trivivally
  // copyable type will cause a problem with misc-move-const-arg
  if (ParamDecl->getType().isTriviallyCopyableType(*Result.Context)) 
    return;

  auto Diag = diag(ParamDecl->getLocStart(), "pass by value and use std::move");

  // Iterate over all declarations of the constructor.
  for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
    auto ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
    auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();

    // Do not replace if it is already a value, skip.
    if (RefTL.isNull())
      continue;

    TypeLoc ValueTL = RefTL.getPointeeLoc();
    auto TypeRange = CharSourceRange::getTokenRange(ParmDecl->getLocStart(),
                                                    ParamTL.getLocEnd());
    std::string ValueStr =
        Lexer::getSourceText(
            CharSourceRange::getTokenRange(ValueTL.getSourceRange()), SM,
            Result.Context->getLangOpts())
            .str();
    ValueStr += ' ';
    Diag << FixItHint::CreateReplacement(TypeRange, ValueStr);
  }

  // Use std::move in the initialization list.
  Diag << FixItHint::CreateInsertion(Initializer->getRParenLoc(), ")")
       << FixItHint::CreateInsertion(
              Initializer->getLParenLoc().getLocWithOffset(1), "std::move(");

  if (auto IncludeFixit = Inserter->CreateIncludeInsertion(
          Result.SourceManager->getFileID(Initializer->getSourceLocation()),
          "utility",
          /*IsAngled=*/true)) {
    Diag << *IncludeFixit;
  }
}
开发者ID:bbannier,项目名称:clang-tools-extra-1,代码行数:52,代码来源:PassByValueCheck.cpp


示例12: TransAssert

bool EmptyStructToIntRewriteVisitor::VisitElaboratedTypeLoc(
       ElaboratedTypeLoc Loc)
{
  const ElaboratedType *ETy = dyn_cast<ElaboratedType>(Loc.getTypePtr());
  const Type *NamedTy = ETy->getNamedType().getTypePtr();
  const RecordType *RDTy = NamedTy->getAs<RecordType>();
  if (!RDTy)
    return true;

  const RecordDecl *RD = RDTy->getDecl();
  TransAssert(RD && "NULL RecordDecl!");
  if (RD->getCanonicalDecl() != ConsumerInstance->TheRecordDecl) {
    return true;
  }

  SourceLocation StartLoc = Loc.getLocStart();
  if (StartLoc.isInvalid())
    return true;
  TypeLoc TyLoc = Loc.getNamedTypeLoc();
  SourceLocation EndLoc = TyLoc.getLocStart();
  if (EndLoc.isInvalid())
    return true;
  EndLoc = EndLoc.getLocWithOffset(-1);
  const char *StartBuf = 
    ConsumerInstance->SrcManager->getCharacterData(StartLoc);
  const char *EndBuf = ConsumerInstance->SrcManager->getCharacterData(EndLoc);
  ConsumerInstance->Rewritten = true;
  // It's possible, e.g., 
  // struct S1 {
  //   struct { } S;
  // };
  // Clang will translate struct { } S to
  // struct {
  // };
  //  struct <anonymous struct ...> S;
  // the last declaration is injected by clang.
  // We need to omit it.
  if (StartBuf > EndBuf) {
    SourceLocation KeywordLoc = Loc.getElaboratedKeywordLoc();
    const llvm::StringRef Keyword = 
      TypeWithKeyword::getKeywordName(ETy->getKeyword());
    ConsumerInstance->TheRewriter.ReplaceText(KeywordLoc, 
                                              Keyword.size(), "int");
    return true;
  }
  
  ConsumerInstance->TheRewriter.RemoveText(SourceRange(StartLoc, EndLoc));
  return true;
}
开发者ID:marxin,项目名称:creduce,代码行数:49,代码来源:EmptyStructToInt.cpp


示例13: while

SourceLocation TypeLoc::getEndLoc() const {
  TypeLoc Cur = *this;
  while (true) {
    switch (Cur.getTypeLocClass()) {
    default:
      break;
    case Qualified:
    case Elaborated:
      Cur = Cur.getNextTypeLoc();
      continue;
    }
    break;
  }
  return Cur.getLocalSourceRange().getEnd();
}
开发者ID:colgur,项目名称:clang,代码行数:15,代码来源:TypeLoc.cpp


示例14: run

    virtual void run(const MatchFinder::MatchResult &Result) {
        auto *d = Result.Nodes.getNodeAs<CXXConstructorDecl>("stuff");
        if (d) {
            if (d->getNumCtorInitializers() > 0) {
                const CXXCtorInitializer *firstinit = *d->init_begin();
                if (!firstinit->isWritten()) {
                    llvm::errs() << "firstinit not written; skipping\n";
                    return;
                }
                if (firstinit->isBaseInitializer()) {
                    TypeLoc basetypeloc = firstinit->getBaseClassLoc();
                    llvm::errs() << "firstinit as base loc: "
                                 << basetypeloc.getBeginLoc().printToString(
                                     *Result.SourceManager) << "\n";
                }
                SourceLocation initloc = firstinit->getSourceLocation();
                llvm::errs() << "firstinit loc: "
                             << initloc.printToString(*Result.SourceManager) << "\n";
                SourceRange initrange = firstinit->getSourceRange();
                llvm::errs() << "firstinit range from "
                             << initrange.getBegin().printToString(
                                 *Result.SourceManager) << "\n";
                llvm::errs() << "firstinit range to "
                             << initrange.getEnd().printToString(
                                 *Result.SourceManager) << "\n";

                SourceLocation start = firstinit->getLParenLoc();
                llvm::errs() << "firstinit start: "
                             << start.printToString(*Result.SourceManager) << "\n";
                Token tok_id = GetTokenBeforeLocation(start, *Result.Context);
                llvm::errs() << "  tok_id: "
                             << tok_id.getLocation().printToString(
                                 *Result.SourceManager) << "\n";
                Token tok_colon =
                    GetTokenBeforeLocation(tok_id.getLocation(), *Result.Context);
                llvm::errs() << "  tok_colon: "
                             << tok_colon.getLocation().printToString(
                                 *Result.SourceManager) << "\n";

                const CXXCtorInitializer *lastinit = *d->init_rbegin();
                SourceLocation end = lastinit->getRParenLoc();
                llvm::errs() << "lastinit end: "
                             << end.printToString(*Result.SourceManager) << "\n";
                //init->getInit()->dump();
            }
        }
    }
开发者ID:hfeeki,项目名称:llvm-clang-samples,代码行数:47,代码来源:try_matcher.cpp


示例15: switch

void ObjCMigrateASTConsumer::migrateMethodInstanceType(ASTContext &Ctx,
                                                       ObjCContainerDecl *CDecl,
                                                       ObjCMethodDecl *OM) {
  ObjCInstanceTypeFamily OIT_Family =
    Selector::getInstTypeMethodFamily(OM->getSelector());
  if (OIT_Family == OIT_None)
    return;
  // TODO. Many more to come
  switch (OIT_Family) {
    case OIT_Array:
      break;
    case OIT_Dictionary:
      break;
    default:
      return;
  }
  if (!OM->getResultType()->isObjCIdType())
    return;
  
  ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
  if (!IDecl) {
    if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(CDecl))
      IDecl = CatDecl->getClassInterface();
    else if (ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(CDecl))
      IDecl = ImpDecl->getClassInterface();
  }
  if (!IDecl)
    return;
  
  if (OIT_Family ==  OIT_Array &&
      !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSArray")))
    return;
  else if (OIT_Family == OIT_Dictionary &&
           !IDecl->lookupInheritedClass(&Ctx.Idents.get("NSDictionary")))
    return;
  
  TypeSourceInfo *TSInfo =  OM->getResultTypeSourceInfo();
  TypeLoc TL = TSInfo->getTypeLoc();
  SourceRange R = SourceRange(TL.getBeginLoc(), TL.getEndLoc());
  edit::Commit commit(*Editor);
  std::string ClassString = "instancetype";
  commit.replace(R, ClassString);
  Editor->commit(commit);
}
开发者ID:nonstriater,项目名称:clang,代码行数:44,代码来源:ObjCMT.cpp


示例16: Extend

void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, 
                          TypeLoc TL, SourceLocation ColonColonLoc) {
  Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc);
  if (Range.getBegin().isInvalid())
    Range.setBegin(TL.getBeginLoc());
  Range.setEnd(ColonColonLoc);

  assert(Range == Builder.getSourceRange() &&
         "NestedNameSpecifierLoc range computation incorrect");
}
开发者ID:apurtell,项目名称:llvm-clang,代码行数:10,代码来源:DeclSpec.cpp


示例17: while

SourceLocation RewriteUtils::getVarDeclTypeLocEnd(const VarDecl *VD)
{
  TypeLoc VarTypeLoc = VD->getTypeSourceInfo()->getTypeLoc();
  const IdentifierInfo *Id = VD->getType().getBaseTypeIdentifier();

  // handle a special case shown as below:
  // x;
  // *y[];
  // (*z)[];
  // void foo(void) {...}
  // where x implicitly has type of int, whereas y has type of int *
  if (!Id) {
    SourceLocation EndLoc = VD->getLocation();
    const char *Buf = SrcManager->getCharacterData(EndLoc);
    int Offset = -1;
    SourceLocation NewEndLoc = EndLoc.getLocWithOffset(Offset);
    if (!NewEndLoc.isValid())
      return EndLoc;

    Buf--;
    while (isspace(*Buf) || (*Buf == '*') || (*Buf == '(')) {
      Offset--;
      NewEndLoc = EndLoc.getLocWithOffset(Offset);
      if (!NewEndLoc.isValid())
        return EndLoc.getLocWithOffset(Offset+1);

      Buf--;
    }
    return EndLoc.getLocWithOffset(Offset+1);
  }

  TypeLoc NextTL = VarTypeLoc.getNextTypeLoc();
  while (!NextTL.isNull()) {
    VarTypeLoc = NextTL;
    NextTL = NextTL.getNextTypeLoc();
  }

  SourceRange TypeLocRange = VarTypeLoc.getSourceRange();
  SourceLocation EndLoc = getEndLocationFromBegin(TypeLocRange);
  TransAssert(EndLoc.isValid() && "Invalid EndLoc!");

  const Type *Ty = VarTypeLoc.getTypePtr();

  // I am not sure why, but for a declaration like below:
  //   unsigned int a; (or long long a;)
  // TypeLoc.getBeginLoc() returns the position of 'u'
  // TypeLoc.getEndLoc() also returns the position of 'u'
  // The size of TypeLoc.getSourceRange() is 8, which is the 
  // length of "unsigned"
  // Then we are getting trouble, because now EndLoc is right 
  // after 'd', but we need it points to the location after "int".
  // skipPossibleTypeRange corrects the above deviation
  // Or am I doing something horrible here?
  EndLoc = skipPossibleTypeRange(Ty, EndLoc, VD->getLocation());
  return EndLoc;
}
开发者ID:annulen,项目名称:creduce,代码行数:56,代码来源:RewriteUtils.cpp


示例18: passRelatedType

bool IndexSwiftASTWalker::passRelatedType(const TypeLoc &Ty) {
  if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
    auto Comps = T->getComponentRange();
    if (auto NTD = dyn_cast_or_null<NominalTypeDecl>(
                     Comps.back()->getBoundDecl())) {
      if (!passRelated(NTD, Comps.back()->getIdLoc()))
        return false;
    }

    return true;
  }

  if (Ty.getType()) {
    if (auto nominal = dyn_cast_or_null<NominalTypeDecl>(
                         Ty.getType()->getDirectlyReferencedTypeDecl()))
      if (!passRelated(nominal, Ty.getLoc()))
        return false;
  }

  return true;
}
开发者ID:AaronTKD,项目名称:swift,代码行数:21,代码来源:SwiftIndexing.cpp


示例19: TypeIndexer

void IndexingContext::indexTypeLoc(TypeLoc TL,
                                   const NamedDecl *Parent,
                                   const DeclContext *DC,
                                   bool isBase,
                                   bool isIBType) {
  if (TL.isNull())
    return;

  if (!DC)
    DC = Parent->getLexicalDeclContext();
  TypeIndexer(*this, Parent, DC, isBase, isIBType).TraverseTypeLoc(TL);
}
开发者ID:davidlt,项目名称:root,代码行数:12,代码来源:IndexTypeSourceInfo.cpp


示例20: getCursorExpr

CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
    if (cursor.kind != CXCursor_CallExpr)
        return cursor;

    if (cursor.xdata == 0)
        return cursor;

    const Expr *E = getCursorExpr(cursor);
    TypeSourceInfo *Type = 0;
    if (const CXXUnresolvedConstructExpr *
            UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
        Type = UnCtor->getTypeSourceInfo();
    } else if (const CXXTemporaryObjectExpr *Tmp =
                   dyn_cast<CXXTemporaryObjectExpr>(E)) {
        Type = Tmp->getTypeSourceInfo();
    }

    if (!Type)
        return cursor;

    CXTranslationUnit TU = getCursorTU(cursor);
    QualType Ty = Type->getType();
    TypeLoc TL = Type->getTypeLoc();
    SourceLocation Loc = TL.getBeginLoc();

    if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
        Ty = ElabT->getNamedType();
        ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
        Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
    }

    if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
        return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
    if (const TagType *Tag = Ty->getAs<TagType>())
        return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
    if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
        return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);

    return cursor;
}
开发者ID:nicolaisi,项目名称:root,代码行数:40,代码来源:CXCursor.cpp



注:本文中的TypeLoc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TypeLocBuilder类代码示例发布时间:2022-05-31
下一篇:
C++ TypeList类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap