Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Attempting to make a Cosmic C Language Extension

After reading http://www.eclipse.org/forums/index.php/mv/msg/162043/512293/#msg_512293, I'm trying to make a new language extension for the Cosmic dialect of C. Mostly the problem is "@" keywords such as @far. I've looked at bug #237028, and POPCPPScannerExtensionConfiguration.java. I also went off Mike Kucera's message to this group, "Re: [cdt-dev] How to extend the C99 / GCC LR Parser." on 11-Jul-2011 in which he suggests using an ILanguage extension point and providing my own configuration that implements IScannerExtensionConfiguration and defines supportAtSignInIdentifiers().

I've made the language plugin consisting of Activator.java, CosmicCLanguage.Java, and CosmicCScannerExstensionConfiguration.java. I can choose my new language under Language Mappings in the CDT. However the parser still trips up over @far. Here's my parser log (I've deleted some lines to make it smaller):

===== BEGIN parser.log =====
Project:               Foo
File:                  file:/C:/Documents%20and%20Settings/watkinsp/runtime-EclipseApplication/Foo/foo.c
Language:              Cosmic C
Index Version:         132.0
Build Configuration:   Debug
Context:               none
Versions in Index:     1
   C: {}; 0 macros, 0 includes, 1 names;

Include Search Path (option -I):
   c:/mingw/lib/gcc/mingw32/4.7.2/include
   c:/mingw/include
   c:/mingw/lib/gcc/mingw32/4.7.2/include-fixed

Macro definitions (option -D):
   i386=1
   WIN32=1
   WINNT=1
   .
   .
   .

Macro definitions (from language + headers in index):
   __builtin_constant_p(exp)=0
   __builtin_offsetof(T,m)=((size_t) &((T *)0)->m)
   __builtin_types_compatible_p(x,y)=__builtin_types_compatible_p(sizeof(x),sizeof(y))
   __builtin_va_arg(ap,type)=*(typeof(type) *)ap
   __CDT_PARSER__=1
   __complex__=_Complex
   __COUNTER__=0
   __DATE__="Mar 21 2013"
   __extension__=
   __FILE__="file"
   __imag__=(int)
   __LINE__=1
   __null=(void *)0
   __offsetof__(x)=(x)
   __real__=(int)
   __stdcall=
   __STDC_VERSION__=199901L
   __thread=
   __TIME__="14:46:09"

Scanner problems:
   Bad character sequence encountered: @ in file: C:\Documents and Settings\watkinsp\runtime-EclipseApplication\Foo\foo.c:13

Parser problems:
   Syntax error in file: C:\Documents and Settings\watkinsp\runtime-EclipseApplication\Foo\foo.c:13

Written on Thu Mar 21 14:46:09 PDT 2013
===== END parser.log =====


Here's my foo.c:
===== BEGIN foo.c =====
void main(int argc, char **argv) {

}

void @far bar(int baz) {
        baz = 2;
}
===== END foo.c =====


Notice the @far on bar() (line 13). Also notice "Cosmic C" in my parser log for "Language: ". Here are the source files for my plugin:

===== BEGIN CosmicCLanguage.java =====
package com.msei.plugin.cdtextensions;

import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;

/**
 * @author Peter Watkins
 *
 */
public class CosmicCLanguage extends GCCLanguage {
        protected static final CosmicCScannerExtensionConfiguration
        COSMIC_C_SCANNER_EXTENSION = new CosmicCScannerExtensionConfiguration();

        @Override
        public String getId() {
                return "com.msei.plugin.cdtextensions.cosmicc";
        }
       
        @Override
        protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
                return COSMIC_C_SCANNER_EXTENSION;
        }
}
===== END CosmicCLanguage.java =====

===== BEGIN CosmicCScannerExtensionConfiguration.java =====
package com.msei.plugin.cdtextensions;

import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;

public class CosmicCScannerExtensionConfiguration extends
                GCCScannerExtensionConfiguration {
        private static CosmicCScannerExtensionConfiguration sInstance = new CosmicCScannerExtensionConfiguration();
       
        public static CosmicCScannerExtensionConfiguration getInstance() {
                return sInstance;
        }

        public CosmicCScannerExtensionConfiguration() {
                addMacro("@far", "");
        }

        public CosmicCScannerExtensionConfiguration(int version) {
                super(version);
                // TODO Auto-generated constructor stub
        }
       
        @Override
        public boolean supportAtSignInIdentifiers() {
                return true;
        }
}
===== END CosmicCScannerExtensionConfiguration.java =====

===== BEGIN Activator.java =====
package com.msei.plugin.cdtextensions;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

        private static BundleContext context;

        static BundleContext getContext() {
                return context;
        }

        /*
         * (non-Javadoc)
         * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
         */
        public void start(BundleContext bundleContext) throws Exception {
                Activator.context = bundleContext;
        }

        /*
         * (non-Javadoc)
         * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
         */
        public void stop(BundleContext bundleContext) throws Exception {
                Activator.context = null;
        }
}
===== END Activator.java =====


Does anything obvious stand out to you? I'm I even going in the right direction? I'm not entirely sure what I'm doing in the first place :). I'm just trying to adapt what I've already seen.

Thanks,

Peter

Back to the top