コード例 #1
0
  private void visitFunc(IASTFunctionDefinition declaration) throws BadLocationException {
    IASTStatement body = declaration.getBody();
    if (!(body instanceof IASTCompoundStatement)) return;

    // starting a function empties the stack... (which should already be empty on good flow)
    _scopeStack.clear();

    IASTFileLocation location = body.getFileLocation();
    int endLoc = location.getNodeOffset() + location.getNodeLength() - 1;

    IASTFunctionDeclarator declerator = declaration.getDeclarator();
    int startLoc = declerator.getFileLocation().getNodeOffset();

    StringBuffer hint = new StringBuffer();
    hint.append(declerator.getName().getRawSignature());
    /* TODO: specific params: exclude function parameters (show only the name) */
    hint.append("( "); // $NON-NLS-1$
    IASTNode[] decChildren = declerator.getChildren();
    boolean firstParam = true;
    for (int i = 0; i < decChildren.length; i++) {
      IASTNode node = decChildren[i];
      if (node instanceof IASTParameterDeclaration) {
        IASTParameterDeclaration param = (IASTParameterDeclaration) node;
        if (firstParam) firstParam = false;
        else hint.append(", "); // $NON-NLS-1$
        hint.append(param.getDeclarator().getName());
      }
    }
    hint.append(" )"); // $NON-NLS-1$

    _container.add(new Hint("function", startLoc, endLoc, hint.toString())); // $NON-NLS-1$
  }
コード例 #2
0
 /*
  * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
  */
 @Override
 public int visit(IASTDeclaration node) {
   boolean isTemplateDecl = isTemplateDecl(node);
   final int startOffset =
       isTemplateDecl ? getStartOffset(node.getParent()) : getStartOffset(node);
   final int endOffset = getEndOffset(node);
   if (node instanceof IASTFunctionDefinition) {
     IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node;
     final int nodeType;
     if (inClassBody()) {
       nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_METHOD : ICElement.C_METHOD;
     } else {
       nodeType = isTemplateDecl ? ICElement.C_TEMPLATE_FUNCTION : ICElement.C_FUNCTION;
     }
     push(nodeType, getDeclaratorName(functionDef.getDeclarator()), startOffset);
     pop(endOffset);
     return PROCESS_SKIP;
   } else if (node instanceof IASTSimpleDeclaration) {
     IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node;
     IASTDeclSpecifier declSpec = simpleDecl.getDeclSpecifier();
     if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
       ICPPASTCompositeTypeSpecifier compositeTypeSpec = (ICPPASTCompositeTypeSpecifier) declSpec;
       final String nodeName = getTypeName(compositeTypeSpec);
       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;
       }
       push(nodeType, nodeName, startOffset);
     } else if (declSpec instanceof IASTEnumerationSpecifier) {
       IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) declSpec;
       push(ICElement.C_ENUMERATION, getEnumerationName(enumSpecifier), startOffset);
     } else {
       IASTDeclarator[] declarators = simpleDecl.getDeclarators();
       for (int i = 0; i < declarators.length; i++) {
         IASTDeclarator declarator = declarators[i];
         int declStartOffset = declarators.length == 1 ? startOffset : getStartOffset(declarator);
         int declEndOffset = declarators.length == 1 ? endOffset : getEndOffset(declarator);
         final String nodeName = getDeclaratorName(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) {
     ICPPASTUsingDeclaration usingDecl = (ICPPASTUsingDeclaration) node;
     push(ICElement.C_USING, ASTStringUtil.getQualifiedName(usingDecl.getName()), startOffset);
     pop(endOffset);
   } else if (node instanceof ICPPASTUsingDirective) {
     ICPPASTUsingDirective usingDirective = (ICPPASTUsingDirective) node;
     push(
         ICElement.C_USING,
         ASTStringUtil.getQualifiedName(usingDirective.getQualifiedName()),
         startOffset);
     pop(endOffset);
   } 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 super.visit(node);
 }