Commit f7bd9857 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Python refactoring: changed name to dict

parent 9e1a6d74
......@@ -115,9 +115,11 @@ aspect PythonTypes {
public void TypeDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("typedef = labcomm2014.typedef('" + getName() + "',");
env.print("typedef = labcomm2014.typedef(");
Python_genIntentions(env);
env.println(",");
env.indent();
getDataType().Python_genTypedef(env);
getTypeInstance().Python_genTypedef(env);
env.unindent();
env.println(")");
env.unindent();
......@@ -127,19 +129,34 @@ aspect PythonTypes {
public void SampleDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("signature = labcomm2014.sample('" + getName() + "', ");
env.print("signature = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
getDataType().Python_genSignature(env);
env.unindent();
env.println(")");
env.println("typedef = labcomm2014.sample('" + getName() + "', ");
env.print("typedef = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
getDataType().Python_genTypedef(env);
getTypeInstance().Python_genTypedef(env);
env.unindent();
env.println(")");
env.unindent();
env.println();
}
public void Decl.Python_genIntentions(Python_env env) {
getTypeInstance().Python_genIntentions(env);
}
public void TypeInstance.Python_genIntentions(Python_env env) {
env.print("{'':'"+getName()+"'}");
}
public void TypeInstance.Python_genTypedef(Python_env env) {
getDataType().Python_genTypedef(env);
}
public void UserType.Python_genSignature(Python_env env) {
lookupType(getName()).getDataType().Python_genSignature(env);
......
......@@ -393,8 +393,11 @@ class SAMPLE(primitive):
# Aggregate types
#
class sampledef_or_sampleref_or_typedef(type_decl):
def __init__(self, name=None, decl=None):
self.name = name
def __init__(self, intentions=None, decl=None):
if intentions is not None and '' in intentions:
self.name = intentions['']
else:
self.name = None
self.decl = decl
def encode_decl(self, encoder):
......@@ -418,7 +421,7 @@ class sampledef_or_sampleref_or_typedef(type_decl):
length = decoder.decode_packed32()
decl = decoder.decode_decl()
result = self.__class__.__new__(self.__class__)
result.__init__(name=name, decl=decl)
result.__init__(intentions={'':name}, decl=decl)
self.add_index(decoder, index, result)
return result
......@@ -455,17 +458,23 @@ class sample_def(sampledef_or_sampleref_or_typedef):
decoder.add_decl(decl, index)
def rename(self, name):
return sample_def(name=name, decl=self.decl)
newIntentions = intentions.copy()
newIntentions['']=name
return sample_def(newIntentions, decl=self.decl)
class sample_ref(sampledef_or_sampleref_or_typedef):
type_index = i_SAMPLE_REF
type_name = 'sample_ref'
def __init__(self, name=None, decl=None, sample=None):
self.name = name
def __init__(self, intentions=None, decl=None, sample=None):
if intentions is not None and '' in intentions:
self.name = intentions['']
print "sampleref: name = %d" % self.name
else:
self.name = None
self.decl = decl
if sample == None and name != None and decl != None:
self.sample = sample_def(name, decl)
if sample == None and self.name != None and decl != None:
self.sample = sample_def(intentions, decl)
else:
self.sample = sample
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment