[beast: 3/47] V8BSE: V8Stub.py: add helpers for code generation of C++ signal arguments



commit 65424b20c3a00d894750e86e4c968dab5a42c543
Author: Tim Janik <timj gnu org>
Date:   Fri Apr 7 23:14:47 2017 +0200

    V8BSE: V8Stub.py: add helpers for code generation of C++ signal arguments
    
    Signed-off-by: Tim Janik <timj gnu org>

 ebeast/v8bse/V8Stub.py |   55 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/ebeast/v8bse/V8Stub.py b/ebeast/v8bse/V8Stub.py
index 1dc7b26..c2b18ec 100644
--- a/ebeast/v8bse/V8Stub.py
+++ b/ebeast/v8bse/V8Stub.py
@@ -64,6 +64,61 @@ class Generator:
     self.strip_path = ""
     self.idcounter = 1001
     self.marshallers = {}
+  @staticmethod
+  def prefix_namespaced_identifier (prefix, ident, postfix = ''):     # Foo::bar -> Foo::PREFIX_bar_POSTFIX
+    cc = ident.rfind ('::')
+    if cc >= 0:
+      ns, base = ident[:cc+2], ident[cc+2:]
+    else:
+      ns, base = '', ident
+    return ns + prefix + base + postfix
+  def type_absolute_namespaces (self, type_node):
+    tnsl = type_node.list_namespaces() # type namespace list
+    namespace_names = [d.name for d in tnsl if d.name]
+    return namespace_names
+  def type2cpp (self, type_node):
+    tstorage = type_node.storage
+    if tstorage == Decls.VOID:          return 'void'
+    if tstorage == Decls.BOOL:          return 'bool'
+    if tstorage == Decls.INT32:         return 'int'
+    if tstorage == Decls.INT64:         return 'int64_t'
+    if tstorage == Decls.FLOAT64:       return 'double'
+    if tstorage == Decls.STRING:        return 'std::string'
+    if tstorage == Decls.ANY:           return 'Rapicorn::Aida::Any'
+    fullnsname = '::'.join (self.type_absolute_namespaces (type_node) + [ type_node.name ])
+    return fullnsname
+  def C4client (self, type_node):
+    tname = self.type2cpp (type_node)
+    if type_node.storage == Decls.INTERFACE:
+      return tname + 'Handle'                           # construct client class RemoteHandle
+    elif type_node.storage in (Decls.SEQUENCE, Decls.RECORD):
+      return self.prefix_namespaced_identifier ('ClnT_', tname)
+    return tname
+  def C (self, type_node, mode = None):                 # construct Class name
+    return self.C4client (type_node)
+  def R (self, type_node):                              # construct Return type
+    tname = self.C (type_node)
+    return tname
+  def A (self, ident, type_node, defaultinit = None):   # construct call Argument
+    constref = type_node.storage in (Decls.STRING, Decls.SEQUENCE, Decls.RECORD, Decls.ANY)
+    needsref = constref or type_node.storage == Decls.INTERFACE
+    s = self.C (type_node)                      # const {Obj} &foo = 3
+    s += ' ' if ident else ''                   # const Obj{ }&foo = 3
+    if constref:
+      s = 'const ' + s                          # {const }Obj &foo = 3
+    if needsref:
+      s += '&'                                  # const Obj {&}foo = 3
+    s += ident                                  # const Obj &{foo} = 3
+    if defaultinit != None:
+      if type_node.storage == Decls.ENUM:
+        s += ' = %s (%s)' % (self.C (type_node), defaultinit)  # { = 3}
+      elif type_node.storage in (Decls.SEQUENCE, Decls.RECORD):
+        s += ' = %s()' % self.C (type_node)                    # { = 3}
+      elif type_node.storage == Decls.INTERFACE:
+        s += ' = *(%s*) NULL' % self.C (type_node)             # { = 3}
+      else:
+        s += ' = %s' % defaultinit                             # { = 3}
+    return s
   def generate_types_v8 (self, implementation_types):
     s  = '// === Generated by V8Stub.py ===            -*-mode:javascript;-*-\n'
     # includes


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]