コード例 #1
0
  public IASTDeclaration getPrimaryDeclaration() {
    // first check if we already know it
    if (declarations != null) {
      for (IASTDeclarator dtor : declarations) {
        if (dtor == null) {
          break;
        }
        dtor = ASTQueries.findOutermostDeclarator(dtor);
        IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
        if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) return decl;
      }
    }
    if (definition != null) {
      IASTDeclarator dtor = ASTQueries.findOutermostDeclarator(definition);
      IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
      if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) return decl;
    }

    final char[] myName = getASTName().getLookupKey();
    ICPPClassScope scope = (ICPPClassScope) getScope();
    ICPPASTCompositeTypeSpecifier compSpec =
        (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
    if (compSpec != null) {
      IASTDeclaration[] members = compSpec.getMembers();
      for (IASTDeclaration member : members) {
        if (member instanceof IASTSimpleDeclaration) {
          IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators();
          for (IASTDeclarator dtor : dtors) {
            IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName();
            if (CharArrayUtils.equals(name.getLookupKey(), myName)
                && name.resolveBinding() == this) {
              return member;
            }
          }
        } else if (member instanceof IASTFunctionDefinition) {
          final IASTFunctionDeclarator declarator =
              ((IASTFunctionDefinition) member).getDeclarator();
          IASTName name = ASTQueries.findInnermostDeclarator(declarator).getName();
          if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) {
            return member;
          }
        }
      }
    }
    return null;
  }
コード例 #2
0
ファイル: CPPASTDeclarator.java プロジェクト: zhaog/cdt
  @Override
  public int getRoleForName(IASTName n) {
    // 3.1.2
    IASTNode parent = ASTQueries.findOutermostDeclarator(this).getParent();
    if (parent instanceof IASTDeclaration) {
      // a declaration is a definition unless ...
      if (parent instanceof IASTFunctionDefinition) return r_definition;

      if (parent instanceof IASTSimpleDeclaration) {
        final IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) parent;

        // unless it declares a function without body
        if (this instanceof IASTFunctionDeclarator) {
          return r_declaration;
        }

        final int storage = sdecl.getDeclSpecifier().getStorageClass();
        // unless it contains the extern specifier or a linkage-specification and neither
        // initializer nor function-body
        if (getInitializer() == null
            && (storage == IASTDeclSpecifier.sc_extern || isSimpleLinkageSpec(sdecl))) {
          return r_declaration;
        }
        // unless it declares a static data member in a class declaration
        if (storage == IASTDeclSpecifier.sc_static
            && CPPVisitor.getContainingScope(parent) instanceof ICPPClassScope) {
          return r_declaration;
        }
        // unless it is a class name declaration: no declarator in this case
        // unless it is a typedef declaration
        if (storage == IASTDeclSpecifier.sc_typedef)
          return r_definition; // should actually be a declaration

        // unless it is a using-declaration or using-directive: no declarator in this case
      }

      // all other cases
      return r_definition;
    }

    if (parent instanceof IASTTypeId) return r_reference;

    if (parent instanceof IASTParameterDeclaration)
      return (n.getLookupKey().length > 0) ? r_definition : r_declaration;

    return r_unclear;
  }
コード例 #3
0
  private ICPPASTFunctionDeclarator findFunctionDeclarator() {
    if (declarations != null) {
      for (IASTDeclarator dtor : declarations) {
        if (dtor == null) break;

        dtor = ASTQueries.findOutermostDeclarator(dtor);
        IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
        if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) {
          dtor = ASTQueries.findTypeRelevantDeclarator(dtor);
          if (dtor instanceof ICPPASTFunctionDeclarator) {
            return (ICPPASTFunctionDeclarator) dtor;
          }
        }
      }
    }
    return definition;
  }
コード例 #4
0
ファイル: CPPASTDeclarator.java プロジェクト: zhaog/cdt
  @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;
  }