Skip to content
Browse files

Added support for enumerations and values

  • Loading branch information...
1 parent dfe9022 commit fe343377cae6ae418d1819aab2c501d2a54d7277 @aruiz committed
Showing with 81 additions and 32 deletions.
  1. +3 −0 api/admin.py
  2. +14 −14 api/models.py
  3. +64 −18 api/views.py
View
3 api/admin.py
@@ -13,6 +13,9 @@ class NsAdmin(admin.ModelAdmin):
admin.site.register(Function, SymbolAdmin)
admin.site.register(Type, SymbolAdmin)
+admin.site.register(Value, SymbolAdmin)
+admin.site.register(Enumeration, SymbolAdmin)
+
admin.site.register(TypedNode, NsAdmin)
admin.site.register(Parameter, NsAdmin)
admin.site.register(ReturnValue, NsAdmin)
View
28 api/models.py
@@ -8,14 +8,14 @@
ast.Node: ('name', 'namespaced_name', 'doc'),
ast.Parameter: ('is_out',),
ast.Type: ('is_array', 'c_type'),
+ ast.Value: ('value',),
ast.Array: ('child_type',),
ast.Callable: ('c_identifier',),
ast.Method: ('virtual', 'static'),
- ast.Enumeration: ('members',),
- ast.Record: ('disguised', 'fields', 'callbacks', 'methods'),
+ ast.Record: ('disguised'),
ast.TypedNode: ('name', 'doc', 'is_pointer', 'is_array'),
ast.Property: ('writable', 'construct_only'),
- ast.Class: ('constructors', 'properties', 'signals', 'parent_class', 'interfaces', 'is_abstract')
+ ast.Class: ('is_abstract')
}
class Namespace(models.Model):
@@ -47,7 +47,8 @@ def __unicode__(self):
return self.name
class Value(Node):
- pass
+ value_of = models.ForeignKey('Enumeration', null=True, blank=True)
+ val = models.CharField(max_length=500)
class Parameter(TypedNode):
is_out = models.BooleanField(default=False)
@@ -85,17 +86,19 @@ class Callback(Type, Callable):
pass
class Signal(Callable):
- pass
+ signal_of = models.ForeignKey('Class')
class Method(Callable):
- virtual = models.BooleanField(default=False)
- static = models.BooleanField(default=False)
+ method_of = models.ForeignKey('Record')
+ virtual = models.BooleanField(default=False)
+ static = models.BooleanField(default=False)
-class Constructor(Method):
- pass
+class Constructor(Callable):
+ #TODO: Can a constructor be static?
+ constructor_of = models.ForeignKey('Class')
class Enumeration(Type):
- members = models.ManyToManyField('Value')
+ pass
class BitField(Enumeration):
pass
@@ -104,19 +107,16 @@ class Record(Type):
disguised = models.BooleanField(default=False)
fields = models.ManyToManyField('Field')
callbacks = models.ManyToManyField('Callback')
- methods = models.ManyToManyField('Method')
class Field (Node):
pass
class Property(Field):
+ property_of = models.ForeignKey('Class')
writable = models.BooleanField(default=False)
construct_only = models.BooleanField(default=False)
class Class(Record):
- constructors = models.ManyToManyField('Constructor', null=True, blank=True)
- properties = models.ManyToManyField('Property', null=True, blank=True)
- signals = models.ManyToManyField('Signal', null=True, blank=True)
parent_class = models.ForeignKey ('self', null=True, blank=True)
interfaces = models.ManyToManyField('Interface', null=True, blank=True, related_name='class_interfaces')
is_abstract = models.BooleanField(default=False)
View
82 api/views.py
@@ -45,57 +45,100 @@ def _store_namespace (ns):
return db_ns
-def _store_type (ast_type):
+def _store_type (ast_type, db_ns):
try:
db_type = models.Type.objects.get(c_type = ast_type.c_type)
except ObjectDoesNotExist:
db_type = models.Type()
+ db_type.namespace = db_ns
_store_props (db_type, ast_type, (ast.Node, ast.Type))
db_type.save()
return db_type
-def _store_param (param, position, callable_obj):
+def _store_param (param, position, db_ns, callable_obj):
db_param = models.Parameter()
- db_param.tn_type = _store_type (param.get_type())
+ db_param.tn_type = _store_type (param.get_type(), db_ns)
db_param.position = position
db_param.callable_obj = callable_obj
+ db_param.namespace = db_ns
_store_props (db_param, param, (ast.TypedNode, ast.Parameter))
db_param.save()
return db_param
-def _store_return_value (rvalue, callable_obj):
+def _store_return_value (rvalue, db_ns, callable_obj):
db_rvalue = models.ReturnValue()
_store_props (db_rvalue, rvalue, (ast.TypedNode,))
- db_rvalue.tn_type = _store_type (rvalue.get_type())
+ db_rvalue.tn_type = _store_type (rvalue.get_type(), db_ns)
db_rvalue.callable_obj = callable_obj
+ db_rvalue.namespace = db_ns
db_rvalue.save()
return db_rvalue
-def _store_function (fn):
+def _store_generic_callable (clble, db_ns, model, asts):
pass
- print fn.name
+ print clble.name
try:
- db_fn = models.Function.objects.get(c_identifier = fn.c_identifier)
+ db_clble = model.objects.get(c_identifier = clble.c_identifier)
except ObjectDoesNotExist:
- db_fn = models.Function(name = fn.name)
- _store_props (db_fn, fn, (ast.Callable, ast.Node))
- db_fn.save()
+ db_clble = model()
+ _store_props (db_clble, clble, asts)
+ db_clble.namespace = db_ns
+ db_clble.save()
- _store_return_value (fn.return_value, db_fn)
+ _store_return_value (clble.return_value, db_ns, db_clble)
db_params = []
pos = 0
- for param in fn.parameters:
- db_params.append(_store_param(param, pos, db_fn))
+ for param in clble.parameters:
+ db_params.append(_store_param(param, pos, db_ns, db_clble))
pos += 1
- return db_fn
+ return db_clble
+
+ #TODO: Update Callable
+ return db_clble
+
+def _store_function (fn, db_ns):
+ return _store_generic_callable (fn, db_ns, models.Function, (ast.Callable, ast.Node))
+
+def _store_callback (cb, db_ns):
+ return _store_generic_callable (cb, db_ns, models.Callback, (ast.Callback, ast.Node))
+
+def _store_signal (cb, db_ns):
+ return _store_generic_callable (cb, db_ns, models.Signal, (ast.Callback, ast.Node))
+
+def _store_value (val, db_ns, parent):
+ try:
+ db_val = models.Value.objects.get(val = val.value, name = val.name)
+ except ObjectDoesNotExist:
+ db_val = models.Value()
+ db_val.value_of = parent
+ _store_props (db_val, val, (ast.Node,))
+ db_val.val = val.value
+ db_val.namespace = db_ns
+ db_val.save()
+
+ return db_val
+
+def _store_enum (enum, db_ns):
+ print enum.name
+ try:
+ db_enum = models.Enumeration.objects.get(c_type = enum.c_type)
+ except ObjectDoesNotExist:
+ db_enum = models.Enumeration()
+ _store_props (db_enum, enum, (ast.Node, ast.Type))
+ db_enum.namespace = db_ns
+ db_enum.save()
+
+ for member in enum.members:
+ _store_value (member, db_ns, db_enum)
+
+
+ return db_enum
- #TODO: Update
- return db_fn
def parse(request):
repo = ast.Repository()
@@ -107,7 +150,10 @@ def parse(request):
for ns in repo.namespaces:
db_ns = _store_namespace (ns)
for fn in ns.functions:
- _store_function (fn)
+ _store_function (fn, db_ns)
+ for enum in ns.enumerations:
+ _store_enum (enum, db_ns)
+
#
# if root_class == None:
# return HttpResponse("<h1>No GObject.Object found</h1>")

0 comments on commit fe34337

Please sign in to comment.
Something went wrong with that request. Please try again.