def check_variable(self, variable): if is_int(variable): self.check_int(variable) elif is_array(variable): self.check_inttab(variable) else: raise CompilerError("Unexpected variable type")
def check_initialized(self, var): if is_int(var): _, symbol, lineno = var if not self.initialized.get(symbol, False): raise_error( "Usage of uninitialized variable '{symbol}'".format( symbol=symbol), lineno) elif is_array(var): # Cannot check int tab initialization pass
def check_scope(self, operand): if is_number(operand): pass elif is_int(operand): if operand[1] not in self.scope: raise_error(msg="Undeclared variable {}".format(operand[1]), lineno=operand[2]) elif is_array(operand): if is_number(operand[2]): self.check_inttab(operand) else: raise CompilerError("Unexpected operand")
def check_inttab(self, variable): _, symbol, index, lineno = variable arr_start = '#'.join([symbol, '0']) if arr_start not in self.scope: raise_error("Usage of undeclared array {}".format(symbol), lineno) if is_number(index): self.check_inttab_index(variable) elif is_int(index): self.check_variable(index) else: raise CompilerError("Unexpected array index")
def addr_to_reg_if_arr(self, source, register): if is_array(source) and is_int(source[2]): _, symbol, index, lineno = source self.code.append('LOAD {}'.format(self.mem[symbol + '#0']['start_ptr'])) self.parse(""" ADD index STORE reg """, index=index, reg=register) return 'int[]', symbol, register, lineno else: return source
def check_assign(self, cmd): _, target, expression = cmd self.check_scope(target) if is_int(target): _, symbol, lineno = target if symbol in self.iterators: raise_error( "Mutation of iterator '{symbol}'".format(symbol=symbol), lineno) elif is_array(target): _, symbol, index, _ = target symbol = '#'.join([symbol, str(index)]) else: raise CompilerError("Unexpected target type") self.check_expression(expression) self.initialized[symbol] = True
def data_check(self): if not self.db_name: self.msg+=MSG_ERR_NAME return False if not self.db_ip: self.msg+=MSG_ERR_IP return False if is_int(self.db_port): self.msg+=MSG_ERR_PORT return False if not self.db_level: self.db_level=DEFAULT_LEVEL if not self.db_online: self.db_online=datetime.datetime.now() if not self.db_business: self.db_business=DEFAULT_BUSINESS if not self.db_owner: self.db_owner=DEFAULT_OWNER return True
def data_check(self): if not self.db_name: self.msg += MSG_ERR_NAME return False if not self.db_ip: self.msg += MSG_ERR_IP return False if is_int(self.db_port): self.msg += MSG_ERR_PORT return False if not self.db_level: self.db_level = DEFAULT_LEVEL if not self.db_online: self.db_online = datetime.datetime.now() if not self.db_business: self.db_business = DEFAULT_BUSINESS if not self.db_owner: self.db_owner = DEFAULT_OWNER return True
def data_check(self): if not self.inst_ip or not check_ip(self.inst_ip): self.msg += MSG_ERR_IP return False if is_int(self.inst_port): self.msg += MSG_ERR_PORT return False if not self.inst_level: self.inst_level = DEFAULT_LEVEL if not self.inst_name: self.inst_name = self.inst_ip if not self.inst_owner: self.inst_owner = DEFAULT_OWNER if not self.inst_online_date: self.inst_online_date = datetime.datetime.now() if not self.inst_dbtype: self.inst_dbtype = DEFAULT_DBTYPE if not self.inst_hatype: self.inst_hatype = DEFAULT_HATYPE if not self.inst_bussiness: self.inst_bussiness = DEFAULT_BUSINESS return True
def data_check(self): if not self.inst_ip or not check_ip(self.inst_ip): self.msg+=MSG_ERR_IP return False if is_int(self.inst_port): self.msg+=MSG_ERR_PORT return False if not self.inst_level: self.inst_level=DEFAULT_LEVEL if not self.inst_name: self.inst_name=self.inst_ip if not self.inst_owner: self.inst_owner=DEFAULT_OWNER if not self.inst_online_date: self.inst_online_date=datetime.datetime.now() if not self.inst_dbtype: self.inst_dbtype=DEFAULT_DBTYPE if not self.inst_hatype: self.inst_hatype=DEFAULT_HATYPE if not self.inst_bussiness: self.inst_bussiness=DEFAULT_BUSINESS return True