)
def visit_declaration_variablearray(self, obj, indent, context):
- if type(obj.typ) == XDRTypeString:
+ if type(obj.typ) is XDRTypeString:
return "%schar *%s" % (indent, obj.identifier)
else:
code = (
+ "%s union {\n" % indent
)
for value in obj.cases:
- if type(value.decl.typ) == XDRTypeVoid:
+ if type(value.decl.typ) is XDRTypeVoid:
continue
code = code + self.visit_object(value, indent + " ") + ";\n"
- if obj.default is not None and type(obj.default.typ) != XDRTypeVoid:
+ if obj.default is not None and type(obj.default.typ) is not XDRTypeVoid:
code = code + self.visit_object(obj.default, indent + " ") + ";\n"
code = code + "%s } %su;\n" % (indent, prefix) + "%s}" % indent
return code
return code
def generate_type_call(self, decl, field, typename, embedded=False, indent=""):
- if type(decl.typ) == XDRTypeVoid:
+ if type(decl.typ) is XDRTypeVoid:
return ""
- if type(decl) == XDRDeclarationFixedArray:
- if type(decl.typ) == XDRTypeOpaque:
+ if type(decl) is XDRDeclarationFixedArray:
+ if type(decl.typ) is XDRTypeOpaque:
code = "%s if (!xdr_%s(xdrs, %s, %s))\n" % (
indent,
self.visit_object(decl.typ, context="func"),
self.visit_object(decl.typ),
self.visit_object(decl.typ, context="func"),
)
- elif type(decl) == XDRDeclarationVariableArray:
+ elif type(decl) is XDRDeclarationVariableArray:
fieldRef = "."
pointerStr = ""
if embedded:
else:
fieldRef = "->"
- if type(decl.typ) == XDRTypeString:
+ if type(decl.typ) is XDRTypeString:
code = "%s if (!xdr_%s(xdrs, %s%s, %s))\n" % (
indent,
self.visit_object(decl.typ, context="func"),
field,
decl.maxlength,
)
- elif type(decl.typ) == XDRTypeOpaque:
+ elif type(decl.typ) is XDRTypeOpaque:
code = "%s if (!xdr_bytes(xdrs, (char **)&%s%s%s_val, " % (
indent,
field,
self.visit_object(decl.typ, context="func"),
)
)
- elif type(decl) == XDRDeclarationPointer:
+ elif type(decl) is XDRDeclarationPointer:
pointerStr = ""
if embedded:
pointerStr = "&"
else:
pointerStr = ""
isFixedArray = (
- type(decl.typ) == XDRTypeCustom
- and type(decl.typ.definition) == XDRDefinitionTypedef
- and type(decl.typ.definition.decl) == XDRDeclarationFixedArray
+ type(decl.typ) is XDRTypeCustom
+ and type(decl.typ.definition) is XDRDefinitionTypedef
+ and type(decl.typ.definition.decl) is XDRDeclarationFixedArray
)
if embedded and not isFixedArray:
if token is None:
return None
- if type(token) == XDRTokenCEscape:
+ if type(token) is XDRTokenCEscape:
return XDRDefinitionCEscape(token.value[1:])
- if type(token) != XDRTokenIdentifier:
+ if type(token) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % token)
defs = {
definition = func()
semi = self.lexer.next()
- if type(semi) != XDRTokenPunctuation or semi.value != ";":
+ if type(semi) is not XDRTokenPunctuation or semi.value != ";":
raise Exception("Expected ';', but got %s" % semi)
return definition
def parse_definition_const(self):
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier:
+ if type(ident) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % ident)
assign = self.lexer.next()
- if type(assign) != XDRTokenPunctuation or assign.value != "=":
+ if type(assign) is not XDRTokenPunctuation or assign.value != "=":
raise Exception("Expected '=', but got %s" % assign)
const = self.lexer.next()
def parse_definition_enum(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_enum_body()
def parse_definition_struct(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_struct_body()
def parse_definition_union(self):
name = self.lexer.next()
- if type(name) != XDRTokenIdentifier:
+ if type(name) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % name)
body = self.parse_union_body()
def parse_declaration(self):
typ = self.parse_type()
- if type(typ) == XDRTypeVoid:
+ if type(typ) is XDRTypeVoid:
return XDRDeclarationScalar(typ, None)
ident = self.lexer.next()
pointer = False
- if type(ident) == XDRTokenPunctuation:
+ if type(ident) is XDRTokenPunctuation:
if ident.value != "*":
raise Exception("Expected '*' or identifer, but got %s" % ident)
- if type(typ) == XDRTypeString or type(typ) == XDRTypeOpaque:
+ if type(typ) is XDRTypeString or type(typ) is XDRTypeOpaque:
raise Exception("Pointer invalid for 'string' and 'opaque' types")
pointer = True
ident = self.lexer.next()
bracket = self.lexer.peek()
- if type(bracket) == XDRTokenPunctuation:
+ if type(bracket) is XDRTokenPunctuation:
if bracket.value == "[":
_ = self.lexer.next()
value = self.lexer.next()
raise Exception("Expected constant, but got %s" % value)
close = self.lexer.next()
- if type(close) != XDRTokenPunctuation or close.value != "]":
+ if type(close) is not XDRTokenPunctuation or close.value != "]":
raise Exception("Expected ']', but got %s" % value)
- if type(typ) == XDRTypeString:
+ if type(typ) is XDRTypeString:
raise Exception("Fixed array invalid for 'string' type")
return XDRDeclarationFixedArray(typ, ident.value, value.value)
elif bracket.value == "<":
value = self.lexer.next().value
close = self.lexer.next()
- if type(close) != XDRTokenPunctuation or close.value != ">":
+ if type(close) is not XDRTokenPunctuation or close.value != ">":
raise Exception("Expected '>', but got %s" % close)
return XDRDeclarationVariableArray(typ, ident.value, value)
def parse_type(self):
typ = self.lexer.next()
- if type(typ) != XDRTokenIdentifier:
+ if type(typ) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % typ)
if typ.value == "unsigned":
typ = self.lexer.peek()
- if type(typ) != XDRTokenIdentifier:
+ if type(typ) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % typ)
if typ.value == "char":
def parse_enum_body(self):
body = self.lexer.next()
- if type(body) != XDRTokenPunctuation or body.value != "{":
+ if type(body) is not XDRTokenPunctuation or body.value != "{":
raise Exception("Expected '{', but got %s" % body)
values = []
while True:
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier:
+ if type(ident) is not XDRTokenIdentifier:
raise Exception("Expected identifier, but got %s" % ident)
equal = self.lexer.next()
- if type(equal) != XDRTokenPunctuation or equal.value != "=":
+ if type(equal) is not XDRTokenPunctuation or equal.value != "=":
raise Exception("Expected '=', but got %s" % ident)
value = self.lexer.next()
- if type(value) != XDRTokenConstant:
+ if type(value) is not XDRTokenConstant:
raise Exception("Expected constant, but got %s" % ident)
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value not in [
+ if type(separator) is not XDRTokenPunctuation and separator.value not in [
"}",
",",
]:
def parse_struct_body(self):
body = self.lexer.next()
- if type(body) != XDRTokenPunctuation or body.value != "{":
+ if type(body) is not XDRTokenPunctuation or body.value != "{":
raise Exception("Expected '{', but got %s" % body)
fields = []
fields.append(field)
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value != ";":
+ if type(separator) is not XDRTokenPunctuation and separator.value != ";":
raise Exception("Expected ';', but got %s" % separator)
end = self.lexer.peek()
- if type(end) == XDRTokenPunctuation and end.value == "}":
+ if type(end) is XDRTokenPunctuation and end.value == "}":
break
# discard the '}' we peeked at to end the loop
def parse_union_body(self):
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier or ident.value != "switch":
+ if type(ident) is not XDRTokenIdentifier or ident.value != "switch":
raise Exception("Expected 'switch', but got %s" % ident)
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != "(":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != "(":
raise Exception("Expected '(', but got %s" % bracket)
discriminator = self.parse_declaration()
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != ")":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != ")":
raise Exception("Expected ')', but got %s" % bracket)
bracket = self.lexer.next()
- if type(bracket) != XDRTokenPunctuation or bracket.value != "{":
+ if type(bracket) is not XDRTokenPunctuation or bracket.value != "{":
raise Exception("Expected '{', but got %s" % bracket)
default = None
cases = []
while True:
ident = self.lexer.next()
- if type(ident) != XDRTokenIdentifier or ident.value not in [
+ if type(ident) is not XDRTokenIdentifier or ident.value not in [
"default",
"case",
]:
raise Exception("Expected constant, but got %s" % value)
sep = self.lexer.next()
- if type(sep) != XDRTokenPunctuation or sep.value != ":":
+ if type(sep) is not XDRTokenPunctuation or sep.value != ":":
raise Exception("Expected ':', but got %s" % value)
decl = self.parse_declaration()
raise Exception("Duplicate 'default' clause")
sep = self.lexer.next()
- if type(sep) != XDRTokenPunctuation or sep.value != ":":
+ if type(sep) is not XDRTokenPunctuation or sep.value != ":":
raise Exception("Expected ':', but got %s" % value)
default = self.parse_declaration()
separator = self.lexer.next()
- if type(separator) != XDRTokenPunctuation and separator.value != ";":
+ if type(separator) is not XDRTokenPunctuation and separator.value != ";":
raise Exception("Expected ';', but got %s" % bracket)
end = self.lexer.peek()
- if type(end) == XDRTokenPunctuation and end.value == "}":
+ if type(end) is XDRTokenPunctuation and end.value == "}":
break
# discard the '}' we peeked at to end the loop