1# -*- python -*-
2#                           Package   : omniidl
3# obv.py                    Created on: 2003/10/08
4#			    Author    : Duncan Grisby
5#
6#    Copyright (C) 2003-2011 Apasphere Ltd.
7#
8#  This file is part of omniidl.
9#
10#  omniidl is free software; you can redistribute it and/or modify it
11#  under the terms of the GNU General Public License as published by
12#  the Free Software Foundation; either version 2 of the License, or
13#  (at your option) any later version.
14#
15#  This program is distributed in the hope that it will be useful,
16#  but WITHOUT ANY WARRANTY; without even the implied warranty of
17#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18#  General Public License for more details.
19#
20#  You should have received a copy of the GNU General Public License
21#  along with this program.  If not, see http://www.gnu.org/licenses/
22#
23# Description:
24
25"""Produce the main header OBV definitions for the C++ backend"""
26
27from omniidl_be.cxx import id, config, ast
28from omniidl_be.cxx.header import template
29
30import sys
31self = sys.modules[__name__]
32
33stream = None
34
35def init(s):
36    global stream, __nested
37    stream = s
38    __nested = 0
39    return self
40
41
42def OBV_prefix():
43    if not self.__nested:
44        return "OBV_"
45    return ""
46
47
48# Control arrives here
49#
50def visitAST(node):
51    self.__completedModules = {}
52    for n in node.declarations():
53        if ast.shouldGenerateCodeForDecl(n):
54            n.accept(self)
55
56def visitModule(node):
57    if node in self.__completedModules:
58        return
59    self.__completedModules[node] = 1
60
61    name = id.mapID(node.identifier())
62
63    if not config.state['Fragment']:
64        stream.out(template.OBV_module_begin,
65                   name = name,
66                   OBV_prefix = OBV_prefix())
67        stream.inc_indent()
68
69    nested = self.__nested
70    self.__nested = 1
71    for n in node.definitions():
72        n.accept(self)
73
74    # Splice the continuations together if splice-modules flag is set
75    # (This might be unnecessary as there (seems to be) no relationship
76    #  between things in the POA module- they all point back into the main
77    #  module?)
78    if config.state['Splice Modules']:
79        for c in node.continuations():
80            for n in c.definitions():
81                n.accept(self)
82            self.__completedModules[c] = 1
83
84    self.__nested = nested
85
86    if not config.state['Fragment']:
87        stream.dec_indent()
88        stream.out(template.OBV_module_end)
89    return
90
91def visitInterface(node):
92    pass
93def visitTypedef(node):
94    pass
95def visitEnum(node):
96    pass
97def visitStruct(node):
98    pass
99def visitStructForward(node):
100    pass
101def visitUnion(node):
102    pass
103def visitUnionForward(node):
104    pass
105def visitForward(node):
106    pass
107def visitConst(node):
108    pass
109def visitDeclarator(node):
110    pass
111def visitMember(node):
112    pass
113def visitException(node):
114    pass
115
116def visitValue(node):
117    from omniidl_be.cxx import value
118    v = value.getValueType(node)
119
120    v.obv_module_decls(stream, self)
121
122def visitValueForward(node):
123    from omniidl_be.cxx import value
124    v = value.getValueType(node)
125
126    v.obv_module_decls(stream, self)
127
128def visitValueAbs(node):
129    from omniidl_be.cxx import value
130    v = value.getValueType(node)
131
132    v.obv_module_decls(stream, self)
133
134def visitValueBox(node):
135    from omniidl_be.cxx import value
136    v = value.getValueType(node)
137
138    v.obv_module_decls(stream, self)
139