Пример #1
0
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "MustUseChecker.h"
#include "CustomMatchers.h"
#include "CustomTypeAnnotation.h"

CustomTypeAnnotation MustUse =
    CustomTypeAnnotation(moz_must_use_type, "must-use");

void MustUseChecker::registerMatchers(MatchFinder *AstMatcher) {
  AstMatcher->addMatcher(switchCase().bind("switchcase"), this);
  AstMatcher->addMatcher(compoundStmt().bind("compound"), this);
  AstMatcher->addMatcher(ifStmt().bind("if"), this);
  AstMatcher->addMatcher(whileStmt().bind("while"), this);
  AstMatcher->addMatcher(doStmt().bind("do"), this);
  AstMatcher->addMatcher(forStmt().bind("for"), this);
  AstMatcher->addMatcher(binaryOperator(binaryCommaOperator()).bind("bin"),
                         this);
}

void MustUseChecker::check(const MatchFinder::MatchResult &Result) {
  if (auto SC = Result.Nodes.getNodeAs<SwitchCase>("switchcase")) {
    handleUnusedExprResult(SC->getSubStmt());
  }
  if (auto C = Result.Nodes.getNodeAs<CompoundStmt>("compound")) {
    for (const auto &S : C->body()) {
      handleUnusedExprResult(S);
    }
  }
Пример #2
0
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "CustomTypeAnnotation.h"
#include "Utils.h"

CustomTypeAnnotation StackClass =
    CustomTypeAnnotation("moz_stack_class", "stack");
CustomTypeAnnotation GlobalClass =
    CustomTypeAnnotation("moz_global_class", "global");
CustomTypeAnnotation NonHeapClass =
    CustomTypeAnnotation("moz_nonheap_class", "non-heap");
CustomTypeAnnotation HeapClass = CustomTypeAnnotation("moz_heap_class", "heap");
CustomTypeAnnotation NonTemporaryClass =
    CustomTypeAnnotation("moz_non_temporary_class", "non-temporary");

void CustomTypeAnnotation::dumpAnnotationReason(BaseCheck &Check, QualType T,
                                                SourceLocation Loc) {
  const char *Inherits =
      "%1 is a %0 type because it inherits from a %0 type %2";
  const char *Member = "%1 is a %0 type because member %2 is a %0 type %3";
  const char *Array = "%1 is a %0 type because it is an array of %0 type %2";
  const char *Templ =
      "%1 is a %0 type because it has a template argument %0 type %2";
  const char *Implicit = "%1 is a %0 type because %2";

  AnnotationReason Reason = directAnnotationReason(T);
  for (;;) {
    switch (Reason.Kind) {
    case RK_ArrayElement: