diff options
author | Juergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com> | 2018-01-24 11:45:33 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com> | 2018-01-24 11:45:33 +0100 |
commit | cf676a4340f64f6a5b9f38b4e2bd3401c6d57d47 (patch) | |
tree | 0dab03a7c79cecf98c468ebce8e3a68bcfa938ae | |
parent | 58b695f9c4b609a027d595398a1660625b49682a (diff) | |
download | qtivi-qface-cf676a4340f64f6a5b9f38b4e2bd3401c6d57d47.tar.gz |
added depencies detection support for symbols.
See symbol.dependencies. It returns a list of TypeSymbol. There are
filters in the qtcpp helpers which make use of these dependencies.
The idea is that we can generate header includes and source includes
for the individual C++ documents.
-rw-r--r-- | qface/helper/qtcpp.py | 69 | ||||
-rw-r--r-- | qface/idl/domain.py | 7 |
2 files changed, 62 insertions, 14 deletions
diff --git a/qface/helper/qtcpp.py b/qface/helper/qtcpp.py index dc37f2a..015bfdb 100644 --- a/qface/helper/qtcpp.py +++ b/qface/helper/qtcpp.py @@ -18,7 +18,7 @@ class Filters(object): @staticmethod def defaultValue(symbol): prefix = Filters.classPrefix - t = symbol.type # type: qface.domain.TypeSymbol + t = symbol.type if t.is_primitive: if t.is_int: return 'int(0)' @@ -38,18 +38,20 @@ class Filters(object): return '{0}{1}Module::{2}'.format(prefix, module_name, value) elif t.is_flag: return '0' - elif symbol.type.is_list: - nested = Filters.returnType(symbol.type.nested) + elif t.is_list: + nested = Filters.returnType(t.nested) return 'QVariantList()'.format(nested) - elif symbol.type.is_struct: - return '{0}{1}()'.format(prefix, symbol.type) - elif symbol.type.is_model: - nested = symbol.type.nested + elif t.is_struct: + return '{0}{1}()'.format(prefix, t) + elif t.is_model: + nested = t.nested if nested.is_primitive: return 'new {0}VariantModel(this)'.format(prefix) elif nested.is_complex: return 'new {0}{1}Model(this)'.format(prefix, nested) - return 'XXX' + elif t.is_interface: + return 'nullptr' + raise Exception("Unknown symbol type") @staticmethod def parameterType(symbol): @@ -78,9 +80,12 @@ class Filters(object): return '{0}VariantModel *{1}'.format(prefix, symbol) elif nested.is_complex: return '{0}{1}Model *{2}'.format(prefix, nested, symbol) - else: - return 'const {0}{1} &{2}'.format(prefix, symbol.type, symbol) - return 'XXX' + elif symbol.type.is_complex: + if symbol.type.is_interface: + return '{0} *{1}'.format(symbol.type, symbol) + else: + return 'const {0}{1} &{2}'.format(prefix, symbol.type, symbol) + raise Exception("Unknown symbol type") @staticmethod def returnType(symbol): @@ -113,9 +118,43 @@ class Filters(object): return '{0}VariantModel *'.format(prefix) elif nested.is_complex: return '{0}{1}Model *'.format(prefix, nested) - else: - return '{0}{1}'.format(prefix, symbol.type) - return 'XXX' + elif symbol.type.is_complex: + if symbol.type.is_interface: + return '{0}*'.format(symbol.type) + else: + return '{0}{1}'.format(prefix, symbol.type) + raise Exception("Unknown symbol type") + + @staticmethod + def header_dependencies(symbol): + types = symbol.dependencies + lines = [] + for t in types: + if t.is_primitive: + continue + if t.is_model: + lines.append('class VariantModel;') + if t.is_interface: + lines.append('class {0};'.format(t)) + if t.is_struct: + lines.append('#include "{0}.h"'.format(t)) + return "\n".join(lines) + + @staticmethod + def source_dependencies(symbol): + types = symbol.dependencies + lines = [] + module_name = symbol.module.module_name + if not symbol.kind == 'module': + lines.append('#include "{0}module.h"'.format(module_name.lower())) + for t in types: + if t.is_primitive: + continue + if t.is_model: + lines.append('#include "variantmodel.h"') + if t.is_interface: + lines.append('#include "{0}.h"'.format(t.name.lower())) + return "\n".join(lines) @staticmethod def open_ns(symbol): @@ -221,4 +260,6 @@ class Filters(object): 'identifier': Filters.identifier, 'path': Filters.path, 'className': Filters.className, + 'source_dependencies': Filters.source_dependencies, + 'header_dependencies': Filters.header_dependencies, } diff --git a/qface/idl/domain.py b/qface/idl/domain.py index 75a2950..e82aeb3 100644 --- a/qface/idl/domain.py +++ b/qface/idl/domain.py @@ -124,6 +124,7 @@ class Symbol(NamedElement): self._tags = dict() self._contentMap = ChainMap() + self._dependencies = set() self.type = TypeSymbol('', self) self.kind = self.__class__.__name__.lower() """ the associated type information """ @@ -162,6 +163,12 @@ class Symbol(NamedElement): """ return general list of symbol contents """ return self._contentMap.values() + @property + def dependencies(self): + if not self._dependencies: + self._dependencies = [x.type for x in self.contents] + return self._dependencies + def toJson(self): o = super().toJson() if self.type.is_valid: |