コード例 #1
0
ファイル: LookupData.java プロジェクト: Traveller7/cdt
  public boolean forFriendship() {
    if (astName == null) return false;
    IASTNode node = astName.getParent();
    while (node instanceof IASTName) node = node.getParent();

    IASTDeclaration decl = null;
    IASTDeclarator dtor = null;
    if (node instanceof ICPPASTDeclSpecifier && node.getParent() instanceof IASTDeclaration) {
      decl = (IASTDeclaration) node.getParent();
    } else if (node instanceof IASTDeclarator) {
      dtor = (IASTDeclarator) node;
      while (dtor.getParent() instanceof IASTDeclarator) dtor = (IASTDeclarator) dtor.getParent();
      if (!(dtor.getParent() instanceof IASTDeclaration)) return false;
      decl = (IASTDeclaration) dtor.getParent();
    } else {
      return false;
    }
    if (decl instanceof IASTSimpleDeclaration) {
      IASTSimpleDeclaration simple = (IASTSimpleDeclaration) decl;
      if (!((ICPPASTDeclSpecifier) simple.getDeclSpecifier()).isFriend()) return false;
      if (dtor != null) return true;
      return simple.getDeclarators().length == 0;
    } else if (decl instanceof IASTFunctionDefinition) {
      IASTFunctionDefinition fnDef = (IASTFunctionDefinition) decl;
      if (!((ICPPASTDeclSpecifier) fnDef.getDeclSpecifier()).isFriend()) return false;
      return (dtor != null);
    }
    return false;
  }
コード例 #2
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;
  }
コード例 #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;
  }