示例#1
0
TEST(test_algorithm5, dictionaries){
    std::ifstream file;
    std::string line;
    std::set<std::wstring> words;
    std::string filename = "../american-english";
    file.open(filename);
    while (std::getline(file, line)){
        words.insert(sj::utf8_to_wstring(line));
    }
    file.close();
    auto solved_words = sj::Solver(words,"nxxxetsxxtiexxfmxxxo", 4, 5);
    EXPECT_EQ(solved_words.Paths()[0].word(), "oftentimes");
}
示例#2
0
TEST(test_algorithm4, special_characters){
    std::ifstream file;
    std::string line;
    std::set<std::wstring> words;
    std::string filename = "../sanat.txt";
    file.open(filename);
    while (std::getline(file, line)){
        words.insert(sj::utf8_to_wstring(line));
    }
    file.close();
    auto solved_words = sj::Solver(words,"xxxxxöytxlätxxix", 4, 4);
    EXPECT_EQ(solved_words.Paths()[0].word(), "öylätti");
}
示例#3
0
/*
TEST(Testin_nimi, Mita_testataan){ //Replace the parameters with the correct equivalents
    EXPECT_EQ(2, 2); // Replace this
    EXPECT_EQ("anything", "something else"); // And this
}
*/
TEST(test_algorithm, normal){ //Replace the parameters with the correct equivalents
    std::ifstream file;
    std::string line;
    std::set<std::wstring> words;
    std::string filename = "../sanat.txt";
    file.open(filename);
    while (std::getline(file, line)){
        words.insert(sj::utf8_to_wstring(line));
    }
    file.close();
    auto solved_words = sj::Solver(words,"ointiikzsaatennm", 4, 4);
    auto solved_words2 = sj::Solver(words,"esionaiinaknmtzt", 4, 4); //90 degree flip clockwise
    EXPECT_EQ(solved_words.Paths()[0].word(), "makasiini");
    EXPECT_EQ(solved_words.Paths()[0].w_word(), L"makasiini");
    EXPECT_EQ(solved_words2.Paths()[0].word(), "makasiini");
    EXPECT_EQ(solved_words2.Paths()[0].w_word(), L"makasiini");
    EXPECT_EQ(solved_words.Paths().size(), solved_words.Paths().size());
}
/// Checks whether the return types are covariant, according to
/// C++[class.virtual]p7.
///
/// Similar with clang::Sema::CheckOverridingFunctionReturnType.
/// \returns true if the return types of BaseMD and DerivedMD are covariant.
static bool checkOverridingFunctionReturnType(const ASTContext *Context,
                                              const CXXMethodDecl *BaseMD,
                                              const CXXMethodDecl *DerivedMD) {
  QualType BaseReturnTy = BaseMD->getType()
                              ->getAs<FunctionType>()
                              ->getReturnType()
                              .getCanonicalType();
  QualType DerivedReturnTy = DerivedMD->getType()
                                 ->getAs<FunctionType>()
                                 ->getReturnType()
                                 .getCanonicalType();

  if (DerivedReturnTy->isDependentType() || BaseReturnTy->isDependentType())
    return false;

  // Check if return types are identical.
  if (Context->hasSameType(DerivedReturnTy, BaseReturnTy))
    return true;

  /// Check if the return types are covariant.

  // Both types must be pointers or references to classes.
  if (!(BaseReturnTy->isPointerType() && DerivedReturnTy->isPointerType()) &&
      !(BaseReturnTy->isReferenceType() && DerivedReturnTy->isReferenceType()))
    return false;

  /// BTy is the class type in return type of BaseMD. For example,
  ///    B* Base::md()
  /// While BRD is the declaration of B.
  QualType DTy = DerivedReturnTy->getPointeeType().getCanonicalType();
  QualType BTy = BaseReturnTy->getPointeeType().getCanonicalType();

  const CXXRecordDecl *DRD = DTy->getAsCXXRecordDecl();
  const CXXRecordDecl *BRD = BTy->getAsCXXRecordDecl();
  if (DRD == nullptr || BRD == nullptr)
    return false;

  if (!DRD->hasDefinition() || !BRD->hasDefinition())
    return false;

  if (DRD == BRD)
    return true;

  if (!Context->hasSameUnqualifiedType(DTy, BTy)) {
    // Begin checking whether the conversion from D to B is valid.
    CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
                       /*DetectVirtual=*/false);

    // Check whether D is derived from B, and fill in a CXXBasePaths object.
    if (!DRD->isDerivedFrom(BRD, Paths))
      return false;

    // Check ambiguity.
    if (Paths.isAmbiguous(Context->getCanonicalType(BTy).getUnqualifiedType()))
      return false;

    // Check accessibility.
    // FIXME: We currently only support checking if B is accessible base class
    // of D, or D is the same class which DerivedMD is in.
    bool IsItself =
        DRD->getCanonicalDecl() == DerivedMD->getParent()->getCanonicalDecl();
    bool HasPublicAccess = false;
    for (const auto &Path : Paths) {
      if (Path.Access == AS_public)
        HasPublicAccess = true;
    }
    if (!HasPublicAccess && !IsItself)
      return false;
    // End checking conversion from D to B.
  }

  // Both pointers or references should have the same cv-qualification.
  if (DerivedReturnTy.getLocalCVRQualifiers() !=
      BaseReturnTy.getLocalCVRQualifiers())
    return false;

  // The class type D should have the same cv-qualification as or less
  // cv-qualification than the class type B.
  if (DTy.isMoreQualifiedThan(BTy))
    return false;

  return true;
}
示例#5
0
Mesh2Cloud::Mesh2Cloud(std::string id, fs::path meshPath) : Visualizer(id), SingleMesh(id, meshPath), MultiPointCloud(id, Paths()) {
}
/// CheckExceptionSpecSubset - Check whether the second function type's
/// exception specification is a subset (or equivalent) of the first function
/// type. This is used by override and pointer assignment checks.
bool Sema::CheckExceptionSpecSubset(
    const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
    const FunctionProtoType *Superset, SourceLocation SuperLoc,
    const FunctionProtoType *Subset, SourceLocation SubLoc) {
  // FIXME: As usual, we could be more specific in our error messages, but
  // that better waits until we've got types with source locations.

  if (!SubLoc.isValid())
    SubLoc = SuperLoc;

  // If superset contains everything, we're done.
  if (!Superset->hasExceptionSpec() || Superset->hasAnyExceptionSpec())
    return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);

  // It does not. If the subset contains everything, we've failed.
  if (!Subset->hasExceptionSpec() || Subset->hasAnyExceptionSpec()) {
    Diag(SubLoc, DiagID);
    if (NoteID.getDiagID() != 0)
      Diag(SuperLoc, NoteID);
    return true;
  }

  // Neither contains everything. Do a proper comparison.
  for (FunctionProtoType::exception_iterator SubI = Subset->exception_begin(),
       SubE = Subset->exception_end(); SubI != SubE; ++SubI) {
    // Take one type from the subset.
    QualType CanonicalSubT = Context.getCanonicalType(*SubI);
    // Unwrap pointers and references so that we can do checks within a class
    // hierarchy. Don't unwrap member pointers; they don't have hierarchy
    // conversions on the pointee.
    bool SubIsPointer = false;
    if (const ReferenceType *RefTy = CanonicalSubT->getAs<ReferenceType>())
      CanonicalSubT = RefTy->getPointeeType();
    if (const PointerType *PtrTy = CanonicalSubT->getAs<PointerType>()) {
      CanonicalSubT = PtrTy->getPointeeType();
      SubIsPointer = true;
    }
    bool SubIsClass = CanonicalSubT->isRecordType();
    CanonicalSubT = CanonicalSubT.getLocalUnqualifiedType();

    CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
                       /*DetectVirtual=*/false);

    bool Contained = false;
    // Make sure it's in the superset.
    for (FunctionProtoType::exception_iterator SuperI =
           Superset->exception_begin(), SuperE = Superset->exception_end();
         SuperI != SuperE; ++SuperI) {
      QualType CanonicalSuperT = Context.getCanonicalType(*SuperI);
      // SubT must be SuperT or derived from it, or pointer or reference to
      // such types.
      if (const ReferenceType *RefTy = CanonicalSuperT->getAs<ReferenceType>())
        CanonicalSuperT = RefTy->getPointeeType();
      if (SubIsPointer) {
        if (const PointerType *PtrTy = CanonicalSuperT->getAs<PointerType>())
          CanonicalSuperT = PtrTy->getPointeeType();
        else {
          continue;
        }
      }
      CanonicalSuperT = CanonicalSuperT.getLocalUnqualifiedType();
      // If the types are the same, move on to the next type in the subset.
      if (CanonicalSubT == CanonicalSuperT) {
        Contained = true;
        break;
      }

      // Otherwise we need to check the inheritance.
      if (!SubIsClass || !CanonicalSuperT->isRecordType())
        continue;

      Paths.clear();
      if (!IsDerivedFrom(CanonicalSubT, CanonicalSuperT, Paths))
        continue;

      if (Paths.isAmbiguous(CanonicalSuperT))
        continue;

      // Do this check from a context without privileges.
      switch (CheckBaseClassAccess(SourceLocation(), false,
                                   CanonicalSuperT, CanonicalSubT,
                                   Paths.front(),
                                   /*ForceCheck*/ true,
                                   /*ForceUnprivileged*/ true,
                                   ADK_quiet)) {
      case AR_accessible: break;
      case AR_inaccessible: continue;
      case AR_dependent:
        llvm_unreachable("access check dependent for unprivileged context");
        break;
      case AR_delayed:
        llvm_unreachable("access check delayed in non-declaration");
        break;
      }

      Contained = true;
      break;
    }
    if (!Contained) {
      Diag(SubLoc, DiagID);
      if (NoteID.getDiagID() != 0)
        Diag(SuperLoc, NoteID);
      return true;
    }
  }
  // We've run half the gauntlet.
  return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
}
示例#7
0
TEST(test_algorithm6, constructors){
    std::ifstream file;
    std::string line;
    std::set<std::wstring> words;
    std::string filename = "../sanat.txt";
    file.open(filename);
    while (std::getline(file, line)){
        words.insert(sj::utf8_to_wstring(line));
    }
    file.close();
    //Each solved_words has different constructor
    auto solved_words = sj::Solver(words,L"ointiikzsaatennm", 4, 4);
    auto solved_words2 = sj::Solver(words,"ointiikzsaatennm", 4, 4);
    file.open(filename);
    std::set<std::string> words2;
    while(std::getline(file, line)){
        words2.insert(line);
    }
    file.close();
    auto solved_words3 = sj::Solver(words2,L"ointiikzsaatennm", 4, 4);
    auto solved_words4 = sj::Solver(words2,"ointiikzsaatennm", 4, 4);
    
    EXPECT_EQ(solved_words.Paths()[0].word(), solved_words2.Paths()[0].word());
    EXPECT_EQ(solved_words.Paths()[0].w_word(), solved_words2.Paths()[0].w_word());
    
    EXPECT_EQ(solved_words.Paths()[0].word(), solved_words3.Paths()[0].word());
    EXPECT_EQ(solved_words.Paths()[0].w_word(), solved_words3.Paths()[0].w_word());
    
    EXPECT_EQ(solved_words.Paths()[0].word(), solved_words4.Paths()[0].word());
    EXPECT_EQ(solved_words.Paths()[0].w_word(), solved_words4.Paths()[0].w_word());
    
    EXPECT_EQ(solved_words2.Paths()[0].word(), solved_words3.Paths()[0].word());
    EXPECT_EQ(solved_words2.Paths()[0].w_word(), solved_words3.Paths()[0].w_word());
    
    EXPECT_EQ(solved_words2.Paths()[0].word(), solved_words4.Paths()[0].word());
    EXPECT_EQ(solved_words2.Paths()[0].w_word(), solved_words4.Paths()[0].w_word());
    
    EXPECT_EQ(solved_words3.Paths()[0].word(), solved_words4.Paths()[0].word());
    EXPECT_EQ(solved_words3.Paths()[0].w_word(), solved_words4.Paths()[0].w_word());
}
示例#8
0
DECL_STATIC Paths*
Paths::New() {
    return new XMP_Debug_new Paths();
}