bool VisitVarDecl(VarDecl *VD) { if (VD != Consumer->TheVarDecl) return true; Rewriter &TheRewriter = Consumer->TheRewriter; const SourceManager &SM = TheRewriter.getSourceMgr(); SourceLocation NameLoc = VD->getLocation(); IdentifierInfo *IdInfo = VD->getIdentifier(); assert(IdInfo && "Nameless variable"); unsigned NameLength = IdInfo->getLength(); assert(NameLength && "Variable name has no length"); SourceLocation TypeLocStart = VD->getLocStart(); const std::string ElemTypeName = getVectorElemTypeName(VD); SourceLocation NameLocM1 = NameLoc.getLocWithOffset(-1); bool isInvalid = false; const char *charBeforeName = SM.getCharacterData(NameLocM1, &isInvalid); assert(!isInvalid && "failed to get char before name"); TheRewriter.ReplaceText(NameLoc.getLocWithOffset(NameLength), 0, ARRAY_SUFFIX); if (!std::isspace(*charBeforeName)) TheRewriter.InsertText(NameLoc, " "); TheRewriter.ReplaceText(SourceRange(TypeLocStart, NameLocM1), ElemTypeName); return true; }
C2::ExprResult C2Sema::ActOnIdExpression(IdentifierInfo& symII, SourceLocation symLoc) { std::string id(symII.getNameStart(), symII.getLength()); #ifdef SEMA_DEBUG std::cerr << COL_SEMA"SEMA: identifier " << id << " at "; symLoc.dump(SourceMgr); std::cerr << ANSI_NORMAL"\n"; #endif return ExprResult(new IdentifierExpr(symLoc, id)); }
/// \brief Get the ASTContext-specific selector. Selector GlobalSelector::getSelector(ASTContext &AST) const { if (isInvalid()) return Selector(); Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val)); llvm::SmallVector<IdentifierInfo *, 8> Ids; for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs(); i != e; ++i) { IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i); IdentifierInfo *II = &AST.Idents.get(GlobII->getName(), GlobII->getName() + GlobII->getLength()); Ids.push_back(II); } return AST.Selectors.getSelector(GlobSel.getNumArgs(), Ids.data()); }
/// \brief Get a GlobalSelector for the ASTContext-specific selector. GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) { if (Sel.isNull()) return GlobalSelector(); ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl); llvm::SmallVector<IdentifierInfo *, 8> Ids; for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs(); i != e; ++i) { IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i); IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName(), II->getName() + II->getLength()); Ids.push_back(GlobII); } Selector GlobSel = ProgImpl.getSelectors().getSelector(Sel.getNumArgs(), Ids.data()); return GlobalSelector(GlobSel.getAsOpaquePtr()); }