Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to add Keyword to CDT Parser

Hi Anitha,

there must a detail which is incorrect.

This is my implementation:

public class IARCScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration {

    private static IARCScannerExtensionConfiguration instance;
   
    public static synchronized IARCScannerExtensionConfiguration getInstance() {
        if(instance == null)
            instance = new IARCScannerExtensionConfiguration();
        return instance;
    }
   
    private IARCScannerExtensionConfiguration() {
        /*
           add part of GNU configuration
        */
        addKeyword(GCCKeywords.cp__ASM, IToken.t_asm);
        addKeyword(GCCKeywords.cp__ASM__, IToken.t_asm);
        addKeyword(GCCKeywords.cp__CONST, IToken.t_const);
        addKeyword(GCCKeywords.cp__CONST__, IToken.t_const);
        addKeyword(GCCKeywords.cp__INLINE, IToken.t_inline);
        addKeyword(GCCKeywords.cp__INLINE__, IToken.t_inline);
        addKeyword(GCCKeywords.cp__VOLATILE, IToken.t_volatile);
        addKeyword(GCCKeywords.cp__VOLATILE__, IToken.t_volatile);
        addKeyword(GCCKeywords.cp__SIGNED, IToken.t_signed);
        addKeyword(GCCKeywords.cp__SIGNED__, IToken.t_signed);
        addKeyword(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof);
        addKeyword(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof);
        addKeyword(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );       
       
        /*
           add IAR C specific configuration
        */       
        addKeyword("__bitvar".toCharArray(), IGCCToken.tIDENTIFIER );       
       
        /*
           add general keywords configuration
        */   
        addKeyword("double".toCharArray(), IGCCToken.tIDENTIFIER );
       
        addMacro("__bitvar", "");
}

In addition find here the definition of the language:
public class IARCLanguage extends GCCLanguage {
   
    public static final String ID = "com.valeo.vws.cdt.iartoolchain.iarclanguage"; //$NON-NLS-1$

    private static IARCLanguage DEFAULT = new IARCLanguage();
   
    public static IARCLanguage getDefault() {
        return DEFAULT;
    }
   
    public String getId() {
        return ID;
    }

    @Override
    protected ISourceCodeParser createParser(IScanner scanner,
            IParserLogService log, IIndex index, boolean forCompletion,
            int options) {
        if (!(scanner instanceof IARCScanner)) {
            scanner = new IARCScanner(scanner);
        }
        return super.createParser(scanner, log, index, forCompletion, options);
    }
   
    @Override
    protected IScannerExtensionConfiguration getScannerExtensionConfiguration(IScannerInfo info) {
        return IARCScannerExtensionConfiguration.getInstance();
    }
   
    @Override
    protected ICParserExtensionConfiguration getParserExtensionConfiguration() {
        return IARCParserExtensionConfiguration.getInstance();
    }

}

Furthermore you need to map the content type to your language. I did this using the org.eclipse.cdt.core.language and org.eclipse.core.contenttype.contentTypes extension points. In addition I added a languate mapping in the project properties->C/C++ General->Language Mappings.

Hope this helps.

Regards, Sebastian

> Date: Mon, 10 Mar 2014 22:33:10 -0700
> From: y_anitha@xxxxxxxxx
> To: cdt-dev@xxxxxxxxxxx
> Subject: Re: [cdt-dev] How to add Keyword to CDT Parser
>
> Hi Sebastian,
>
> Thanks for your suggestion. I did what you mentioned and now my class looks
> like below:
>
> public class NCScannerExtensionConfiguration extends
> GCCScannerExtensionConfiguration {
> public static final String CSTATUS = "_c_status";
> public static final char[] extendcCSTATUS = "_c_status".toCharArray();
>
> public NsCppScannerExtensionConfiguration() {
> addKeyword(extendcCSTATUS, IGCCToken.tIDENTIFIER );
> }
>
> public NsCppScannerExtensionConfiguration(int version) {
> super(version);
> addKeyword(extendcCSTATUS, IGCCToken.tIDENTIFIER );
> }
>
> public CharArrayIntMap getAdditionalKeywords() {
> CharArrayIntMap additionalCKeywords = new CharArrayIntMap(0, 0);
> additionalCKeywords.put(
> NCScannerExtensionConfiguration.extendcppCCSTATUS, IToken.t_class);
> return additionalCKeywords;
> }
> }
>
> Still the keyword is not getting detected. In the outline view it is shown
> as a variable. Is there something i am not doing right?
>
> Thanks once again.
>
> Anitha
>
>
>
> --
> View this message in context: http://eclipse.1072660.n5.nabble.com/How-to-add-Keyword-to-CDT-Parser-tp166002p166030.html
> Sent from the Eclipse CDT - Development mailing list archive at Nabble.com.
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top