Hello Everyone,<br><br>Thank You Jamey for the reply,<br><br>I am facing few problems,<br><ul><li>I am unable to compile xtypes.py with python interpretor. I reciev an error -> Traceback (most recent call last):<br> File "workspace/xcb/proto/xcbgen/xtypes.py", line 80, in <module><br>
class SimpleType(Type):<br> File "workspace/xcb/proto/xcbgen/xtypes.py", line 106, in SimpleType<br> out = __main__.output['simple']<br><b>AttributeError: 'module' object has no attribute 'output' </b>and as a result for every change that I try to bring I need to start from make clean all over again for both ptroto</li>
<li>module.resolve keep troubling me whenever I try to introduce something in the xtypes so how can I resolve those</li></ul>So
far what I have understood/interpreted from your reply I have tried to
do something, ( and its compiling :-) ) and here it is, please review it
[ I have tried to have follow the coding style and tried not not to
make any typo error, still if any prob occur please notify ]<br>
<br><br>[vikash@localhost proto]$ git diff<br>diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py<br>index 14c318a..98c6811 100644<br>--- a/xcbgen/xtypes.py<br>+++ b/xcbgen/xtypes.py<br>@@ -34,6 +34,7 @@ class Type(object):<br>
self.is_pad = False<br> self.is_switch = False<br> self.is_bitcase = False<br>+ self.is_align = False<br> <br> def resolve(self, module):<br> '''<br>@@ -89,13 +90,19 @@ class SimpleType(Type):<br>
self.is_simple = True<br> self.size = size<br> self.nmemb = 1<br>+ <br>+ # align should be either equal to self.size or 4<br>+ self.align = min(self.size, 4)<br>+ self.is_align = True if self.align else False<br>
+# print self.is_align<br> <br>+ <br> def resolve(self, module):<br> self.resolved = True<br> <br> def fixed_size(self):<br> return True<br>-<br>+ <br> out = __main__.output['simple']<br>
<br> <br>@@ -169,6 +176,15 @@ class ListType(Type):<br> <br> self.size = member.size if member.fixed_size() else None<br> self.nmemb = self.expr.nmemb if self.expr.fixed_size() else None<br>+ <br>
+ # Please look over here<br>
+ # align should be between size and 4<br>+ # What should I take instead of None ?<br>+ self.align = min (member.size, 4) if member.fixed_size() else None<br>+ self.is_align = True if self.align else False<br>
+# print self.is_align<br>+# Also many a time I am recieving self.align = 0<br>+<br> <br> def make_member_of(self, module, complex_type, field_type, field_name, v<br> if not self.fixed_size():<br>
@@ -231,6 +247,13 @@ class ExprType(Type):<br> <br> self.size = member.size<br> self.nmemb = 1<br>+ <br>+ # align should be either equal to size or 4<br>+ self.align = min(self.size, 4)<br>
+ self.is_align = True if self.align else False<br>+ print self.align<br>+# print self.is_align<br>+<br> <br> def resolve(self, module):<br> if self.resolved:<br>@@ -273,6 +296,8 @@ class ComplexType(Type):<br>
self.nmemb = 1<br> self.size = 0<br> self.lenfield_parent = [self]<br>+ self.align = []<br>+ <br> <br> def resolve(self, module):<br> if self.resolved:<br>@@ -329,7 +354,8 @@ class ComplexType(Type):<br>
<br> self.calc_size() # Figure out how big we are<br> self.resolved = True<br>-<br>+ self.align_size()<br>+ <br> def calc_size(self):<br> self.size = 0<br> for m in self.fields:<br>
@@ -337,7 +363,6 @@ class ComplexType(Type):<br> continue<br> if m.type.fixed_size():<br> self.size = self.size + (m.type.size * m.type.nmemb)<br>- else:<br> self.size = None<br>
break<br> <br>@@ -346,6 +371,29 @@ class ComplexType(Type):<br> if not m.type.fixed_size():<br> return False<br> return True<br>+ <br>+ def align_size(self):<br>
+ '''<br>+ I think this func should work for both StructTypes and UnionTypes<br>+ '''<br>+ self.size = 0<br>+ arr=[]<br>+ for m in self.fields:<br>+ if not m.wire:<br>
+ continue<br>+ if m.type.fixed_size():<br>+ self.size = self.size + (m.type.size * m.type.nmemb)<br>+# print 'calc_size',self.size<br>+ arr.append(self.size)<br>
+# print 'arr', arr<br>+# print 'max of arr', max(arr)<br>+ self.align=min(max(arr), 4)<br>+ print 'align', self.align<br>+ self.is_align = True<br>
+# return self.size<br>+ <br>+<br>+ <br> <br> class SwitchType(ComplexType):<br> '''<br>@@ -455,6 +503,7 @@ class Struct(ComplexType):<br> '''<br>
Derived class representing a struct data type.<br> '''<br>+ <br> out = __main__.output['struct']<br> <br> <br>@@ -518,6 +567,12 @@ class Reply(ComplexType):<br> def __init__(self, name, elt):<br>
ComplexType.__init__(self, name, elt)<br> self.is_reply = True<br>+ <br>+ # align should be equal to 4<br>+ self.align = 4<br>+ self.is_align = True if self.is_align else False<br>
+# print self.is_align<br>+ <br> <br> def resolve(self, module):<br> if self.resolved:<br>@@ -542,6 +597,12 @@ class Request(ComplexType):<br> ComplexType.__init__(self, name, elt)<br> self.reply = None<br>
self.opcode = elt.get('opcode')<br>+ <br>+ # align should be equal to 4<br>+ self.align = 4<br>+ self.is_align = True if self.align else False<br>+# print self.is_align<br>
+ <br> <br> for child in list(elt):<br> if child.tag == 'reply':<br>@@ -578,6 +639,11 @@ class Event(ComplexType):<br> def __init__(self, name, elt):<br> ComplexType.__init__(self, name, elt)<br>
self.opcodes = {}<br>+ <br>+ # align should be equal to 4<br>+ self.align = 4<br>+ self.is_align = True if self.align else False<br>+# print self.is_align<br> tmp = elt.get('no-sequence-number')<br>
self.has_seq = (tmp == None or tmp.lower() == 'false' or tmp == '0')<br>@@ -611,7 +677,12 @@ class Error(ComplexType):<br> def __init__(self, name, elt):<br> ComplexType.__init__(self, name, elt)<br>
self.opcodes = {}<br>-<br>+ <br>+ # align should be equal to 4<br>+ self.align = 4<br>+ self.is_align = True if self.align else False<br>+# print self.is_align<br>+ <br> def add_opcode(self, opcode, name, main):<br>
self.opcodes[name] = opcode<br> if main:<br><br><br>Love <br><br>Vikash<br><br>and waiting for review :)