void DeprecatedIosBaseAliasesCheck::check(
    const MatchFinder::MatchResult &Result) {
  SourceManager &SM = *Result.SourceManager;

  const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
  StringRef TypeName = Typedef->getName();
  bool HasReplacement = ReplacementTypes.count(TypeName);

  const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
  SourceLocation IoStateLoc = TL->getBeginLoc();

  // Do not generate fixits for matches depending on template arguments and
  // macro expansions.
  bool Fix = HasReplacement && !TL->getType()->isDependentType();
  if (IoStateLoc.isMacroID()) {
    IoStateLoc = SM.getSpellingLoc(IoStateLoc);
    Fix = false;
  }

  SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);

  if (HasReplacement) {
    auto FixName = ReplacementTypes.lookup(TypeName);
    auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
                                    "'std::ios_base::%1' instead")
                   << TypeName << FixName;

    if (Fix)
      Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc),
                                              FixName);
  } else
    diag(IoStateLoc, "'std::ios_base::%0' is deprecated") << TypeName;
}
Ejemplo n.º 2
0
 bool operator()(const Multilib &M) const override {
   for (StringRef Flag : M.flags()) {
     llvm::StringMap<bool>::const_iterator SI = FlagSet.find(Flag.substr(1));
     if (SI != FlagSet.end())
       if (SI->getValue() != isFlagEnabled(Flag))
         return true;
   }
   return false;
 }
Ejemplo n.º 3
0
 // Register a directive at the specified marker.
 void addDirective(StringRef MarkerName, const UnattachedDirective &UD) {
   auto MarkerIt = Markers.find(MarkerName);
   if (MarkerIt != Markers.end()) {
     Marker &M = MarkerIt->second;
     if (M.UseLoc.isInvalid())
       M.UseLoc = UD.DirectivePos;
     return attachDirective(Diags, UD, M.DefLoc);
   }
   DeferredDirectives[MarkerName].push_back(UD);
 }
Ejemplo n.º 4
0
static void rename(llvm::StringMap<cl::Option *> &map, const char *from,
                   const char *to) {
  auto i = map.find(from);
  if (i != map.end()) {
    cl::Option *opt = i->getValue();
    map.erase(i);
    opt->setArgStr(to);
    map[to] = opt;
  }
}
void CGObjCJit::GenerateClass(const ObjCImplementationDecl *ClassDecl) {
  if (isUsable) {
    const char* ClassName = ClassDecl->getIdentifier()->getNameStart();

    void* Superclass = 0;
    ObjCInterfaceDecl *superClassDecl =
      ClassDecl->getClassInterface()->getSuperClass();

    if (superClassDecl) {
      const char* superClassName =
          superClassDecl->getIdentifier()->getNameStart();
      Superclass = _objc_getClass(superClassName);
    }

    void *theClass =
      _objc_allocateClassPair(Superclass, ClassName, 0); // TODO: always zero?

    // Add methods
    AddMethodsToClass(theClass);

    // Add interface ivars
    const ObjCInterfaceDecl *classInterfaceDecl = ClassDecl->getClassInterface();
    AddIvarsToClass(theClass,
                    classInterfaceDecl->ivar_begin(),
                    classInterfaceDecl->ivar_end());

    // Add implementation ivars
    AddIvarsToClass(theClass,
                    ClassDecl->ivar_begin(),
                    ClassDecl->ivar_end());

    // Add protocols
    ObjCInterfaceDecl::protocol_iterator protocol =
      classInterfaceDecl->protocol_begin();
    const ObjCInterfaceDecl::protocol_iterator protocol_end =
      classInterfaceDecl->protocol_end();
    while (protocol != protocol_end) {
      void *theProtocol = 0;
      // Search "locally" first, then from runtime
      llvm::StringMap<void*>::iterator proto_local =
        DefinedProtocols.find((*protocol)->getName());
      if (proto_local != DefinedProtocols.end()) {
        theProtocol = proto_local->second;
      } else {
        theProtocol = _objc_getProtocol((*protocol)->getNameAsString().c_str());
      }
      _class_addProtocol(theClass, theProtocol);
      protocol++;
    }

    // Finalize class (adding methods later, at runtime, in init function)
    _objc_registerClassPair(theClass);
  }
}
Ejemplo n.º 6
0
 int declare_variable(ast::Variable& it) {
     if(variables.find(it.identifier) != variables.end()) {
         std::cout << "Variable shadowing of "
                   << it.identifier;
         print_id(it.id);
         std::cout << std::endl;
     }
     variables.insert(std::pair<llvm::StringRef, ast::Variable>(it.identifier,
                      it));
     return EXIT_SUCCESS;
 }
Ejemplo n.º 7
0
void displayCounts() {
    vector<pair<int, string> > counts;
    llvm::StringMap<int>::iterator cmi = countsMap.begin();
    while (cmi != countsMap.end()) {
        counts.push_back(make_pair(cmi->getValue(), cmi->getKey()));
        ++cmi;
    }
    sort(counts.begin(), counts.end());
    for (unsigned i = 0; i < counts.size(); ++i) {
        llvm::outs() << counts[i].second << " - " << counts[i].first << '\n';
    }
}
Ejemplo n.º 8
0
static void
callHandler(const llvm::StringMap<std::unique_ptr<Handler>> &Handlers,
            llvm::yaml::ScalarNode *Method, llvm::yaml::ScalarNode *Id,
            llvm::yaml::MappingNode *Params, Handler *UnknownHandler) {
  llvm::SmallString<10> MethodStorage;
  auto I = Handlers.find(Method->getValue(MethodStorage));
  auto *Handler = I != Handlers.end() ? I->second.get() : UnknownHandler;
  if (Id)
    Handler->handleMethod(Params, Id->getRawValue());
  else
    Handler->handleNotification(Params);
}
Ejemplo n.º 9
0
 int declare_extern(ast::Extern* extrn) {
     assert(extrn != nullptr);
     if(functions.find(extrn->identifier) != functions.end()) {
         std::cout << "Double declaration of "
                   << extrn->identifier;
         print_id(extrn->id);
         std::cout << std::endl;
     }
     functions.insert(std::pair<llvm::StringRef, ast::Extern>(extrn->identifier,
                      *extrn));
     return EXIT_SUCCESS;
 }
Ejemplo n.º 10
0
void incrementCount(ObjectPtr obj) {
    string buf;
    llvm::raw_string_ostream sout(buf);
    sout << obj;
    string s = sout.str();
    llvm::StringMap<int>::iterator i = countsMap.find(s);
    if (i == countsMap.end()) {
        countsMap[s] = 1;
    }
    else {
        i->second += 1;
    }
}
Ejemplo n.º 11
0
    int check_call(ast::Call* call) {
        assert(call != nullptr);

        auto func = functions.find(call->function_name);
        if(func == functions.end()) {
            std::cout << "Unknown function "
                      << call->function_name
                      << " at "
                      << call->id
                      << std::endl;
            return EXIT_FAILURE;
        }
        auto fun = func->getValue();
        auto actual_argument_size = call->arguments.size();
        auto prototype_argument_size = fun.arguments.size();
        if(actual_argument_size < prototype_argument_size) {
            std::cout << "Not enough arguments to "
                      << fun.identifier
                      << " (expected "
                      << prototype_argument_size
                      << ", got "
                      << actual_argument_size
                      << ")"
                      << std::endl;
            return EXIT_FAILURE;
        }
        if(actual_argument_size > prototype_argument_size && !fun.variadic) {
            std::cout << "Too many arguments to "
                      << fun.identifier
                      << " (expected "
                      << prototype_argument_size
                      << ", got "
                      << actual_argument_size
                      << ")"
                      << std::endl;
            return EXIT_FAILURE;
        }
        check_coercion(call->type, fun.return_value, fun.identifier, call->id);
        for (auto it = call->arguments.begin(); it != call->arguments.end(); ++it) {
            auto op = it->get();
            auto index = std::distance(call->arguments.begin(), it);
            auto prototype_op = std::next(fun.arguments.begin(), index);
            check_operation(op);
            // Variadic functions.. don't check type.
            if(prototype_op != fun.arguments.end()) {
                check_coercion(op->type, prototype_op->type, "function argument", op->id);
            }
        }
        return EXIT_SUCCESS;
    }
Ejemplo n.º 12
0
llvm::Optional<DurationScale> getScaleForTimeInverse(llvm::StringRef Name) {
  static const llvm::StringMap<DurationScale> ScaleMap(
      {{"ToUnixHours", DurationScale::Hours},
       {"ToUnixMinutes", DurationScale::Minutes},
       {"ToUnixSeconds", DurationScale::Seconds},
       {"ToUnixMillis", DurationScale::Milliseconds},
       {"ToUnixMicros", DurationScale::Microseconds},
       {"ToUnixNanos", DurationScale::Nanoseconds}});

  auto ScaleIter = ScaleMap.find(std::string(Name));
  if (ScaleIter == ScaleMap.end())
    return llvm::None;

  return ScaleIter->second;
}
Ejemplo n.º 13
0
  void erase(const FileEntry *Entry) {
    std::string FullPath(GetFullPath(Entry->getName()));

    // Lowercase string because Windows filesystem is case insensitive.
    FullPath = StringRef(FullPath).lower();
    UniqueFiles.erase(FullPath);
  }
Ejemplo n.º 14
0
  /// getFile - Return an existing FileEntry with the given name if
  /// there is already one; otherwise create and return a
  /// default-constructed FileEntry.
  FileEntry &getFile(const char *Name, const struct stat & /*StatBuf*/) {
    std::string FullPath(GetFullPath(Name));

    // Lowercase string because Windows filesystem is case insensitive.
    FullPath = StringRef(FullPath).lower();
    return UniqueFiles.GetOrCreateValue(FullPath).getValue();
  }
Ejemplo n.º 15
0
static void hide(llvm::StringMap<cl::Option *> &map, const char *name) {
  // Check if option exists first for resilience against LLVM changes
  // between versions.
  if (map.count(name)) {
    map[name]->setHiddenFlag(cl::Hidden);
  }
}
Ejemplo n.º 16
0
 FileEntry &getFile(const char *Name, struct stat &StatBuf) {
   std::string FullPath(GetFullPath(Name));
   return UniqueFiles.GetOrCreateValue(
                              FullPath.c_str(),
                              FullPath.c_str() + FullPath.size()
                                                                ).getValue();
 }
Ejemplo n.º 17
0
namespace clay {

static llvm::StringMap<int> countsMap;

void incrementCount(ObjectPtr obj) {
    string buf;
    llvm::raw_string_ostream sout(buf);
    sout << obj;
    string s = sout.str();
    llvm::StringMap<int>::iterator i = countsMap.find(s);
    if (i == countsMap.end()) {
        countsMap[s] = 1;
    }
    else {
        i->second += 1;
    }
}

void displayCounts() {
    vector<pair<int, string> > counts;
    llvm::StringMap<int>::iterator cmi = countsMap.begin();
    while (cmi != countsMap.end()) {
        counts.push_back(make_pair(cmi->getValue(), cmi->getKey()));
        ++cmi;
    }
    sort(counts.begin(), counts.end());
    for (unsigned i = 0; i < counts.size(); ++i) {
        llvm::outs() << counts[i].second << " - " << counts[i].first << '\n';
    }
}

}
Ejemplo n.º 18
0
 FileEntry &getFile(const char *Name, struct stat &StatBuf) {
   std::string FullPath(GetFullPath(Name));
   
   // LowercaseString because Windows filesystem is case insensitive.
   FullPath = llvm::LowercaseString(FullPath);
   return UniqueFiles.GetOrCreateValue(FullPath).getValue();
 }
Ejemplo n.º 19
0
/// Check if a fixed size width buffer type matches the MPI datatype.
///
/// \param Typedef buffer type
/// \param BufferTypeName buffer type name, gets assigned
/// \param MPIDatatype name of the MPI datatype
///
/// \returns true if the type matches or the buffer type is unknown
static bool isTypedefTypeMatching(const TypedefType *const Typedef,
                                  std::string &BufferTypeName,
                                  const std::string &MPIDatatype) {
  static llvm::StringMap<std::string> FixedWidthMatches = {
      {"int8_t", "MPI_INT8_T"},     {"int16_t", "MPI_INT16_T"},
      {"int32_t", "MPI_INT32_T"},   {"int64_t", "MPI_INT64_T"},
      {"uint8_t", "MPI_UINT8_T"},   {"uint16_t", "MPI_UINT16_T"},
      {"uint32_t", "MPI_UINT32_T"}, {"uint64_t", "MPI_UINT64_T"}};

  const auto it = FixedWidthMatches.find(Typedef->getDecl()->getName());
  // Check if the typedef is known and not matching the MPI datatype.
  if (it != FixedWidthMatches.end() && it->getValue() != MPIDatatype) {
    BufferTypeName = Typedef->getDecl()->getName();
    return false;
  }
  return true;
}
Ejemplo n.º 20
0
    int check_variable(ast::Variable* var) {
        assert(var != nullptr);

        auto ptr = variables.find(var->identifier);
        assert_existing_variable(ptr, var->identifier, var->id);
        auto expected = ptr->getValue().type;
        return check_coercion(var->type, expected, var->identifier, var->id);
    }
Ejemplo n.º 21
0
 void assert_existing_variable(llvm::StringMapIterator<ast::Variable> ptr, std::string identifier, int id = -1) {
     if(ptr == variables.end()) {
         std::cout << "Unknown variable "
                   << identifier;
         print_id(id);
         std::cout << std::endl;
     }
 }
Ejemplo n.º 22
0
 int check_assignment(ast::Assignment* assignment) {
     assert(assignment != nullptr);
     auto ptr = variables.find(assignment->identifier);
     assert_existing_variable(ptr, assignment->identifier, assignment->id);
     auto val = assignment->value.get();
     check_operation(val);
     return check_coercion(val->type, ptr->getValue().type, "assignment", assignment->id);
 }
static FoundationClass findKnownClass(const ObjCInterfaceDecl *ID) {
  static llvm::StringMap<FoundationClass> Classes;
  if (Classes.empty()) {
    Classes["NSArray"] = FC_NSArray;
    Classes["NSDictionary"] = FC_NSDictionary;
    Classes["NSEnumerator"] = FC_NSEnumerator;
    Classes["NSOrderedSet"] = FC_NSOrderedSet;
    Classes["NSSet"] = FC_NSSet;
    Classes["NSString"] = FC_NSString;
  }

  // FIXME: Should we cache this at all?
  FoundationClass result = Classes.lookup(ID->getIdentifier()->getName());
  if (result == FC_None)
    if (const ObjCInterfaceDecl *Super = ID->getSuperClass())
      return findKnownClass(Super);

  return result;
}
Ejemplo n.º 24
0
llvm::Optional<DurationScale> getScaleForDurationInverse(llvm::StringRef Name) {
  static const llvm::StringMap<DurationScale> ScaleMap(
      {{"ToDoubleHours", DurationScale::Hours},
       {"ToInt64Hours", DurationScale::Hours},
       {"ToDoubleMinutes", DurationScale::Minutes},
       {"ToInt64Minutes", DurationScale::Minutes},
       {"ToDoubleSeconds", DurationScale::Seconds},
       {"ToInt64Seconds", DurationScale::Seconds},
       {"ToDoubleMilliseconds", DurationScale::Milliseconds},
       {"ToInt64Milliseconds", DurationScale::Milliseconds},
       {"ToDoubleMicroseconds", DurationScale::Microseconds},
       {"ToInt64Microseconds", DurationScale::Microseconds},
       {"ToDoubleNanoseconds", DurationScale::Nanoseconds},
       {"ToInt64Nanoseconds", DurationScale::Nanoseconds}});

  auto ScaleIter = ScaleMap.find(std::string(Name));
  if (ScaleIter == ScaleMap.end())
    return llvm::None;

  return ScaleIter->second;
}
llvm::Value *CGObjCJit::GenerateProtocolRef(CodeGenFunction &CGF,
                                            const ObjCProtocolDecl *PD) {
  if (isUsable) {
    llvm::Value *theProtocol;  
    // If not locally defined, retrieve from runtime
    llvm::StringMap<void*>::iterator it =
      DefinedProtocols.find(PD->getIdentifier()->getNameStart());
    if (it != DefinedProtocols.end()) {
      theProtocol =
          llvm::Constant::getIntegerValue(ObjCTypes.ProtocolPtrTy,
                                          llvm::APInt(sizeof(void*) * 8,
                                                      (uint64_t)it->second));
    } else {
      llvm::Value *ProtocolName =
          CGF.Builder.CreateGlobalStringPtr(PD->getNameAsString());
      theProtocol = CGF.Builder.CreateCall(fn_objc_getProtocol, ProtocolName);
    }
    return CGF.Builder.CreateBitCast(theProtocol, ObjCTypes.getExternalProtocolPtrTy());
  }
  return 0;
}
Ejemplo n.º 26
0
  // Register a marker.
  void addMarker(StringRef MarkerName, SourceLocation Pos) {
    auto InsertResult = Markers.insert(
        {MarkerName, Marker{Pos, SourceLocation(), SourceLocation()}});

    Marker &M = InsertResult.first->second;
    if (!InsertResult.second) {
      // Marker was redefined.
      M.RedefLoc = Pos;
    } else {
      // First definition: build any deferred directives.
      auto Deferred = DeferredDirectives.find(MarkerName);
      if (Deferred != DeferredDirectives.end()) {
        for (auto &UD : Deferred->second) {
          if (M.UseLoc.isInvalid())
            M.UseLoc = UD.DirectivePos;
          attachDirective(Diags, UD, Pos);
        }
        DeferredDirectives.erase(Deferred);
      }
    }
  }
Ejemplo n.º 27
0
Archivo: util.cpp Proyecto: jmgc/pyston
llvm::Constant* embedRelocatablePtr(const void* addr, llvm::Type* type, llvm::StringRef shared_name) {
    assert(addr);

    if (!ENABLE_JIT_OBJECT_CACHE)
        return embedConstantPtr(addr, type);

    std::string name;
    if (!shared_name.empty()) {
        llvm::GlobalVariable* gv = g.cur_module->getGlobalVariable(shared_name, true);
        if (gv)
            return gv;
        assert(!relocatable_syms.count(name));
        name = shared_name;
    } else {
        name = (llvm::Twine("c") + llvm::Twine(relocatable_syms.size())).str();
    }

    relocatable_syms[name] = addr;

    llvm::Type* var_type = type->getPointerElementType();
    return new llvm::GlobalVariable(*g.cur_module, var_type, true, llvm::GlobalVariable::ExternalLinkage, 0, name);
}
static void collectCheckers(const CheckerRegistry::CheckerInfoList &checkers,
                            const llvm::StringMap<size_t> &packageSizes,
                            CheckerOptInfo &opt, CheckerInfoSet &collected) {
  // Use a binary search to find the possible start of the package.
  CheckerRegistry::CheckerInfo packageInfo(NULL, opt.getName(), "");
  CheckerRegistry::CheckerInfoList::const_iterator e = checkers.end();
  CheckerRegistry::CheckerInfoList::const_iterator i =
    std::lower_bound(checkers.begin(), e, packageInfo, checkerNameLT);

  // If we didn't even find a possible package, give up.
  if (i == e)
    return;

  // If what we found doesn't actually start the package, give up.
  if (!isInPackage(*i, opt.getName()))
    return;

  // There is at least one checker in the package; claim the option.
  opt.claim();

  // See how large the package is.
  // If the package doesn't exist, assume the option refers to a single checker.
  size_t size = 1;
  llvm::StringMap<size_t>::const_iterator packageSize =
    packageSizes.find(opt.getName());
  if (packageSize != packageSizes.end())
    size = packageSize->getValue();

  // Step through all the checkers in the package.
  for (e = i+size; i != e; ++i) {
    if (opt.isEnabled())
      collected.insert(&*i);
    else
      collected.remove(&*i);
  }
}
Ejemplo n.º 29
0
    int check_func(ast::Func* func) {
        assert(func != nullptr);

        for (auto it = func->arguments.begin(); it != func->arguments.end(); ++it) {
            declare_variable(*it);
        }
        // Allocate memory on stack for local variables
        for (auto it = func->local_variables.begin(); it != func->local_variables.end(); ++it) {
            declare_variable(*it);
        }
        this->current_function = func;
        check_body(func->body);

        // TODO: check for return value?
        auto return_ = std::make_shared<ast::Return>();
        return_->value =
            std::make_shared<ast::Constant>(default_value_for(func->return_value));
        func->body.push_back(return_);
        this->current_function = nullptr;
        variables.clear();
        return EXIT_SUCCESS;
    }
Ejemplo n.º 30
0
 size_t size() const { return UniqueDirs.size(); }