Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Your advice
  • From: Ming Cheng <chengm349@xxxxxxxxxxx>
  • Date: Fri, 28 Feb 2020 09:10:33 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d1rtpQrYcb6keR/HBM+vHmWRGICTCZWqLawvQgCHsYY=; b=SKVjxnx6VyIb52TDGctonefmwwJ1LQ3eI31BeJSSD7cGH2V1geclbAOlKttyziFB0tF5CJ0/FScoAW5pKdyQ3RL3vbf0hrirpV4QCefmYfi77z2n19K2G8gFxOpQZZ6JJMUdMv0OoGvm8hoRmDjrOgv+L5Zj7HET4AKJDHH87XRTy32GC1DDfPzhODBuCFb1nZTo4+g0gOonqx/A31xEYHN2kqEiFwf3m47eHjB57fA3PQi57p5fA2Qm0mV0hZKfDMQE5E9TNI/yMuy1bFJwjAdu6swtp+m+AxwXcB3CbKXTHoAM74RZBjquMu6S+8IRoYMtG88Tqdrzx43uiugvzA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rik1YKa19sqNEhT8JgLRyLrE1aTHwBe9Ffp2cXaFMKuTbgt0c8m6UcgdGv1ScQ8NgQZjY5f9o4a2dE7ljaVAFIUjA0xyVAs6QgZdU3q+IJb2+VCpjyWXthW/Cyn4z369b/Uf8DhPpWw3I5it/ltqfNQTYWeMEWppdOuoLmaUopiIWnk/3SeXU6ml3XJeAag4X95DZWFI2m43ZtB4qeRHec6ednRTaAyOzR4fEZ+x2/bbN5WkJoO3/8/+BmrOVHq1Nch22WclzpjdCwJGbL0yuGSZi9ZokemJ5OJqYDPUmjp+lSOi/0i+AfCo1amPYd16nvq6MikH3OIbAV2nM/QswA==
  • Delivered-to: cdt-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/cdt-dev>
  • List-help: <mailto:cdt-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHV65S4k1GaPOv83Eick3ZQtzFoQqgrV4uAgAFgY8uAAA6VgIAAQeShgAFOp1OAAZyGAYAAApGigABccr4=
  • Thread-topic: [cdt-dev] Your advice

This is my code:

 

class CheckCodeVisitor extends ASTVisitor {

 

@Override

    public int visit(IASTDeclaration decl) {

        IASTDeclarationImplClass.visit(index, decl);

        return PROCESS_CONTINUE;

    }

 

}

 

If we check IASTDeclaration document (https://help.eclipse.org/2019-12/index.jsp), we can see these information:

 

 

 

My concern is that if I can use IASTSimpleDeclaration to get all C++ code information, why we need ICPPASTExplicitTemplateInstantiation/ICPPASTxxxxxxx etc?

 

Again this is my IASTDeclarationImplClass code:

 

public class IASTDeclarationImplClass {

    private static final Logger log = LoggerFactory.getLogger(IASTDeclarationImplClass.class);

   

    public static int visit(IIndex index, IASTDeclaration decl) {

        if (decl instanceof CASTAmbiguousSimpleDeclaration) {

            CASTAmbiguousSimpleDeclaration simpleDeclaration = (CASTAmbiguousSimpleDeclaration) decl;

            return visit(index, simpleDeclaration);

        } else if (decl instanceof CASTASMDeclaration) {

            CASTASMDeclaration asmDeclaration = (CASTASMDeclaration) decl;

            return visit(index, asmDeclaration);

        } else if (decl instanceof CASTFunctionDefinition) {

            CASTFunctionDefinition funcDecl = (CASTFunctionDefinition) decl;

            return visit(index, funcDecl);

        } else if (decl instanceof CASTProblemDeclaration) {

            CASTProblemDeclaration problemDecl = (CASTProblemDeclaration) decl;

            return visit(index, problemDecl);

        } else if (decl instanceof CPPASTAmbiguousSimpleDeclaration) {

            CPPASTAmbiguousSimpleDeclaration cppSimpleDeclaration = (CPPASTAmbiguousSimpleDeclaration) decl;

            return visit(index, cppSimpleDeclaration);

        } else if (decl instanceof IASTSimpleDeclaration) {

            IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) decl;

            return visit(index, simpleDeclaration);

        } else if (decl instanceof CPPASTASMDeclaration) {

            CPPASTASMDeclaration cppASMDeclaration = (CPPASTASMDeclaration) decl;

            return visit(index, cppASMDeclaration);

        } else if (decl instanceof CPPASTExplicitTemplateInstantiation) {

            CPPASTExplicitTemplateInstantiation explicitTemplateInstantiation = (CPPASTExplicitTemplateInstantiation) decl;

            return visit(index, explicitTemplateInstantiation);

        } else if (decl instanceof CPPASTFunctionDefinition) {

            CPPASTFunctionDefinition cppFuncDefinition = (CPPASTFunctionDefinition) decl;

            return visit(index, cppFuncDefinition);

        } else if (decl instanceof CPPASTFunctionWithTryBlock) {

            CPPASTFunctionWithTryBlock cppFunctionWithTryBlock = (CPPASTFunctionWithTryBlock) decl;

            return visit(index, cppFunctionWithTryBlock);

        } else if (decl instanceof ICPPASTInternalTemplateDeclaration) {

            ICPPASTInternalTemplateDeclaration internalTempDecl = (ICPPASTInternalTemplateDeclaration) decl;

            return visit(index, internalTempDecl);

        } else if (decl instanceof CPPASTLinkageSpecification) {

            CPPASTLinkageSpecification linkageSpec = (CPPASTLinkageSpecification) decl;

            return visit(index, linkageSpec);

        } else if (decl instanceof CPPASTNamespaceAlias) {

            CPPASTNamespaceAlias nsAlias = (CPPASTNamespaceAlias) decl;

            return visit(index, nsAlias);

        } else if (decl instanceof CPPASTNamespaceDefinition) {

            CPPASTNamespaceDefinition nsDefn = (CPPASTNamespaceDefinition) decl;

            return visit(index, nsDefn);

        } else if (decl instanceof CPPASTProblemDeclaration) {

            CPPASTProblemDeclaration problemDeclaration = (CPPASTProblemDeclaration) decl;

            return visit(index, problemDeclaration);

        } else if (decl instanceof CPPASTSimpleDeclaration) {

            CPPASTSimpleDeclaration cppSimpleDeclaration = (CPPASTSimpleDeclaration) decl;

            return visit(index, cppSimpleDeclaration);

        } else if (decl instanceof CPPASTStaticAssertionDeclaration) {

            CPPASTStaticAssertionDeclaration staticAssertDecl = (CPPASTStaticAssertionDeclaration) decl;

            return visit(index, staticAssertDecl);

        } else if (decl instanceof CPPASTTemplateDeclaration) {

            CPPASTTemplateDeclaration cppTempDecl = (CPPASTTemplateDeclaration) decl;

            return visit(index, cppTempDecl);

        } else if (decl instanceof CPPASTTemplateSpecialization) {

            CPPASTTemplateSpecialization cppTempSpecialization = (CPPASTTemplateSpecialization) decl;

            return visit(index, cppTempSpecialization);

        } else if (decl instanceof CPPASTUsingDeclaration) {

            CPPASTUsingDeclaration cppUsingDecl = (CPPASTUsingDeclaration) decl;

            return visit(index, cppUsingDecl);

        } else if (decl instanceof CPPASTUsingDirective) {

            CPPASTUsingDirective cppUsingDirective = (CPPASTUsingDirective) decl;

            return visit(index, cppUsingDirective);

        } else if (decl instanceof CPPASTVisibilityLabel) {

            CPPASTVisibilityLabel cppVisibilityLabel = (CPPASTVisibilityLabel) decl;

            return visit(index, cppVisibilityLabel);

        } else if (decl instanceof GPPASTExplicitTemplateInstantiation) {

            GPPASTExplicitTemplateInstantiation cppExplicitTemplateInstantiation = (GPPASTExplicitTemplateInstantiation) decl;

            return visit(index, cppExplicitTemplateInstantiation);

        }

       

        return PROCESS_SKIP;

    }

 

 

   private static int visit(IIndex index, CASTAmbiguousSimpleDeclaration simpleDeclaration) {

        display("Visiting CASTAmbiguousSimpleDeclaration: " + simpleDeclaration.getRawSignature());

        return PROCESS_CONTINUE;

    }

}

 

According to yours and Jonah’s replies, it seems the following possible impl should be enough?

 

IASTASMDeclaration, IASTFunctionDefinition, IASTProblemDeclaration, IASTSimpleDeclaration

 

public class IASTDeclarationImplClass {

    private static final Logger log = LoggerFactory.getLogger(IASTDeclarationImplClass.class);

   

    public static int visit(IIndex index, IASTDeclaration decl) {

        if (decl instanceof IASTASMDeclaration) {

            IASTASMDeclaration asmDeclaration = (IASTASMDeclaration) decl;

            return visit(index, asmDeclaration);

        } else if (decl instanceof IASTFunctionDefinition) {

            IASTFunctionDefinition  funcDefn = (IASTFunctionDefinition) decl;

            return visit(index, funcDefn);

        } else if (decl instanceof IASTProblemDeclaration) {

            IASTProblemDeclaration problem = (IASTProblemDeclaration) decl;

            return visit(index, problem);

        }  else if (decl instanceof IASTSimpleDeclaration) {

            IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) decl;

            return visit(index, simpleDeclaration);

        }

        

        return PROCESS_SKIP;

    }

 

 

   private static int visit(IIndex index, IASTSimpleDeclaration simpleDeclaration) {

        display("Visiting IASTSimpleDeclaration: " + simpleDeclaration.getRawSignature());

        // use IASTSimpleDeclaration public API to get more detail information like whether it’s class or struct, or explicit template class instantiation etc?

        return PROCESS_CONTINUE;

    }

 

 

    ……

 

}

Sent from Mail for Windows 10

 

From: Nathan Ridge
Sent: Friday, February 28, 2020 11:26 AM
To: Ming Cheng; CDT General developers list.
Subject: Re: [cdt-dev] Your advice

 

> You said something but I feel they are not relevant to “yet without using internal iface/class” directly.

All of the mentioned interfaces for AST nodes (e.g. IASTSimpleDeclaration, IASTFunctionDefinition, etc.) and the methods for navigating the AST (e.g. IASTSimpleDeclaration.getDeclSpecifier()) are public APIs.

Regards,
Nate

 


Back to the top