def __init__(self, name, ext_name, decls, ts, localts=None): super(mjClass, self).__init__() self.name = name self.ext_name = ext_name self.ext_class = None # no resuelto todavia self.decls = decls self.long = 0 self.vtable = "VT_%s" % self.name.get_lexeme() self.cr = "CR_%s" % self.name.get_lexeme() self.preconstruct = "%s_spreconstr" % self.name.get_lexeme() self.ipreconstruct = "%s_ipreconstr" % self.name.get_lexeme() if not ts is None: (redef, other) = ts.classExists(self) if redef: raise SemanticError(other.name.get_line(), other.name.get_col(), "Clase ya definida") ts.addClass(self) self.ts = localts if localts is None: self.ts = mjTS(ts) self.ts.set_owner(self) self.gen_default_construct() if self.ext_name is None and self.name.get_lexeme() != "Object": e = Token() e._lexeme = "Object" e._type = IDENTIFIER e._line = 0 e._col = 0 self.ext_name = e
def create_block_ts(self, stat=None, last_ts=None): """ Crea un ts para cada block con parent en el anterior """ if last_ts is None: last_ts = self.ts if stat is None: stat = self.body if isBlock(stat): ts = mjTS(last_ts) stat.set_ts(ts)
def set_ts(self, ts): self.ts = ts for stat in self.stats: if not stat is None: if isBlock(stat): bts = mjTS(ts) stat.set_ts(bts) elif isIf(stat): stat.expr.set_ts(ts) if not stat.stat is None: bts = mjTS(ts) stat.stat.set_ts(bts) if not stat.elsestat is None: bts = mjTS(ts) stat.elsestat.set_ts(bts) elif isWhile(stat): stat.expr.set_ts(ts) if not stat.statement is None: bts = mjTS(ts) stat.statement.set_ts(bts) else: stat.set_ts(ts)
def __init__(self, modifs, ret_type, name, params, body, ts, localts=None): super(mjMethod, self).__init__() self.modifs = modifs self.ret_type = ret_type self.name = name self.params = params self.processed_params = [] self.body = body # hack self._modifiable = mjModifiable() self._modifiable.modifs = self.modifs self.isStatic = self._modifiable.isStatic self.isPublic = self._modifiable.isPublic self.isProtected = self._modifiable.isProtected self.ts = localts if localts is None: self.ts = mjTS(ts) self.ts.set_owner(self) if not ts is None: if not ts.addMethod(self): raise SemanticError(self.name.get_line(), self.name.get_col(), "Redefinicion de metodo.") param_offset = 3 if not self.isStatic(): param_offset = 4 param_offset = len(self.params) + param_offset for (t, v) in self.params: param_offset -= 1 var = mjVariable(t, v, ts=self.ts) var.offset = param_offset self.processed_params.append(var) if not self.ts.addVar(var): raise SemanticError( v.get_line(), v.get_col(), "%s ya esta definido como parametro" % v.get_lexeme()) self.create_block_ts() self.body.set_owning_method(self)
def __init__(self, modifs, ret_type, name, params, body, ts, localts=None): super(mjMethod, self).__init__() self.modifs = modifs self.ret_type = ret_type self.name = name self.params = params self.processed_params = [] self.body = body # hack self._modifiable = mjModifiable() self._modifiable.modifs = self.modifs self.isStatic = self._modifiable.isStatic self.isPublic = self._modifiable.isPublic self.isProtected = self._modifiable.isProtected self.ts = localts if localts is None: self.ts = mjTS(ts) self.ts.set_owner(self) if not ts is None: if not ts.addMethod(self): raise SemanticError(self.name.get_line(), self.name.get_col(), "Redefinicion de metodo.") param_offset = 3 if not self.isStatic(): param_offset = 4 param_offset = len(self.params) + param_offset for (t, v) in self.params: param_offset -= 1 var = mjVariable(t, v, ts=self.ts) var.offset = param_offset self.processed_params.append(var) if not self.ts.addVar(var): raise SemanticError(v.get_line(), v.get_col(), "%s ya esta definido como parametro" % v.get_lexeme()) self.create_block_ts() self.body.set_owning_method(self)