private void VisitEnumConstNode(enum_const_node en) { bw.Write(en.constant_value); WriteTypeReference(en.type); }
public override void visit(SyntaxTree.enum_type_definition _enum_type_definition) { //SSM 15/01/16 - реализация (integer,integer) // Если кто-то - не named_type_reference с одним ident, то надо идти по ветке типов - это не м.б.перечисление bool is_tuple_type = false; foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { if (!((en.name is named_type_reference) && (en.name as named_type_reference).names.Count()==1)) { is_tuple_type = true; break; } } bool is_enum = false; if (!is_tuple_type) // Значит, все - идентификаторы и сказать пока ничего нельзя foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = (en.name as named_type_reference).FirstIdent; var si = context.CurrentScope.Find(id.name); if ((si==null) || !(si.sym_info is type_node)) { is_enum = true; break; } } if (!is_enum) // Значит, это определение типа { var lt = new List<type_definition>(); for (var iii=0; iii<_enum_type_definition.enumerators.enumerators.Count(); iii++) { var en = _enum_type_definition.enumerators.enumerators[iii]; var name = en.name; if (en.value != null) AddError(get_location(en.value), "TUPLE_TYPE_ERROR"); lt.Add(name); } var l = new List<ident>(); l.Add(new ident("?System")); l.Add(new ident("Tuple")); var tp = new template_param_list(lt); // значит, это Tuple - создать его, обойти и выйти var ttr = new SyntaxTree.template_type_reference(new named_type_reference(l), tp); visit(ttr); return; } //end SSM // Если мы здесь - значит, это перечислимый тип //throw new NotSupportedError(get_location(_enum_type_definition)); //ivan added int num = 0; List<constant_definition_node> cnsts = new List<constant_definition_node>(); check_if_has_enum_consts(_enum_type_definition); foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = (en.name as named_type_reference).FirstIdent; // это - точно идентификаторы constant_definition_node cdn = context.add_const_definition(id.name, get_location(id)); if (en.value == null) cdn.const_value = new enum_const_node(num++, null, get_location(id)); else { constant_node cn = convert_strong_to_constant_node(en.value,SystemLibrary.SystemLibrary.integer_type); check_for_strong_constant(cn,get_location(en.value)); cdn.const_value = new enum_const_node((cn as int_const_node).constant_value,null,get_location(id)); } cnsts.Add(cdn); } common_type_node ctn = context.create_enum_type(null, get_location(_enum_type_definition)); //_enum_type_definition.values num = 0; foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = (en.name as named_type_reference).FirstIdent; constant_definition_node cdn = context.add_const_definition(id.name, get_location(id)); if (en.value == null) cdn.const_value = new enum_const_node(num++, null, get_location(id)); else { constant_node cn = convert_strong_to_constant_node(en.value,SystemLibrary.SystemLibrary.integer_type); check_for_strong_constant(cn,get_location(en.value)); cdn.const_value = new enum_const_node((cn as int_const_node).constant_value,null,get_location(id)); } cdn.const_value.type = ctn; } foreach (constant_definition_node cdn in cnsts) cdn.const_value.type = ctn; internal_interface ii = SystemLibrary.SystemLibrary.integer_type.get_internal_interface(internal_interface_kind.ordinal_interface); ordinal_type_interface oti_old = (ordinal_type_interface)ii; enum_const_node lower_value = new enum_const_node(0, ctn, ctn.loc); enum_const_node upper_value = new enum_const_node(ctn.const_defs.Count - 1, ctn, ctn.loc); ordinal_type_interface oti_new = new ordinal_type_interface(oti_old.inc_method, oti_old.dec_method, oti_old.inc_value_method, oti_old.dec_value_method, oti_old.lower_eq_method, oti_old.greater_eq_method, oti_old.lower_method, oti_old.greater_method, lower_value, upper_value, oti_old.value_to_int, oti_old.ordinal_type_to_int); ctn.add_internal_interface(oti_new); //foreach (constant_definition_node cdn in cnsts) // cdn.const_value.type = ctn; //context.leave_block(); context.leave_record(); return_value(ctn); }
private void MakeTypeAsOrdinal(common_type_node ctn, int low_val, int upper_val) { internal_interface ii = SystemLibrary.SystemLibrary.integer_type.get_internal_interface(internal_interface_kind.ordinal_interface); ordinal_type_interface oti_old = (ordinal_type_interface)ii; enum_const_node lower_value = new enum_const_node(low_val, ctn, ctn.loc); enum_const_node upper_value = new enum_const_node(upper_val - 1, ctn, ctn.loc); ordinal_type_interface oti_new = new ordinal_type_interface(oti_old.inc_method, oti_old.dec_method, oti_old.inc_value_method, oti_old.dec_value_method, oti_old.lower_eq_method, oti_old.greater_eq_method, oti_old.lower_method, oti_old.greater_method, lower_value, upper_value, oti_old.value_to_int, oti_old.ordinal_type_to_int); ctn.add_internal_interface(oti_new); }
public static compiled_type_node get_type_node(System.Type st) { //(ssyy) Обрабатываем параметры generic-типов //Сделаю потом, если это понадобится. //if (st.IsGenericParameter) //{ //} //if (st.Name.EndsWith("&") == true) //(ssyy) Лучше так if (st.IsByRef) { //return get_type_node(st.Module.GetType(st.FullName.Substring(0,st.FullName.Length-1))); return get_type_node(st.GetElementType()); } compiled_type_node ctn;//=compiled_types[st]; if (compiled_types.TryGetValue(st, out ctn)) { //ctn.reinit_scope(); return ctn; } ctn=new compiled_type_node(st); //Если это не чистить, будет ошибка. Т.к. при следующей компиляции области видимости могут изменится. //Но если это чистить то тоже ошибка. нужна еще одна статическая таблица для стандартных типов compiled_types[st] = ctn; ctn.init_constructors(); ctn.mark_if_delegate(); ctn.mark_if_array(); if (st.IsEnum) { internal_interface ii = SystemLibrary.SystemLibrary.integer_type.get_internal_interface(internal_interface_kind.ordinal_interface); ordinal_type_interface oti_old = (ordinal_type_interface)ii; enum_const_node lower_value = new enum_const_node(0, ctn, ctn.loc); enum_const_node upper_value = new enum_const_node(st.GetFields().Length-2, ctn, ctn.loc); ordinal_type_interface oti_new = new ordinal_type_interface(oti_old.inc_method, oti_old.dec_method, oti_old.inc_value_method, oti_old.dec_value_method, oti_old.lower_eq_method, oti_old.greater_eq_method, oti_old.lower_method, oti_old.greater_method, lower_value, upper_value, oti_old.value_to_int, oti_old.ordinal_type_to_int); ctn.add_internal_interface(oti_new); SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.gr_name, ctn, SemanticTree.basic_function_type.enumgr, SystemLibrary.SystemLibrary.bool_type); SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.greq_name, ctn, SemanticTree.basic_function_type.enumgreq, SystemLibrary.SystemLibrary.bool_type); SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.sm_name, ctn, SemanticTree.basic_function_type.enumsm, SystemLibrary.SystemLibrary.bool_type); SystemLibrary.SystemLibrary.make_binary_operator(compiler_string_consts.smeq_name, ctn, SemanticTree.basic_function_type.enumsmeq, SystemLibrary.SystemLibrary.bool_type); InitEnumOperations(ctn); } //ctn.init_scope(); //TODO: Тут надо подумать. Может как-то сделать по другому? if (!NetHelper.NetHelper.IsStandType(st)) { SystemLibrary.SystemLibrary.init_reference_type(ctn); } return ctn; }
public override void visit(SyntaxTree.enum_type_definition _enum_type_definition) { //throw new NotSupportedError(get_location(_enum_type_definition)); //ivan added int num = 0; List<constant_definition_node> cnsts = new List<constant_definition_node>(); check_if_has_enum_consts(_enum_type_definition); foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = en.name; constant_definition_node cdn = context.add_const_definition(id.name, get_location(id)); if (en.value == null) cdn.const_value = new enum_const_node(num++, null, get_location(id)); else { constant_node cn = convert_strong_to_constant_node(en.value,SystemLibrary.SystemLibrary.integer_type); check_for_strong_constant(cn,get_location(en.value)); cdn.const_value = new enum_const_node((cn as int_const_node).constant_value,null,get_location(id)); } cnsts.Add(cdn); } common_type_node ctn = context.create_enum_type(null, get_location(_enum_type_definition)); //_enum_type_definition.values num = 0; foreach (SyntaxTree.enumerator en in _enum_type_definition.enumerators.enumerators) { SyntaxTree.ident id = en.name; constant_definition_node cdn = context.add_const_definition(id.name, get_location(id)); if (en.value == null) cdn.const_value = new enum_const_node(num++, null, get_location(id)); else { constant_node cn = convert_strong_to_constant_node(en.value,SystemLibrary.SystemLibrary.integer_type); check_for_strong_constant(cn,get_location(en.value)); cdn.const_value = new enum_const_node((cn as int_const_node).constant_value,null,get_location(id)); } cdn.const_value.type = ctn; } foreach (constant_definition_node cdn in cnsts) cdn.const_value.type = ctn; internal_interface ii = SystemLibrary.SystemLibrary.integer_type.get_internal_interface(internal_interface_kind.ordinal_interface); ordinal_type_interface oti_old = (ordinal_type_interface)ii; enum_const_node lower_value = new enum_const_node(0, ctn, ctn.loc); enum_const_node upper_value = new enum_const_node(ctn.const_defs.Count - 1, ctn, ctn.loc); ordinal_type_interface oti_new = new ordinal_type_interface(oti_old.inc_method, oti_old.dec_method, oti_old.inc_value_method, oti_old.dec_value_method, oti_old.lower_eq_method, oti_old.greater_eq_method, oti_old.lower_method, oti_old.greater_method, lower_value, upper_value, oti_old.value_to_int, oti_old.ordinal_type_to_int); ctn.add_internal_interface(oti_new); //foreach (constant_definition_node cdn in cnsts) // cdn.const_value.type = ctn; //context.leave_block(); context.leave_record(); return_value(ctn); }