Esempio n. 1
0
void MyFrame::OnCalc(wxCommandEvent& event)
{
	std::string text	= invoice_list->GetValue().ToStdString();
	std::string target	= target_input->GetValue().ToStdString();
	Finder f = Finder();
	int n;
	Finder::readToInt(&n,target.c_str());
	f.setTarget(n);
	f.setValues(text);
	f.make();
	std::vector<int> result = f.getResult();

	if (result.size() == 0) {
		result_list->SetValue(L"拼凑失败!");
		return;
	}

	double sum = 0;
	std::stringstream result_str;
	for (std::vector<int>::size_type i = 0; i != result.size(); ++i) {
		double v = result[i] / 100.0;
		result_str << v;
		if (i != result.size() -1)
			result_str << " + ";
		sum += v;
	}
	result_str << " = ";
	result_str << sum;

	result_list->SetValue(result_str.str());
}
Esempio n. 2
0
std::vector<SourceLocation>
getLocationsOfUSRs(const std::vector<std::string> &USRs, StringRef PrevName,
                   Decl *Decl) {
  USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext());
  Visitor.TraverseDecl(Decl);
  NestedNameSpecifierLocFinder Finder(Decl->getASTContext());

  for (const auto &Location : Finder.getNestedNameSpecifierLocations())
    Visitor.handleNestedNameSpecifierLoc(Location);

  return Visitor.getLocationsFound();
}
Esempio n. 3
0
bool EquivalenceScope::CheckConnection(DiagnosticsEngine &Diags, Object A, Object B, bool ReportWarnings) {
  if(A.Obj == B.Obj) {
    // equivalence (x,x)
    if(A.Offset != B.Offset) {
      Diags.Report(B.E->getLocation(), diag::err_equivalence_conflicting_offsets)
        << A.E->getSourceRange() << B.E->getSourceRange();
      ReportWarnings = false;
    }
    if(ReportWarnings) {
      Diags.Report(B.E->getLocation(), diag::warn_equivalence_same_object)
        << A.E->getSourceRange() << B.E->getSourceRange();
      ReportWarnings = false;
    }
  }

  ConnectionFinder Finder(Connections);
  Finder.FindRelevantConnections(A, B);
  auto Relevant = Finder.getResults();
  if (!Relevant.empty()) {

    for(auto I : Relevant) {
      bool same = true;
      if(B.Obj == I.A.Obj)
        same = B.Offset == I.A.Offset;
      else if(B.Obj == I.B.Obj)
        same = B.Offset == I.B.Offset;
      if(same) {
        if(A.Obj == I.A.Obj)
          same = A.Offset == I.A.Offset;
        else if(A.Obj == I.B.Obj)
          same = A.Offset == I.B.Offset;
      }
      if(!same) {
        Diags.Report(B.E->getLocation(), diag::err_equivalence_conflicting_offsets)
          << A.E->getSourceRange() << B.E->getSourceRange();
        Diags.Report(I.A.E->getLocation(), diag::note_equivalence_prev_offset)
          << I.A.E->getSourceRange() << I.B.E->getSourceRange();
        return false;
      }
    }

    if(ReportWarnings) {
      Diags.Report(B.E->getLocation(), diag::warn_equivalence_redundant)
        << A.E->getSourceRange() << B.E->getSourceRange();
      auto I = Relevant.front();
      Diags.Report(I.A.E->getLocation(), diag::note_equivalence_identical_association)
        << I.A.E->getSourceRange() << I.B.E->getSourceRange();
      ReportWarnings = false;
    }
  }
  return true;
}
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
    clang::CompilerInstance &Compiler, StringRef File) {
  // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
  // modify Compiler.
  Context.setSourceManager(&Compiler.getSourceManager());
  Context.setCurrentFile(File);
  Context.setASTContext(&Compiler.getASTContext());

  std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
  CheckFactories->createChecks(&Context, Checks);

  ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
  if (auto *P = Context.getCheckProfileData())
    FinderOptions.CheckProfiling.emplace(P->Records);

  std::unique_ptr<ast_matchers::MatchFinder> Finder(
      new ast_matchers::MatchFinder(std::move(FinderOptions)));

  for (auto &Check : Checks) {
    Check->registerMatchers(&*Finder);
    Check->registerPPCallbacks(Compiler);
  }

  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
  if (!Checks.empty())
    Consumers.push_back(Finder->newASTConsumer());

  AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
  // FIXME: Remove this option once clang's cfg-temporary-dtors option defaults
  // to true.
  AnalyzerOptions->Config["cfg-temporary-dtors"] =
      Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";

  GlobList &Filter = Context.getChecksFilter();
  AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
  if (!AnalyzerOptions->CheckersControlList.empty()) {
    setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
    AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
    AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
    AnalyzerOptions->AnalyzeNestedBlocks = true;
    AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
    std::unique_ptr<ento::AnalysisASTConsumer> AnalysisConsumer =
        ento::CreateAnalysisConsumer(Compiler);
    AnalysisConsumer->AddDiagnosticConsumer(
        new AnalyzerDiagnosticConsumer(Context));
    Consumers.push_back(std::move(AnalysisConsumer));
  }
  return llvm::make_unique<ClangTidyASTConsumer>(
      std::move(Consumers), std::move(Finder), std::move(Checks));
}
  bool FindSymbol(ASTContext &Context, const SourceManager &SourceMgr,
                  unsigned SymbolOffset, const std::string &QualifiedName) {
    DiagnosticsEngine &Engine = Context.getDiagnostics();

    const SourceLocation Point =
        SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID())
            .getLocWithOffset(SymbolOffset);

    if (!Point.isValid()) {
      ErrorOccurred = true;
      unsigned InvalidOffset = Engine.getCustomDiagID(
          DiagnosticsEngine::Error,
          "SourceLocation in file %0 at offset %1 is invalid");
      Engine.Report(Point, InvalidOffset) << SourceMgr.getFilename(Point)
                                          << SymbolOffset;
      return false;
    }

    const NamedDecl *FoundDecl = QualifiedName.empty()
                                     ? getNamedDeclAt(Context, Point)
                                     : getNamedDeclFor(Context, QualifiedName);

    if (FoundDecl == nullptr) {
      if (QualifiedName.empty()) {
        FullSourceLoc FullLoc(Point, SourceMgr);
        unsigned CouldNotFindSymbolAt = Engine.getCustomDiagID(
            DiagnosticsEngine::Error,
            "clang-rename could not find symbol (offset %0)");
        Engine.Report(Point, CouldNotFindSymbolAt) << SymbolOffset;
        ErrorOccurred = true;
        return false;
      }
      unsigned CouldNotFindSymbolNamed = Engine.getCustomDiagID(
          DiagnosticsEngine::Error, "clang-rename could not find symbol %0");
      Engine.Report(CouldNotFindSymbolNamed) << QualifiedName;
      ErrorOccurred = true;
      return false;
    }

    // If FoundDecl is a constructor or destructor, we want to instead take
    // the Decl of the corresponding class.
    if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
      FoundDecl = CtorDecl->getParent();
    else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
      FoundDecl = DtorDecl->getParent();

    SpellingNames.push_back(FoundDecl->getNameAsString());
    AdditionalUSRFinder Finder(FoundDecl, Context);
    USRList.push_back(Finder.Find());
    return true;
  }
Esempio n. 6
0
clang::ASTConsumer *ClangTidyASTConsumerFactory::CreateASTConsumer(
    clang::CompilerInstance &Compiler, StringRef File) {
    // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
    // modify Compiler.
    Context.setSourceManager(&Compiler.getSourceManager());
    Context.setCurrentFile(File);

    std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
    ChecksFilter &Filter = Context.getChecksFilter();
    CheckFactories->createChecks(Filter, Checks);

    std::unique_ptr<ast_matchers::MatchFinder> Finder(
        new ast_matchers::MatchFinder);
    for (auto &Check : Checks) {
        Check->setContext(&Context);
        Check->registerMatchers(&*Finder);
        Check->registerPPCallbacks(Compiler);
    }

    SmallVector<ASTConsumer *, 2> Consumers;
    if (!Checks.empty())
        Consumers.push_back(Finder->newASTConsumer());

    AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
    // FIXME: Remove this option once clang's cfg-temporary-dtors option defaults
    // to true.
    AnalyzerOptions->Config["cfg-temporary-dtors"] =
        Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";

    AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
    if (!AnalyzerOptions->CheckersControlList.empty()) {
        AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
        AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
        AnalyzerOptions->AnalyzeNestedBlocks = true;
        AnalyzerOptions->eagerlyAssumeBinOpBifurcation = true;
        ento::AnalysisASTConsumer *AnalysisConsumer = ento::CreateAnalysisConsumer(
                    Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
                    AnalyzerOptions, Compiler.getFrontendOpts().Plugins);
        AnalysisConsumer->AddDiagnosticConsumer(
            new AnalyzerDiagnosticConsumer(Context));
        Consumers.push_back(AnalysisConsumer);
    }
    return new ClangTidyASTConsumer(Consumers, std::move(Finder),
                                    std::move(Checks));
}
  void NullDerefProtectionTransformer::Transform() {
    FunctionDecl* FD = getTransaction()->getWrapperFD();
    if (!FD)
      return;

    NonNullDeclFinder Finder(m_Sema);
    std::string mangledName = Finder.getMangledName(FD);
    // Find the function in the module.
    llvm::Function* F = getTransaction()->getModule()->getFunction(mangledName);
    if (!F) return;

    llvm::IRBuilder<> TheBuilder(F->getContext());
    Builder = &TheBuilder;
    runOnFunction(*F);

    // Find all the function decls with null attribute arguments.
    for (size_t Idx = 0, E = getTransaction()->size(); Idx < E; ++Idx) {
      Transaction::DelayCallInfo I = (*getTransaction())[Idx];
      for (DeclGroupRef::const_iterator J = I.m_DGR.begin(),
             JE = I.m_DGR.end(); J != JE; ++J)
        if ((*J)->hasBody())
          Finder.TraverseStmt((*J)->getBody());
    }

    const llvm::SmallVector<std::string, 8>&
      FDeclNames = Finder.getDeclNames();
    if (FDeclNames.empty()) return;

    llvm::Module* M = F->getParent();

    for (llvm::SmallVector<std::string, 8>::const_iterator
         i = FDeclNames.begin(), e = FDeclNames.end(); i != e; ++i) {
      const nonnull_map_t& ArgIndexs = Finder.getArgIndexs();
      nonnull_map_t::const_iterator it = ArgIndexs.find(*i);

      if (it != ArgIndexs.end()) {
        const std::bitset<32>& ArgNums = it->second;
        handleNonNullArgCall(*M, *i, ArgNums);
      }
    }
  }
Esempio n. 8
0
const NamedDecl *getNamedDeclAt(const ASTContext &Context,
                                const SourceLocation Point) {
  StringRef SearchFile = Context.getSourceManager().getFilename(Point);
  NamedDeclFindingASTVisitor Visitor(Point, Context);

  // We only want to search the decls that exist in the same file as the point.
  for (auto *CurrDecl : Context.getTranslationUnitDecl()->decls()) {
    const SourceLocation FileLoc = CurrDecl->getLocStart();
    StringRef FileName = Context.getSourceManager().getFilename(FileLoc);
    // FIXME: Add test.
    if (FileName == SearchFile) {
      Visitor.TraverseDecl(CurrDecl);
    }
  }

  NestedNameSpecifierLocFinder Finder(const_cast<ASTContext &>(Context));
  for (const auto &Location : Finder.getNestedNameSpecifierLocations()) {
    Visitor.handleNestedNameSpecifierLoc(Location);
  }

  return Visitor.getNamedDecl();
}
Esempio n. 9
0
const NamedDecl *getNamedDeclAt(const ASTContext &Context,
                                const SourceLocation Point) {
  const SourceManager &SM = Context.getSourceManager();
  NamedDeclFindingASTVisitor Visitor(Point, Context);

  // Try to be clever about pruning down the number of top-level declarations we
  // see. If both start and end is either before or after the point we're
  // looking for the point cannot be inside of this decl. Don't even look at it.
  for (auto *CurrDecl : Context.getTranslationUnitDecl()->decls()) {
    SourceLocation StartLoc = CurrDecl->getLocStart();
    SourceLocation EndLoc = CurrDecl->getLocEnd();
    if (StartLoc.isValid() && EndLoc.isValid() &&
        SM.isBeforeInTranslationUnit(StartLoc, Point) !=
            SM.isBeforeInTranslationUnit(EndLoc, Point))
      Visitor.TraverseDecl(CurrDecl);
  }

  NestedNameSpecifierLocFinder Finder(const_cast<ASTContext &>(Context));
  for (const auto &Location : Finder.getNestedNameSpecifierLocations())
    Visitor.handleNestedNameSpecifierLoc(Location);

  return Visitor.getNamedDecl();
}
  void HandleTranslationUnit(ASTContext &Context) override {
    const SourceManager &SourceMgr = Context.getSourceManager();
    // The file we look for the USR in will always be the main source file.
    const SourceLocation Point =
        SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID())
            .getLocWithOffset(SymbolOffset);
    if (!Point.isValid())
      return;
    const NamedDecl *FoundDecl = nullptr;
    if (OldName.empty()) {
      FoundDecl = getNamedDeclAt(Context, Point);
    } else {
      FoundDecl = getNamedDeclFor(Context, OldName);
    }
    if (FoundDecl == nullptr) {
      FullSourceLoc FullLoc(Point, SourceMgr);
      errs() << "clang-rename: could not find symbol at "
             << SourceMgr.getFilename(Point) << ":"
             << FullLoc.getSpellingLineNumber() << ":"
             << FullLoc.getSpellingColumnNumber() << " (offset " << SymbolOffset
             << ").\n";
      return;
    }

    // If FoundDecl is a constructor or destructor, we want to instead take the
    // Decl of the corresponding class.
    if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl)) {
      FoundDecl = CtorDecl->getParent();
    } else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl)) {
      FoundDecl = DtorDecl->getParent();
    }
    *SpellingName = FoundDecl->getNameAsString();

    AdditionalUSRFinder Finder(FoundDecl, Context, USRs);
    Finder.Find();
  }
boost::optional<SettingValue> SettingsTree::find(
    const std::string &key) const
{
    return boost::apply_visitor(Finder(key), myTree);
}
Esempio n. 12
0
	inline Object::const_iterator Object::Find(const std::string& name) const {
		return std::find_if(m_Members.begin(), m_Members.end(), Finder(name));
	}
Esempio n. 13
0
void QRcodeReader::decode() {
    Binarizer binarizer(img);
    img = binarizer.getBlackMatrix();

    if (more) {
        imshow("original", rgbImg);
        imshow("test",img);
        waitKey(0);
        printf("**************************************************************\n");
        printf("Begin detection to find the three finder pattern centers:\n");
    }

    Finder finder = Finder(img);
    FinderResult fr = finder.find();
    if (more) {
        printf("\n");
        printf("Three finder pattern centers:\n");
        FinderPoint bL = fr.getBottomLeft();
        FinderPoint tL = fr.getTopLeft();
        FinderPoint tR = fr.getTopRight();
        printf("bottomLeft: (%f, %f)\n", bL.getX(), bL.getY());
        printf("topLeft: (%f, %f)\n", tL.getX(), tL.getY());
        printf("topRight: (%f, %f)\n", tR.getX(), tR.getY());
        Point2f p1 = Point2f(bL.getX(), bL.getY());
        circle(rgbImg, p1, 3, Scalar(0,255,0));
        Point2f p2 = Point2f(tL.getX(), tL.getY());
        circle(rgbImg, p2, 3, Scalar(0,255,0));
        Point2f p3 = Point2f(tR.getX(), tR.getY());
        circle(rgbImg, p3, 3, Scalar(0,255,0));
        imshow("original", rgbImg);
        waitKey(0);
    }

    Detector detector = Detector(img);
    DetectorResult detectorResult = detector.processFinderPatternInfo(fr);
    if (more) {
        vector<FinderPoint> patternPoints = detectorResult.getResultPoints();
        BitMatrix bits = detectorResult.getBits();
        printf("\n");
        printf("Module Size: %f\n", detectorResult.getModuleSize());
        printf("Dimension: %d\n", detectorResult.getDimension());
        printf("Alignment Pattern : (%f, %f)\n", patternPoints[3].getX(), patternPoints[3].getY());
        Point2f p4 = Point2f(patternPoints[3].getX(), patternPoints[3].getY());
        circle(rgbImg, p4, 3, Scalar(0,255,0));
        imshow("original", rgbImg);
        waitKey(0);

        printf("\n");
        printf("The bit matrix:\n");
        bits.display();
        printf("\nDetection Done!\n");
        printf("**************************************************************\n");
        waitKey(0);
    }


    Decoder decoder = Decoder(detectorResult);
    DecoderResult decoderResult = decoder.decode();
    if (more) {
        printf("Decode:\n");
        printf("version : %d\n", decoderResult.getVersion());
        printf("Error correct level : %d\n", decoderResult.getEcLevel());
        vector<char> resultBytes = decoderResult.getResultBytes();
        printf("Data bytes: ");
        for (int i = 0; i < resultBytes.size(); ++i) {
            printf("%d ",resultBytes[i]);
        }
        printf("\n");
        string result = decoderResult.getResultText();
        printf("%s\n", result.c_str());
        waitKey(0);
    }
    else {
        string result = decoderResult.getResultText();
        printf("%s\n", result.c_str());
    }
}
Esempio n. 14
0
TPT_NO_INLINE Object::iterator Object::Find(const std::string& name) 
{
   return std::find_if(m_Members.begin(), m_Members.end(), Finder(name));
}