Exemple #1
0
def run(tree):
    w = Walker()
    w.cci = output.Stream(open("CCI" + tree.filebase + ".cxx", "w"), 2)
    w.doing_header = 0
    tree.accept(w)
    w.cci = output.Stream(open("CCI" + tree.filebase + ".hxx", "w"), 2)
    w.doing_header = 1
    tree.accept(w)
Exemple #2
0
    def visitAST(self, node):
        directory, basename = os.path.split(node.file())
        self._included = ['xpcom.idl']
        if string.lower(basename[-4:]) == '.idl':
            basename = basename[:-4]
        self.hxx = output.Stream(open('x2p' + basename + '.hxx', 'w'))
        self.cpp = output.Stream(open('x2p' + basename + '.cpp', 'w'))
        gbasename = ''
        for i in basename:
            if (i >= 'A' and i <= 'Z') or (i >= 'a' and i <= 'z'):
                gbasename = gbasename + i
        self.hxx.out("// This output is automatically generated. Do not edit.")
        guardname = 'X2P__' + string.upper(gbasename) + '__INCLUDED'
        self.hxx.out('#ifndef ' + guardname)
        self.hxx.out("#define " + guardname)
        self.hxx.out('#include "Iface' + basename + '.hxx"')
        self.hxx.out('#include "I' + basename + '.h"')
        self.hxx.out('#include "x2pxpcom.hxx"')
        self.cpp.out('#include <exception>')
        self.cpp.out('#include "cda_compiler_support.h"')
        self.cpp.out('#include "p2x' + basename + '.hxx"')
        self.cpp.out('#include "x2p' + basename + '.hxx"')
        self.cpp.out('#include "X2PFactory.hxx"')
        self.cpp.out('#include "P2XFactory.hxx"')
        self.cpp.out('#include "WideCharSupport.h"')
        self.cpp.out('#include "IWrappedPCM.h"')
        self.cpp.out('#include <Utilities.hxx>')
        self.cpp.out('#include <nsMemory.h>')
        for n in node.declarations():
            if n.mainFile():
                self.contextNamespaces = ['x2p']
                n.accept(self)
            else:
                self.leaveNamespaces()
                filename = n.file()
                pos = string.rfind(filename, '/')
                if pos != -1:
                    filename = filename[pos + 1:]

                if not filename in self._included:
                    self._included.append(filename)

                    if filename[-4:] == ".idl":
                        filename = filename[0:-4] + ".hxx"

                    if filename != "xpcom.idl":
                        self.hxx.out('#include "x2p@filename@"',
                                     filename=filename)
        self.leaveNamespaces()
        self.hxx.out('#endif // not ' + guardname)
Exemple #3
0
def run(tree, args):
    inline = 0
    dump   = 0

    for arg in args:
        if arg == "inline":
            inline = 1

        elif arg == "dump":
            dump = 1

        else:
            sys.stderr.write(main.cmdname + ": Warning: ami "
                             "back-end does not understand argument: %s\n" %
                             arg)

    av = AMIVisitor(dump)
    tree.accept(av)

    st = output.Stream(sys.stdout, 2)
    dv = DumpVisitor(st, inline)

    if dump:
        tree.accept(dv)

    else:
        new_tree = av.result()
        new_tree.accept(dv)
Exemple #4
0
    def visitAST(self, node):
        directory, basename = os.path.split(node.file())
        self._included = ['xpcom.idl']
        if string.lower(basename[-4:]) == '.idl':
            basename = basename[:-4]

        self._idl = output.Stream(open('I' + basename + '.idl', 'w'), 2)
        gbasename = ''
        for i in basename:
            if (i >= 'A' and i <= 'Z') or (i >= 'a' and i <= 'z'):
                gbasename = gbasename + i
        self._idl.out(
            "// This output is automatically generated. Do not edit.")
        guardname = 'XPIDL__' + string.upper(gbasename) + '__INCLUDED'
        self._idl.out("#ifndef " + guardname)
        self._idl.out("#define " + guardname)
        self._idl.out('#include "nsISupports.idl"')
        for n in node.declarations():
            if n.mainFile():
                n.accept(self)
            else:
                filename = n.file()
                pos = string.rfind(filename, '/')
                if pos != -1:
                    filename = filename[pos + 1:]

                if not filename in self._included:
                    self._included.append(filename)

                    if filename != "xpcom.idl":
                        self._idl.out('#include "I@filename@"\n',
                                      filename=filename)
        self._idl.out('#endif // not ' + guardname)
        self._idl = None
Exemple #5
0
def run(tree, args):
	debug = False
	genMakefile = False
	skeleton = False
	for a in args:
		if a.find('d', 0, 1) != -1:
			debug = True
		elif a.find('c', 0, 1) != -1:
			confFile = a.split('=')[1]
		elif a.find('m', 0, 1) != -1:
			getMakefile = True
		elif a.find('s', 0, 1) != -1:
			skeleton = True
	parser = make_parser()
	parser.setFeature(feature_namespaces, 0)

	#Process the conf file first
	handler = confHandler()
	parser.setContentHandler(handler)
	parser.parse(confFile)
	confHash = handler.getContents()
	#if args.count('debug') > 0:
	#	debug = True
	
	
	st = output.Stream(sys.stdout, 2)
	nv = NesCVisitor(st, tree, debug, skeleton, confHash)
	tree.accept(nv)
	
	if getMakefile:
		generateMakefile(confHash['conditions'].get('platform', ''), confHash['makefile'])
Exemple #6
0
 def visitInterface(self, node):
     if not node.mainFile():
         return
     self.out = output.Stream(
         open(self.directory + '/' + jnutils.JavaName(node) + ".java", 'w'))
     self.out.out('package ' + self.package + ';')
     self.out.out('public interface ' + jnutils.JavaName(node))
     inh = node.inherits()
     extends = ''
     if len(inh) != 0:
         for inherit in inh:
             if isinstance(inherit, idlast.Declarator) and inherit.alias():
                 inherit = inherit.alias().aliasType().unalias().decl()
             if inherit.scopedName() == ['XPCOM', 'IObject']:
                 continue
             if extends == '':
                 extends = 'extends ' + jnutils.GetClassName(inherit)
             else:
                 extends = extends + ", " + jnutils.GetClassName(inherit)
     self.out.out('  ' + extends)
     self.out.out('{')
     self.out.inc_indent()
     for i in node.contents():
         i.accept(self)
     self.out.dec_indent()
     self.out.out('};')
     self.out = None
Exemple #7
0
def run(tree, args, templates, suffix):
    sa = tools.Aggregator()
    tree.accept(sa)
    if len(sa.getStructs()) == 0:
        return
    name, ext = os.path.splitext(os.path.basename(tree.file()))
    with open(name + '_' + suffix + '.hpp', 'w') as header:
        st = output.Stream(header, 2)

        cv = Serializer(st, templates, suffix)
        tree.accept(cv)
Exemple #8
0
def run(tree, args, templates, suffix):
    ag = tools.Aggregator()
    tree.accept(ag)
    interfaces = ag.getInterfaces()
    module_prefix = ag.getModulePrefix()

    for interface in interfaces:
        with open(interface + '_' + suffix + '.hpp', 'w') as header:
            st = output.Stream(header, 2)

            cv = AdapterHeader(st, interface, suffix, templates,
                               len(ag.getStructs()) != 0)
            tree.accept(cv)

    for interface in interfaces:
        with open(interface + '_' + suffix + '.cpp', 'w') as source:
            st = output.Stream(source, 2)

            cv = AdapterSource(st, interface, suffix, module_prefix, templates)
            tree.accept(cv)
Exemple #9
0
def run(tree, args):
    ha = tools.Aggregator()
    tree.accept(ha)
    includes, stdincludes = ha.getIncludes()
    includes = map(lambda i: os.path.splitext(i)[0], includes)

    name, ext = os.path.splitext(os.path.basename(tree.file()))
    with open(name + '.hpp', 'w') as header:
        st = output.Stream(header, 2)
        cv = Header(st, includes, stdincludes)
        tree.accept(cv)
Exemple #10
0
def run(tree, args):
    inline = 0

    for arg in args:
        if arg == "inline":
            inline = 1

        else:
            sys.stderr.write(main.cmdname + ": Warning: dump "
                             "back-end does not understand argument: %s\n" %
                             arg)

    st = output.Stream(sys.stdout, 2)
    dv = DumpVisitor(st, inline)
    tree.accept(dv)
Exemple #11
0
def run(tree, args):

    DEBUG = "debug" in args
    AGGRESSIVE = "aggressive" in args

    st = output.Stream(sys.stdout, 4)  # set indent for stream
    ev = WiresharkVisitor(st, DEBUG)  # create visitor object

    ev.visitAST(tree)  # go find some operations

    #
    # Grab name of main IDL file being compiled.
    #
    # Assumption: Name is of the form   abcdefg.xyz  (eg: CosNaming.idl)
    #

    fname = path.basename(
        tree.file())  # grab basename only, dont care about path
    nl = string.split(
        fname, ".")[0]  # split name of main IDL file using "." as separator
    # and grab first field (eg: CosNaming)

    if DEBUG:
        for i in ev.oplist:
            print "XXX - Operation node ", i, " repoId() = ", i.repoId()
        for i in ev.atlist:
            print "XXX - Attribute node ", i, " identifiers() = ", i.identifiers(
            )
        for i in ev.enlist:
            print "XXX - Enum node ", i, " repoId() = ", i.repoId()
        for i in ev.stlist:
            print "XXX - Struct node ", i, " repoId() = ", i.repoId()
        for i in ev.unlist:
            print "XXX - Union node ", i, " repoId() = ", i.repoId()

    # create a C generator object
    # and generate some C code

    eg = wireshark_gen_C(ev.st,
                         string.upper(nl),
                         string.lower(nl),
                         string.capitalize(nl) + " Dissector Using GIOP API",
                         debug=DEBUG,
                         aggressive=AGGRESSIVE)
    eg.genCode(ev.oplist, ev.atlist, ev.enlist, ev.stlist,
               ev.unlist)  # pass them onto the C generator
Exemple #12
0
    def visitException(self, node):
        setupOut = 0
        if self.out == None:
            if not node.mainFile():
                return
            self.out = output.Stream(
                open(self.directory + '/' + jnutils.JavaName(node) + ".java",
                     'w'))
            self.out.out('package ' + self.directory + ';')
            setupOut = 1

        self.out.out('public class ' + jnutils.JavaName(node) +
                     ' extends RuntimeException')
        self.out.out('{')
        self.out.inc_indent()

        constructorArgs = ''
        constructorSave = ''
        for n in node.members():
            if constructorArgs != '':
                constructorArgs = constructorArgs + ', '
            for dn in n.declarators():
                constructorSave = constructorSave + (
                    '%s = _%s;' % (jnutils.JavaName(dn), jnutils.JavaName(dn)))

                constructorArgs = \
                    constructorArgs + \
                    jnutils.GetTypeInformation(n.memberType()).javaType(jnutils.Type.IN) +\
                    ' _' + jnutils.JavaName(dn)
                if dn.sizes() != None:
                    constructorArgs = constructorArgs + string.join(
                        map(lambda x: '[%s]' % x, dn.sizes()), '')

        self.out.out('  public ' + node.simplename + '(' + constructorArgs +
                     '){ ' + constructorSave + ' }')
        for n in node.members():
            n.accept(self)
        self.out.dec_indent()
        self.out.out('};')

        if setupOut:
            self.out = None
Exemple #13
0
    def visitEnum(self, node):
        setupOut = 0
        if self.out == None:
            if not node.mainFile():
                return
            self.out = output.Stream(
                open(self.directory + '/' + jnutils.JavaName(node) + ".java",
                     'w'))
            self.out.out('package ' + self.directory + ';')
            setupOut = 1

        self.firstEnumerator = 1
        self.out.out('public enum ' + jnutils.JavaName(node) + '{')
        self.out.inc_indent()
        for e in node.enumerators():
            e.accept(self)
        self.out.dec_indent()
        self.out.out('};')

        if setupOut:
            self.out = None
Exemple #14
0
    def visitAST(self, node):
        directory, basename = os.path.split(node.file())

        self._included = ['xpcom.idl']
        if string.lower(basename[-4:]) == '.idl':
            basename = basename[:-4]

        self.hxx = output.Stream(open('j2p' + basename + '.hxx', 'w'))
        self.cppMod = output.Stream(open('j2p' + basename + 'Mod.cpp', 'w'))
        self.cppSup = output.Stream(open('j2p' + basename + 'Sup.cpp', 'w'))

        self.hxx.out("// This output is automatically generated. Do not edit.")
        self.modname = basename
        self.defname = 'J2P__' + self.modname
        guardname = self.defname + '__INCLUDED'
        self.hxx.out('#ifndef ' + guardname)
        self.hxx.out("#define " + guardname)
        self.hxx.out('#include "pick-jni.h"')
        self.hxx.out('#include "j2psupport.hxx"')
        self.hxx.out('#include "Iface' + basename + '.hxx"')

        self.cppMod.out('#include <exception>')
        self.cppMod.out('#include "cda_compiler_support.h"')
        self.cppMod.out('#include "j2p' + basename + '.hxx"')
        self.cppMod.out('#include "p2j' + basename + '.hxx"')
        self.cppMod.out('#include <Utilities.hxx>')
        self.cppSup.out('#include <exception>')
        self.cppSup.out('#include "cda_compiler_support.h"')
        self.cppSup.out('#include "j2p' + basename + '.hxx"')
        self.cppSup.out('#include "p2j' + basename + '.hxx"')
        self.cppSup.out('#include <Utilities.hxx>')
        for n in node.declarations():
            if n.mainFile():
                pass
            else:
                filename = n.file()
                pos = string.rfind(filename, '/')
                if pos != -1:
                    filename = filename[pos + 1:]

                if not filename in self._included:
                    self._included.append(filename)

                    if filename[-4:] == ".idl":
                        filename = filename[0:-4] + ".hxx"

                    if filename != "xpcom.idl":
                        self.hxx.out('#include "j2p@filename@"',
                                     filename=filename)

        self.hxx.out('#undef PUBLIC_JAVAMOD_PRE')
        self.hxx.out('#undef PUBLIC_JAVAMOD_POST')
        self.hxx.out('#ifdef IN_MODULE_%s' % self.defname)
        self.hxx.out('#define PUBLIC_JAVAMOD_PRE CDA_EXPORT_PRE')
        self.hxx.out('#define PUBLIC_JAVAMOD_POST CDA_EXPORT_POST')
        self.hxx.out('#else')
        self.hxx.out('#define PUBLIC_JAVAMOD_PRE CDA_IMPORT_PRE')
        self.hxx.out('#define PUBLIC_JAVAMOD_POST CDA_IMPORT_POST')
        self.hxx.out('#endif')
        self.hxx.out('#undef PUBLIC_JAVALIB_PRE')
        self.hxx.out('#undef PUBLIC_JAVALIB_POST')
        self.hxx.out('#ifdef IN_LIBRARY_%s' % self.defname)
        self.hxx.out('#define PUBLIC_JAVALIB_PRE CDA_EXPORT_PRE')
        self.hxx.out('#define PUBLIC_JAVALIB_POST CDA_EXPORT_POST')
        self.hxx.out('#else')
        self.hxx.out('#define PUBLIC_JAVALIB_PRE CDA_IMPORT_PRE')
        self.hxx.out('#define PUBLIC_JAVALIB_POST CDA_IMPORT_POST')
        self.hxx.out('#endif')

        for n in node.declarations():
            if n.mainFile():
                n.accept(self)
        self.hxx.out('#endif // not ' + guardname)
Exemple #15
0
def run(tree, args):
    st = output.Stream(sys.stdout, 2)
    dv = ZeroMQVisitor(st)
    tree.accept(dv)
Exemple #16
0
    def visitInterface(self, node):
        if not node.mainFile():
            return
        self.out = output.Stream(
            open(self.directory + '/' + jnutils.JavaName(node) + ".java", 'w'))
        self.out.out('package ' + self.package + ';')
        self.out.out('public class ' + jnutils.JavaName(node))
        self.out.out('  implements ' + jnutils.GetClassName(node) +
                     ", pjm.XPCOMDerived")
        self.out.out('{')
        self.out.inc_indent()
        self.out.out('private ' + jnutils.JavaName(node) + '() {};')
        self.out.out('protected native void finalize();')
        self.out.out('public int compareTo(Object obj)')
        self.out.out('{')
        self.out.inc_indent()
        self.out.out('try')
        self.out.out('{')
        self.out.inc_indent()
        self.out.out('long v1 = fetchIObject();')
        self.out.out('long v2 = ((pjm.XPCOMDerived)obj).fetchIObject();')
        self.out.out('if (v1 == v2) return 0;')
        self.out.out('if (v1 > v2) return 1;')
        self.out.out('return -1;')
        self.out.dec_indent()
        self.out.out('}')
        self.out.out('catch (ClassCastException cce) { return -1; }')
        self.out.dec_indent()
        self.out.out('}')

        self.out.out('public boolean equals(Object obj)')
        self.out.out('{')
        self.out.inc_indent()
        self.out.out('try')
        self.out.out('{')
        self.out.out('long v1 = fetchIObject();')
        self.out.out('long v2 = ((pjm.XPCOMDerived)obj).fetchIObject();')
        self.out.out('return (v1 == v2);')
        self.out.out('}')
        self.out.out('catch (ClassCastException cce) { return false; }')
        self.out.dec_indent()
        self.out.out('}')

        self.out.out('public native int hashCode();')
        self.recurseAcceptInheritedContents(node)
        self.out.out('private long nativePtr;')
        self.out.out('private long nativePtr_xpcom_iobject;')
        self.out.out(
            'public long fetchIObject() { return nativePtr_xpcom_iobject; }')
        self.out.out('public static ' + jnutils.JavaName(node) +
                     ' queryInterface(pjm.XPCOMDerived obj)')
        self.out.out('{')
        self.out.inc_indent()
        self.out.out('return nqueryInterface(obj.fetchIObject());')
        self.out.dec_indent()
        self.out.out('}')
        self.out.out('private static native ' + jnutils.JavaName(node) +
                     ' nqueryInterface(long obj);')
        self.out.dec_indent()
        self.out.out('};')
        self.out = None
Exemple #17
0
def run(tree, args):
    st = output.Stream(sys.stdout, 2)
    dv = ExtractVisitor(st)
    tree.accept(dv)
    dv.writeAll()
Exemple #18
0
def run(tree, args):
    st = output.Stream(sys.stdout, 2)
    main = Main_head(st, tree, args)

    # And then write everything to the to-be-generated header file
    main.writeAll()
Exemple #19
0
def run(tree, args):
    st = output.Stream(sys.stdout, 2)
    dv = StandardVisitor(st)
    tree.accept(dv)
    # And then write everything to the to-be-generated header file
    dv.writeAll()
Exemple #20
0
    def visitAST(self, node):
        directory, basename = os.path.split(node.file())

        self._included = ['xpcom.idl']
        if string.lower(basename[-4:]) == '.idl':
            basename = basename[:-4]
        self.hxx = output.Stream(open('p2j' + basename + '.hxx', 'w'))
        self.cpp = output.Stream(open('p2j' + basename + '.cpp', 'w'))
        self.hxx.out("// This output is automatically generated. Do not edit.")
        self.modname = basename
        self.defname = 'P2J__' + self.modname
        guardname = self.defname + '__INCLUDED'
        self.hxx.out('#ifndef ' + guardname)
        self.hxx.out("#define " + guardname)
        self.hxx.out('#include <exception>')
        self.hxx.out('#include "cda_compiler_support.h"')
        self.hxx.out('#include "pick-jni.h"')
        self.hxx.out('#include "Iface' + basename + '.hxx"')
        self.hxx.out('#include "p2jxpcom.hxx"')
        self.cpp.out('#ifndef MODULE_CONTAINS_' + self.defname)
        self.cpp.out('#define MODULE_CONTAINS_' + self.defname)
        self.cpp.out('#endif')
        self.cpp.out('#include <exception>')
        self.cpp.out('#include "cda_compiler_support.h"')
        self.cpp.out('#include "j2p' + basename + '.hxx"')
        self.cpp.out('#include "p2j' + basename + '.hxx"')
        self.cpp.out('#include <Utilities.hxx>')

        self.hxx.out('#ifdef MODULE_CONTAINS_' + self.defname)
        self.hxx.out('#define PUBLIC_' + self.defname + '_PRE CDA_EXPORT_PRE')
        self.hxx.out('#define PUBLIC_' + self.defname +
                     '_POST CDA_EXPORT_POST')
        self.hxx.out('#else')
        self.hxx.out('#define PUBLIC_' + self.defname + '_PRE CDA_IMPORT_PRE')
        self.hxx.out('#define PUBLIC_' + self.defname +
                     '_POST CDA_IMPORT_POST')
        self.hxx.out('#endif')

        for n in node.declarations():
            if n.mainFile():
                self.contextNamespaces = ['p2j']
                n.accept(self)
            else:
                filename = n.file()
                pos = string.rfind(filename, '/')
                if pos != -1:
                    filename = filename[pos + 1:]

                if not filename in self._included:
                    self._included.append(filename)

                    self.leaveNamespaces()

                    if filename[-4:] == ".idl":
                        filename = filename[0:-4] + ".hxx"

                    if filename != "xpcom.idl":
                        self.leaveNamespaces()
                        self.hxx.out('#include "p2j@filename@"',
                                     filename=filename)

                    self.contextNamespaces = ['p2j']
        self.leaveNamespaces()
        self.hxx.out('#endif // not ' + guardname)
Exemple #21
0
def run(tree):
    w = Walker()
    w.cxxheader = output.Stream(open("Iface" + tree.filebase + ".hxx", "w"), 2)
    tree.accept(w)
Exemple #22
0
	def visitModule(self, node):
		moduleName = node.identifier()
		self.module = moduleName
		self.debug('Start generating module ' + moduleName)
		
		# run through all AST, for gathering information about header file
		for n in node.definitions():
			n.accept(self)			
		self.firstRound = False
		for n in node.definitions():
			n.accept(self)
			
		self.interfaces['Application'] = 'Application' + componentSuffix
		
		# Handle all typedef
		self.debug('\tStart generating typedef')
		f = open(moduleName + '_type' + self.h_ext, 'w')
		stTypedef = output.Stream(f, 2);
		# FIXME: how to handler forwarder ?
		for i in self.interfaces:
			stTypedef.out('typedef uint16_t @interface@_t;', interface = i)
		for i in self.skipintf:
			stTypedef.out('typedef uint16_t @interface@_t;', interface = i)
		stTypedef.out('\n')
		for t in self.typedef:
			stTypedef.out(t)
		f.close()
		self.debug('\tFinish generating typedef\n')
	
		# Handle all const
		# TODO: put the copyright and condition check here(ifndef)
		self.debug('\tStart generating const')
		f = open(moduleName + '_const' + self.h_ext, 'w')
		stCons = output.Stream(f, 2);
		for t in self.const:
			stCons.out(t)
		f.close()
		self.debug('\tFinish generating const\n')
		
		# Handle struct
		self.debug('\tStart generating struct')
		f = open(moduleName + '_struct' + self.h_ext, 'w')
		stStruct = output.Stream(f, 2);
		for t in self.struct:
			stStruct.out(t)
		f.close()
		self.debug('\tFinish generating struct\n')
		
		# Handle enum
		self.debug('\tStart generating enum')
		f = open(moduleName + '_enum' + self.h_ext, 'w')
		stEnum = output.Stream(f, 2);
		for t in self.enum:
			stEnum.out(t)
		f.close()
		self.debug('\tFinish generating enum\n')
		
		# Then generate the module file
		# TODO: Some kind of template here?
		f = open(moduleName + self.nesc_ext, 'w')
		stConf = output.Stream(f, 2)
		stConf.out('''//$Id: nesc.py,v 1.4 2008-08-11 19:49:34 pruet Exp $

/*Copyright (c) 2008 University of Massachusetts, Boston 
All rights reserved. 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the University of Massachusetts, Boston  nor 
the names of its contributors may be used to endorse or promote products 
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OF
MASSACHUSETTS, BOSTON OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
		''')
		stConf.out('//This file is generated from @name@ by omniidl (nesC backend)- omniORB_4_1. Do not edit manually.', name = self.tree.file())
		stConf.out('//Header block')
		if len(self.enum) > 0:
			stConf.out('includes @name@_enum;', name = moduleName)
		if len(self.typedef) > 0:
			stConf.out('includes @name@_type;', name = moduleName)
		if len(self.struct) > 0:
			stConf.out('includes @name@_struct;', name = moduleName)
		if len(self.const) > 0:
			stConf.out('includes @name@_const;', name = moduleName)
		if len(self.headers) > 0:
			for h in self.headers:
				stConf.out('includes @name@;', name = h)

		stConf.out('//Configuration block')
		stConf.out('configuration @id@ {', id = moduleName)
		stConf.out('}\n')
		stConf.out('//Implementation block')
		stConf.out('implementation {')
		for i in self.interfaces.keys():
			if self.interfaces[i] not in self.components and i not in self.implementations.keys():
				self.components.append(self.interfaces[i])
		for i in self.implementations.keys():
			self.components.remove(i)
			if self.implementations[i] not in self.components:
				self.components.append(self.implementations[i])
		stConf.out('\tcomponents ' + string.join(self.components, ', ') + ';\n')
		for s in self.dotStar:
			for c in self.components:
				if c != s.split('.')[0] and c not in self.stdctrl and c in self.components:
					if c in self.implementations.keys():
						c = self.implementations[c]
					stConf.out('\t@fr@ -> @to@;', fr = s, to = c)
		for pair in self.connections:
			c = pair['to']
			s = pair['from']
			if c.split('.')[0] in self.components and s.split('.')[0] in self.components:
				if c.split('.')[0] in self.implementations.keys():
					c = self.implementations[c.split('.')[0]] + '.' + c.split('.')[1]
				if s.split('.')[0] in self.implementations.keys():
					s = self.implementations[s.split('.')[0]] + '.' + s.split('.')[1]
				stConf.out('\t@fr@ -> @to@;', fr = s, to = c)
			if c.split('.')[0] in self.implementations.keys() and s.split('.')[0] in self.components:
				c = self.implementations[c.split('.')[0]]# + '.' + c.split('.')[1]
				stConf.out('\t@fr@ -> @to@;', fr = s, to = c)
			if s.split('.')[0] in self.implementations.keys() and c.split('.')[0] in self.components:
				s = self.implementations[s.split('.')[0]] + '.' + s.split('.')[1]
				stConf.out('\t@fr@ -> @to@;', fr = s, to = c)
				
				
		for i in self.interfaces:	
			self.debug('\tStart generating interface ' + i)
			fi = open(i + self.nesc_ext, 'w')
			stIntf = output.Stream(fi, 2)
			stIntf.out('''//$Id: nesc.py,v 1.4 2008-08-11 19:49:34 pruet Exp $

/*Copyright (c) 2008 University of Massachusetts, Boston 
All rights reserved. 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

	Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
	Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
    Neither the name of the University of Massachusetts, Boston  nor 
the names of its contributors may be used to endorse or promote products 
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OF
MASSACHUSETTS, BOSTON OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
			''')
			stIntf.out('//This file is generated from IDL/Configuration. Do not edit manually')
			if i in self.stdctrl:
				provides = []
			else:
				provides = ['StdControl']
			uses = []
		
			for pair in self.connections:
				if pair['from'].split('.')[0] == self.interfaces[i]:
					if pair['from'].split('.')[1] not in uses:
						uses.append(pair['from'].split('.')[1])
				if pair['to'].split('.')[0] == self.interfaces[i]:
					if len(pair['from'].split('.')) > 1:
						if pair['from'].split('.')[1] not in provides:
							provides.append(pair['from'].split('.')[1])
					elif pair['from'] not in provides:
						provides.append(pair['from'])
			if self.inherit.has_key(i):
				stIntf.out('//Ancestors List:')
				for ih in self.inherit[i]:
					if ih not in uses:
						#uses.append(ih)
						stIntf.out('//\t@name@', name = ih)
			if i not in provides:
				provides.append(i)
			stIntf.out('interface ' + i + ' {')
			if self.skeleton:
				cname = self.interfaces[i]
				#cname = i + componentSuffix
				if cname in self.implementations.keys():
					cname = self.implementations[cname]
				mi = open(cname + self.nesc_ext, 'w')
				stMod = output.Stream(mi, 2)
				stMod.out('//This file is generated from IDL/Configuration. please use it as the skelton file for your module')				
				if self.inherit.has_key(i):
					stMod.out('//Ancestors List:')
					for ih in self.inherit[i]:
						stMod.out('//\t@name@', name = ih)
				stMod.out('module @name@ {', name = cname)
				stMod.out('\tprovides {')
				#stMod.out('\t\t interface @interface@;', interface = i)
				if len(provides) > 0:
					for p in provides:
						stMod.out('\t\tinterface @interface@;', interface = p)
				stMod.out('\t}')
				if len(uses) > 0:
					stMod.out('\tuses {')
					for u in uses:
						stMod.out('\t\tinterface @interface@;', interface = u)
					stMod.out('\t}')
				stMod.out('}')
				stMod.out('implementation {')
				
			#FIXME
			if self.skeleton:
				stMod.out('\tcommand result_t StdControl.init ()\n\t{\n\t}\n')
				stMod.out('\tcommand result_t StdControl.start ()\n\t{\n\t}\n')
				stMod.out('\tcommand result_t StdControl.stop ()\n\t{\n\t}\n')
			empty = True;
			if self.operations.has_key(i):
				empty = False;
				for o in self.operations[i]:
					stIntf.out('\tcommand  @op@;', op = o)
					if self.skeleton:
						opa = o.split(' ')
						if opa[1] == '*':
							stMod.out('\tcommand @ret@* @interface@.@op@\n\t{\n\t}\n', ret = opa[0], interface = i, op = string.join(opa[2:], ' '))
						else:
							stMod.out('\tcommand @ret@ @interface@.@op@\n\t{\n\t}\n', ret = opa[0], interface = i, op = string.join(opa[1:], ' '))
			for ec in self.commandReturn.keys():
				if i == ec.split(':')[1]:
					empty = False;
					params_list = []
					for p in self.commandParameters[ec]:
						params_list.append(p)
					stIntf.out('\tcommand %s %s (%s);' % (self.commandReturn[ec], ec.split(':')[0], string.join(params_list, ', ')))
			for ec in self.eventReturn.keys():
				if i == ec.split(':')[1]:
					empty = False;
					params_list = []
					for p in self.eventParameters[ec]:
						params_list.append(p)
					stIntf.out('\tevent %s %s (%s);' % (self.eventReturn[ec], ec.split(':')[0], string.join(params_list, ', ')))
			if self.skeleton:		
				for ec in self.commandReturn.keys():
					if i == ec.split(':')[1]:
						params_list = []
						for p in self.commandParameters[ec]:
							params_list.append(p)
						stMod.out('\tcommand %s %s.%s (%s) \n\t{\n\t}\n' % (self.commandReturn[ec], ec.split(':')[1], ec.split(':')[0], string.join(params_list, ', ')))
				for u in uses:
					for ec in self.eventReturn.keys():
						if u == ec.split(':')[1]:
							params_list = []
							for p in self.eventParameters[ec]:
								params_list.append(p)
							stMod.out('\tevent %s %s.%s (%s) \n\t{\n\t}\n' % (self.eventReturn[ec], ec.split(':')[1], ec.split(':')[0], string.join(params_list, ', ')))
				
			if empty:
				stIntf.out(';')
			if self.inherit.has_key(i):
				for ih in self.inherit[i]:
					if self.operations.has_key(ih):
						for o in self.operations[ih]:
							stIntf.out('\t//Inherited from @name@', name = ih)
							stIntf.out('\tcommand  @op@;', op = o)
							if self.skeleton:
								stMod.out('\t//Inherited from @name@', name = ih)
								opa = o.split(' ')
								if opa[1] == '*':
									stMod.out('\tcommand @ret@* @interaface@.@op@\n\t{\n\t}', ret = opa[0], interaface = i, op = string.join(opa[2:], ' '))
								else:
									stMod.out('\tcommand @ret@ @interaface@.@op@\n\t{\n\t}', ret = opa[0], interaface = i, op = string.join(opa[1:], ' '))
			stIntf.out('}')	
			if self.skeleton:
				stMod.out('}')
			self.debug('\tFinish generating interface ' + i + '\n')
		stConf.out('}');
		self.debug('Finish generating module ' + moduleName)
		f.close()