GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 72925e0e authored by Stefan Marr's avatar Stefan Marr

Added support for reading fields of the parent class

Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent 79a60edc
......@@ -6,8 +6,6 @@ class ClassGenerationContext(object):
self._name = None
self._super_name = None
self._class_side = False # to be overridden
self._number_of_instance_fields_of_super = -1
self._number_of_class_fields_of_super = -1
self._instance_fields = []
self._instance_methods = []
self._class_fields = []
......@@ -18,18 +16,18 @@ class ClassGenerationContext(object):
def set_super_name(self, symbol):
self._super_name = symbol
def set_instance_fields_of_super(self, field_names):
for i in range(0, field_names.get_number_of_indexable_fields()):
self._instance_fields.append(field_names.get_indexable_field(i))
def set_class_fields_of_super(self, field_names):
for i in range(0, field_names.get_number_of_indexable_fields()):
self._class_fields.append(field_names.get_indexable_field(i))
def set_number_of_instance_fields_of_super(self, num):
self._number_of_instance_fields_of_super = num
def set_number_of_class_fields_of_super(self, num):
self._number_of_class_fields_of_super = num
def add_instance_method(self, meth):
self._instance_methods.append(meth)
def set_class_side(self, boolean):
self._class_side = boolean
......@@ -46,9 +44,10 @@ class ClassGenerationContext(object):
return field in (self._class_fields if self.is_class_side() else self._instance_fields)
def get_field_index(self, field):
local_index = (self._class_fields if self.is_class_side() else self._instance_fields).index(field)
return (local_index +
(self._number_of_class_fields_of_super if self.is_class_side() else self._number_of_instance_fields_of_super))
if (self.is_class_side()):
return self._class_fields.index(field)
else:
return self._instance_fields.index(field)
def is_class_side(self):
return self._class_side
......
......@@ -35,22 +35,7 @@ class Parser(object):
self._expect(Symbol.Identifier)
self._expect(Symbol.Equal)
if self._sym == Symbol.Identifier:
super_name = self._universe.symbol_for(self._text)
self._accept(Symbol.Identifier)
else:
super_name = self._universe.symbol_for("Object")
cgenc.set_super_name(super_name)
# Load the super class
if super_name.get_string() == "nil": # Break the dependency cycle by hard coding the values for Object
cgenc.set_number_of_instance_fields_of_super(0) # Object's super class is nil, has no fields
cgenc.set_number_of_class_fields_of_super(4) # Object's class has the fields of Class
else:
super_class = self._universe.load_class(super_name)
cgenc.set_number_of_instance_fields_of_super(super_class.get_number_of_instance_fields())
cgenc.set_number_of_class_fields_of_super(super_class.get_class().get_number_of_instance_fields())
self._superclass(cgenc)
self._expect(Symbol.NewTerm)
self._instance_fields(cgenc)
......@@ -91,6 +76,32 @@ class Parser(object):
self._expect(Symbol.EndTerm)
def _superclass(self, cgenc):
if self._sym == Symbol.Identifier:
super_name = self._universe.symbol_for(self._text)
self._accept(Symbol.Identifier)
else:
super_name = self._universe.symbol_for("Object")
cgenc.set_super_name(super_name)
# Load the super class, if it is not nil (break the dependency cycle)
if super_name.get_string() != "nil":
super_class = self._universe.load_class(super_name)
cgenc.set_instance_fields_of_super(super_class.get_instance_fields())
cgenc.set_class_fields_of_super(super_class.get_class().get_instance_fields())
else:
# WARNING:
# We hardcode here the field names for Class
# since Object class superclass = Class
# We avoid here any kind of dynamic solution to avoid further
# complexity. However, that makes it static, it is going to make it
# harder to change the definition of Class and Object
field_names_of_class = ["class", "superClass", "name",
"instanceFields", "instanceInvokables"]
field_names = self._universe.new_array_with_strings(field_names_of_class)
cgenc.set_class_fields_of_super(field_names)
def _sym_in(self, symbol_list):
return self._sym in symbol_list
......
Markdown is supported
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