Пример #1
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitStatements) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    if (init != null) if (!init.accept(action)) return false;
    if (condition != null) if (!condition.accept(action)) return false;
    if (iterationExpression != null) if (!iterationExpression.accept(action)) return false;
    if (body != null) if (!body.accept(action)) return false;

    if (action.shouldVisitStatements) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    return true;
  }
Пример #2
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitDeclSpecifiers) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    if (blockSizeExpression != null) if (!blockSizeExpression.accept(action)) return false;

    if (action.shouldVisitDeclSpecifiers) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    return true;
  }
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitParameterDeclarations) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (declSpec != null) {
      if (!declSpec.accept(action)) {
        return false;
      }
    }
    if (declarator != null) {
      if (!declarator.accept(action)) {
        return false;
      }
    }
    if (action.shouldVisitParameterDeclarations) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    return true;
  }
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitNamespaces) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (fName != null && !fName.accept(action)) return false;

    IASTDeclaration[] decls = getDeclarations(action.includeInactiveNodes);
    for (IASTDeclaration decl : decls) {
      if (!decl.accept(action)) return false;
    }

    if (action.shouldVisitNamespaces && action.leave(this) == ASTVisitor.PROCESS_ABORT)
      return false;

    return true;
  }
Пример #5
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitTokens) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (action.shouldVisitTokens) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    return true;
  }
Пример #6
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitDeclarations) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (!acceptByAttributeSpecifiers(action)) return false;
    if (name != null && !name.accept(action)) return false;

    if (action.shouldVisitDeclarations) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    return true;
  }
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitExpressions) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (action.shouldVisitImplicitNames) {
      for (IASTImplicitName name : getImplicitNames()) {
        if (!name.accept(action)) return false;
      }
    }

    if (operand != null && !operand.accept(action)) return false;

    if (action.shouldVisitExpressions) {
      switch (action.leave(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }
    return true;
  }
 @Override
 public void analyze(
     final AnalysisConfig config,
     final AnalysisResult result,
     final IChecker checker,
     IASTTranslationUnit unit) {
   translationUnit = unit;
   ASTVisitor visitor = createVisitor(config, result, checker);
   visitor.shouldVisitDeclarations = true;
   unit.accept(visitor);
 }
Пример #9
0
  @Override
  public boolean accept(ASTVisitor action) {
    N stack = null;
    ICPPASTIfStatement stmt = this;
    loop:
    for (; ; ) {
      if (action.shouldVisitStatements) {
        switch (action.visit(stmt)) {
          case ASTVisitor.PROCESS_ABORT:
            return false;
          case ASTVisitor.PROCESS_SKIP:
            stmt = null;
            break loop;
          default:
            break;
        }
      }

      if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false;

      IASTNode child = stmt.getConditionExpression();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getConditionDeclaration();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getThenClause();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getElseClause();
      if (child instanceof ICPPASTIfStatement) {
        if (action.shouldVisitStatements) {
          N n = new N(stmt);
          n.fNext = stack;
          stack = n;
        }
        stmt = (ICPPASTIfStatement) child;
      } else {
        if (child != null && !child.accept(action)) return false;
        break loop;
      }
    }

    if (action.shouldVisitStatements) {
      if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) return false;
      while (stack != null) {
        if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) return false;
        stack = stack.fNext;
      }
    }
    return true;
  }
Пример #10
0
 /*
  * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#leave(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
  */
 @Override
 public int leave(IASTTranslationUnit tu) {
   super.leave(tu);
   assert getCurrentContainer().getTypeCode() == ICElement.C_UNIT;
   pop(fDocument.getLength());
   return PROCESS_SKIP;
 }
Пример #11
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitPointerOperators) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
      }
    }
    if (n != null && !n.accept(action)) return false;

    if (action.shouldVisitPointerOperators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
      return false;
    return true;
  }
Пример #12
0
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitDeclarators) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (pointerOps != null) {
      for (IASTPointerOperator op : pointerOps) {
        if (op == null) break;
        if (!op.accept(action)) return false;
      }
    }

    if (!acceptByAttributeSpecifiers(action)) return false;

    if (nested == null && name != null) {
      IASTDeclarator outermost = ASTQueries.findOutermostDeclarator(this);
      if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) {
        if (!name.accept(action)) return false;
        if (action.shouldVisitImplicitNames) {
          for (IASTImplicitName implicitName : getImplicitNames()) {
            if (!implicitName.accept(action)) return false;
          }
        }
      }
    }

    if (nested != null && !nested.accept(action)) return false;

    if (!postAccept(action)) return false;

    if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
      return false;

    return true;
  }
Пример #13
0
  @Override
  public boolean accept(ASTVisitor visitor) {
    if (visitor.shouldVisitCaptures) {
      switch (visitor.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (fIdentifier != null && !fIdentifier.accept(visitor)) return false;

    if (visitor.shouldVisitCaptures && visitor.leave(this) == ASTVisitor.PROCESS_ABORT)
      return false;

    return true;
  }
  @Override
  public boolean accept(ASTVisitor action) {
    if (action.shouldVisitExpressions) {
      switch (action.visit(this)) {
        case ASTVisitor.PROCESS_ABORT:
          return false;
        case ASTVisitor.PROCESS_SKIP:
          return true;
        default:
          break;
      }
    }

    if (fOperand1 != null && !fOperand1.accept(action)) return false;
    if (fOperand2 != null && !fOperand2.accept(action)) return false;

    if (action.shouldVisitExpressions && action.leave(this) == ASTVisitor.PROCESS_ABORT)
      return false;

    return true;
  }
Пример #15
0
 @Override
 public boolean accept(ASTVisitor action) {
   if (action.shouldVisitProblems) {
     switch (action.visit(getProblem())) {
       case ASTVisitor.PROCESS_ABORT:
         return false;
       case ASTVisitor.PROCESS_SKIP:
         return true;
       default:
         break;
     }
     switch (action.leave(getProblem())) {
       case ASTVisitor.PROCESS_ABORT:
         return false;
       case ASTVisitor.PROCESS_SKIP:
         return true;
       default:
         break;
     }
   }
   return true;
 }
Пример #16
0
 /*
  * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#leave(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
  */
 @Override
 public int leave(IASTDeclaration node) {
   super.leave(node);
   boolean isTemplateDecl = isTemplateDecl(node);
   final int endOffset = isTemplateDecl ? getEndOffset(node.getParent()) : getEndOffset(node);
   if (node instanceof IASTFunctionDefinition) {
     final int nodeType;
     if (inClassBody()) {
       nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_METHOD : ICElement.C_METHOD;
     } else {
       nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_FUNCTION : ICElement.C_FUNCTION;
     }
     assert getCurrentContainer().getTypeCode() == nodeType;
     pop(endOffset);
   } else if (node instanceof IASTSimpleDeclaration) {
     IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
     IASTDeclSpecifier declSpec = simpleDecl.getDeclSpecifier();
     boolean isCompositeType = false;
     if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
       isCompositeType = true;
       ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) declSpec;
       final int nodeType;
       switch (compositeTypeSpec.getKey()) {
         case IASTCompositeTypeSpecifier.k_struct:
           nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_STRUCT : ICElement.C_STRUCT;
           break;
         case IASTCompositeTypeSpecifier.k_union:
           nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_UNION : ICElement.C_UNION;
           break;
         case ICPPASTCompositeTypeSpecifier.k_class:
           nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_CLASS : ICElement.C_CLASS;
           break;
         default:
           assert false : "Unexpected composite type specifier"; // $NON-NLS-1$
           return PROCESS_CONTINUE;
       }
       assert getCurrentContainer().getTypeCode() == nodeType;
       pop(isTemplateDecl ? endOffset : getEndOffset(declSpec));
     } else if (declSpec instanceof IASTEnumerationSpecifier) {
       isCompositeType = true;
       assert getCurrentContainer().getTypeCode() == ICElement.C_ENUMERATION;
       pop(getEndOffset(declSpec));
     }
     if (isCompositeType) {
       IASTDeclarator[] declarators = simpleDecl.getDeclarators();
       for (int i = 0; i < declarators.length; i++) {
         IASTDeclarator declarator = declarators[i];
         final String nodeName = getDeclaratorName(declarator);
         final int declStartOffset = getStartOffset(declarator);
         final int declEndOffset = getEndOffset(declarator);
         if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_typedef) {
           push(ICElement.C_TYPEDEF, nodeName, declStartOffset);
           pop(declEndOffset);
         } else if (declarator instanceof IASTFunctionDeclarator
             && !hasNestedPointerOperators(declarator)) {
           final int nodeType;
           if (inClassBody()) {
             nodeType =
                 isTemplateDecl
                     ? ICElement.C_TEMPLATE_METHOD_DECLARATION
                     : ICElement.C_METHOD_DECLARATION;
           } else {
             nodeType =
                 isTemplateDecl
                     ? ICElement.C_TEMPLATE_FUNCTION_DECLARATION
                     : ICElement.C_FUNCTION_DECLARATION;
           }
           push(nodeType, nodeName, declStartOffset);
           pop(declEndOffset);
         } else if (declarator != null) {
           final int nodeType;
           if (inClassBody()) {
             nodeType = ICElement.C_FIELD;
           } else {
             if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_extern) {
               nodeType = ICElement.C_VARIABLE_DECLARATION;
             } else {
               nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_VARIABLE : ICElement.C_VARIABLE;
             }
           }
           push(nodeType, nodeName, declStartOffset);
           pop(declEndOffset);
         }
       }
     }
   } else if (node instanceof IASTASMDeclaration) {
     // ignored
   } else if (node instanceof ICPPASTVisibilityLabel) {
     // ignored
   } else if (node instanceof ICPPASTNamespaceDefinition) {
     // handled below
   } else if (node instanceof ICPPASTNamespaceAlias) {
     // ignored
   } else if (node instanceof ICPPASTUsingDeclaration) {
     // handled in visit
   } else if (node instanceof ICPPASTUsingDirective) {
     // handled in visit
   } else if (node instanceof ICPPASTLinkageSpecification) {
     // declarations get flattened
   } else if (node instanceof ICPPASTTemplateDeclaration) {
     // handled at child declaration level
   } else if (node instanceof ICPPASTTemplateSpecialization) {
     // ignored
   } else if (node instanceof ICPPASTExplicitTemplateInstantiation) {
     // ignored
   } else if (node instanceof IASTProblemDeclaration) {
     // ignored
   }
   return PROCESS_CONTINUE;
 }