当前位置: 首页>>代码示例>>C++>>正文


C++ TypeLoc::getBeginLoc方法代码示例

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


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

示例1: getTypeRefCursor

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:oguzaras,项目名称:clang,代码行数:40,代码来源:CXCursor.cpp

示例2: VisitTypeLoc

 bool VisitTypeLoc(TypeLoc TypeLocation) {
   Match(TypeLocation.getType().getAsString(), TypeLocation.getBeginLoc());
   return true;
 }
开发者ID:Abocer,项目名称:android-4.2_r1,代码行数:4,代码来源:RecursiveASTVisitorTest.cpp

示例3: processTypeLoc

void TypeRenameTransform::processTypeLoc(TypeLoc TL, bool forceRewriteMacro)
{
  if (TL.isNull()) {
    return;
  }
  
  auto BL = TL.getBeginLoc();
  
  // ignore system headers
  if (shouldIgnore(BL)) {
    return;
  }
  
  // is a result from macro expansion? sorry...
  if (BL.isMacroID() && !forceRewriteMacro) {
    llvm::errs() << "Cannot rename type from macro expansion at: " << loc(BL) << "\n";
    return;
  }
  
  // TODO: Take care of spelling loc finesses
  // BL = sema->getSourceManager().getSpellingLoc(BL);

  pushIndent();
  auto QT = TL.getType();

  // llvm::errs() << indent()
  //   << "TypeLoc"
  //   << ", typeLocClass: " << typeLocClassName(TL.getTypeLocClass())
  //   << "\n" << indent() << "qualType as str: " << QT.getAsString()
  //   << "\n" << indent() << "beginLoc: " << loc(TL.getBeginLoc())
  //   << "\n";
    
  switch(TL.getTypeLocClass()) {    
    case TypeLoc::FunctionProto:
    {
      if (auto FTL = dyn_cast<FunctionTypeLoc>(&TL)) {
        for (unsigned I = 0, E = FTL->getNumArgs(); I != E; ++I) {
          processParmVarDecl(FTL->getArg(I));
        }
      }
      break;
    }    
    // an elaborated type loc captures the "prefix" of a type
    // for example, the elaborated type loc of "A::B::C" is A::B
    // we need to know if A::B and A are types we are renaming
    // (so that we can handle nested classes, in-class typedefs, etc.)
    case TypeLoc::Elaborated:
    {
      if (auto ETL = dyn_cast<ElaboratedTypeLoc>(&TL)) {
        processQualifierLoc(ETL->getQualifierLoc(), forceRewriteMacro);
      }
      break;
    }
    
    case TypeLoc::ObjCObject:
    {
      if (auto OT = dyn_cast<ObjCObjectTypeLoc>(&TL)) {
        for (unsigned I = 0, E = OT->getNumProtocols(); I != E; ++I) {
          if (auto P = OT->getProtocol(I)) {
            std::string newName;
            if (nameMatches(P, newName, true)) {
              renameLocation(OT->getProtocolLoc(I), newName);
            }
          }
        }
      }
      break;
    }
    
    case TypeLoc::InjectedClassName:
    {
      if (auto TSTL = dyn_cast<InjectedClassNameTypeLoc>(&TL)) {
        auto CD = TSTL->getDecl();
        std::string newName;
        if (nameMatches(CD, newName, true)) {
          renameLocation(BL, newName);          
        }      
      }
      break;
    }
    
    case TypeLoc::TemplateSpecialization:
    {
      if (auto TSTL = dyn_cast<TemplateSpecializationTypeLoc>(&TL)) {
        
        // See if it's the template name that needs renaming
        auto T = TL.getTypePtr();
        
        if (auto TT = dyn_cast<TemplateSpecializationType>(T)) {
          auto TN = TT->getTemplateName();
          auto TD = TN.getAsTemplateDecl();
          auto TTD = TD->getTemplatedDecl();

          std::string newName;
          if (nameMatches(TTD, newName, true)) {
            renameLocation(TSTL->getTemplateNameLoc(), newName);
          }
        }

        // iterate through the args
//.........这里部分代码省略.........
开发者ID:sbinet,项目名称:clang-refactor,代码行数:101,代码来源:TypeRenameTransform.cpp


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