MCPcopy Create free account
hub / github.com/HelenOS/helenos / create

Function create

tools/xstruct.py:100–163  ·  view source on GitHub ↗

Create structure object

(definition)

Source from the content-addressed store, hash-verified

98 i += 1
99
100def create(definition):
101 "Create structure object"
102
103 tokens = definition.split(None)
104
105 # Initial byte order tag
106 format = {
107 "little:": lambda: "<",
108 "big:": lambda: ">",
109 "network:": lambda: "!"
110 }[tokens[0]]()
111 inst = Struct()
112 args = []
113
114 # Member tags
115 comment = False
116 variable = None
117 for token in tokens[1:]:
118 if (comment):
119 if (token == "*/"):
120 comment = False
121 continue
122
123 if (token == "/*"):
124 comment = True
125 continue
126
127 if (variable != None):
128 subtokens = token.split("[")
129
130 length = None
131 if (len(subtokens) > 1):
132 length = int(subtokens[1].split("]")[0])
133 format += "%d" % length
134
135 format += variable
136
137 inst.__dict__[subtokens[0]] = None
138 args.append((subtokens[0], variable, length))
139
140 variable = None
141 continue
142
143 if (token[0:8] == "padding["):
144 size = token[8:].split("]")[0]
145 format += "%dx" % int(size)
146 continue
147
148 variable = {
149 "char": lambda: "s",
150 "uint8_t": lambda: "B",
151 "uint16_t": lambda: "H",
152 "uint32_t": lambda: "L",
153 "uint64_t": lambda: "Q",
154
155 "int8_t": lambda: "b",
156 "int16_t": lambda: "h",
157 "int32_t": lambda: "l",

Callers 1

threadMethod · 0.85

Calls 2

StructClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected