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
 public String getTypeName() {
   if (newTypeName != null) return newTypeName;
   INodeFactory nodeFactory = name.getTranslationUnit().getASTNodeFactory();
   IASTParameterDeclaration declaration = getParameterDeclaration(nodeFactory, null);
   ASTWriterVisitor writer = new ASTWriterVisitor();
   declaration.accept(writer);
   return writer.toString();
 }
Пример #3
0
 public String getReturnType() {
   if (!isReturnValue()) return null;
   INodeFactory nodeFactory = name.getTranslationUnit().getASTNodeFactory();
   IASTDeclarator sourceDeclarator = getDeclarator();
   IASTDeclSpecifier declSpec = safeCopy(getDeclSpecifier());
   IASTDeclarator declarator = createDeclarator(nodeFactory, sourceDeclarator, null);
   IASTParameterDeclaration declaration =
       nodeFactory.newParameterDeclaration(declSpec, declarator);
   ASTWriterVisitor writer = new ASTWriterVisitor();
   declaration.accept(writer);
   return writer.toString();
 }