public void CanBuildSemanticTree() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var serviceBaseUri = new Uri("http://server/service/"); var queryUri = new Uri(serviceBaseUri, "Customers(1)"); var semanticTree = SemanticTree.ParseUri(queryUri, serviceBaseUri, model); }
public SemanticTree.IProgramNode Convert(SemanticTree.IProgramNode ProgramNode) { foreach (ISemanticTreeConverter SemanticTreeConverter in semanticTreeConverters) { ChangeState(State.Convert, SemanticTreeConverter); ProgramNode = SemanticTreeConverter.Convert(Compiler, ProgramNode); } return ProgramNode; }
public common_event(string name, type_node del_type, common_type_node cont_type, common_method_node add_method, common_method_node remove_method, common_method_node raise_method, SemanticTree.field_access_level fal, SemanticTree.polymorphic_state ps, location loc) { this._name = name; this.del_type = del_type; this._add_method = add_method; this._remove_method = remove_method; this._raise_method = raise_method; this._field_access_level = fal; this._polymorphic_state = ps; this._cont_type = cont_type; this._loc = loc; }
public void ParseCompoundOrderBy() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var serviceBaseUri = new Uri("http://server/service/"); var queryUri = new Uri(serviceBaseUri, "Customers?$orderby=Name,Website desc"); var semanticTree = SemanticTree.ParseUri(queryUri, serviceBaseUri, model); var thenOrderByNode = semanticTree.Query as OrderByQueryNode; Assert.NotNull(thenOrderByNode); var orderByNode = thenOrderByNode.Collection as OrderByQueryNode; Assert.NotNull(orderByNode); Assert.Equal("Name", (orderByNode.Expression as PropertyAccessQueryNode).Property.Name); Assert.Equal("Website", (thenOrderByNode.Expression as PropertyAccessQueryNode).Property.Name); }
public void ParseSimpleOrderBy() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var serviceBaseUri = new Uri("http://server/service/"); var queryUri = new Uri(serviceBaseUri, "Customers?$orderby=Name"); var semanticTree = SemanticTree.ParseUri(queryUri, serviceBaseUri, model); var orderByNode = semanticTree.Query as OrderByQueryNode; Assert.NotNull(orderByNode); Assert.Equal(QueryNodeKind.PropertyAccess, orderByNode.Expression.Kind); var propertyAccess = orderByNode.Expression as PropertyAccessQueryNode; Assert.NotNull(propertyAccess); var customerEntityType = model.FindDeclaredType(typeof(Customer).FullName) as IEdmEntityType; var nameProperty = customerEntityType.Properties().Single(p => p.Name == "Name"); Assert.Equal(nameProperty, propertyAccess.Property); }
//ssyy public static string GetFullMethodHeaderString(SemanticTree.IFunctionNode member) { string s = member.name; SemanticTree.IParameterNode[] ps = member.parameters; if (ps.Length > 0) { s += '('; s += ps[0].type.name; for (int i = 1; i < ps.Length; i++) { s += "," + ps[i].type.name; } s += ')'; } if (member.return_value_type != null) { s += ":" + member.return_value_type.name; } return s; }
public void ParseSimpleFilter() { var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetServiceModel(); var serviceBaseUri = new Uri("http://server/service/"); var queryUri = new Uri(serviceBaseUri, "Customers?$filter=Name eq 'Alex'"); var semanticTree = SemanticTree.ParseUri(queryUri, serviceBaseUri, model); var filterNode = semanticTree.Query as FilterQueryNode; Assert.NotNull(filterNode); var equalityNode = filterNode.Expression as BinaryOperatorQueryNode; Assert.NotNull(equalityNode); Assert.Equal(BinaryOperatorKind.Equal, equalityNode.OperatorKind); var leftNode = equalityNode.Left as PropertyAccessQueryNode; Assert.NotNull(leftNode); Assert.Equal("Name", leftNode.Property.Name); var rightNode = equalityNode.Right as ConstantQueryNode; Assert.NotNull(rightNode); Assert.Equal("Alex", rightNode.Value); }
//сохранение отлад. информации private void WriteDebugInfo(SemanticTree.ILocation loc) { WriteDebugInfo(bw,loc); }
/* private static void mark_byte_as_ordinal() { basic_function_node inc_value_method = create_inc_value_method(SemanticTree.basic_function_type.binc, _byte_type); basic_function_node dec_value_method = create_dec_value_method(SemanticTree.basic_function_type.bdec, _byte_type); basic_function_node inc_method = create_inc_method(SemanticTree.basic_function_type.binc, _byte_type); basic_function_node dec_method = create_dec_method(SemanticTree.basic_function_type.bdec, _byte_type); SymbolInfo si = _byte_type.find_in_type(compiler_string_consts.greq_name); basic_function_node greq = (basic_function_node)si.sym_info; si = _byte_type.find(compiler_string_consts.smeq_name); basic_function_node loeq = (basic_function_node)si.sym_info; constant_node cn_max = new byte_const_node(byte.MaxValue, null); constant_node cn_min = new byte_const_node(byte.MinValue, null); basic_function_node i2i_method = create_emty_function(byte_type); ordinal_type_to_int ordinal_type_to_int = byte_to_int; ordinal_type_interface oti = new ordinal_type_interface(inc_method, dec_method, inc_value_method, dec_value_method, internal_inc_value, internal_dec_value, loeq, greq, cn_min, cn_max, i2i_method, ordinal_type_to_int); _byte_type.add_internal_interface(oti); } */ private static void mark_type_as_ordinal(type_node type, SemanticTree.basic_function_type inc,SemanticTree.basic_function_type dec, SemanticTree.basic_function_type vinc, SemanticTree.basic_function_type vdec, constant_node lower_value, constant_node upper_value, function_node t2i,ordinal_type_to_int t2i_comp) { basic_function_node inc_value = create_oti_method(inc, type, SemanticTree.parameter_type.value); basic_function_node dec_value = create_oti_method(dec, type, SemanticTree.parameter_type.value); basic_function_node inc_var = create_oti_method(vinc, type, SemanticTree.parameter_type.var); basic_function_node dec_var = create_oti_method(vdec, type, SemanticTree.parameter_type.var); SymbolInfo si = type.find_in_type(compiler_string_consts.greq_name); basic_function_node greq = (basic_function_node)si.sym_info; si = type.find(compiler_string_consts.smeq_name); basic_function_node loeq = (basic_function_node)si.sym_info; si = type.find(compiler_string_consts.sm_name); basic_function_node lo = (basic_function_node)si.sym_info; si = type.find(compiler_string_consts.gr_name); basic_function_node gr = (basic_function_node)si.sym_info; ordinal_type_interface oti = new ordinal_type_interface(inc_value, dec_value, inc_var, dec_var, loeq, greq, lo, gr, lower_value, upper_value, t2i, t2i_comp); type.add_internal_interface(oti); }
private static basic_function_node create_oti_method(SemanticTree.basic_function_type bft, type_node type, SemanticTree.parameter_type pt) { basic_function_node bfn = new basic_function_node(bft, type, true); basic_parameter cp = new basic_parameter(compiler_string_consts.unary_param_name, type, pt, bfn); bfn.parameters.AddElement(cp); //TODO: Важен порядок вызовов. add_stand_type(bft, bfn); return bfn; }
public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft, bool is_implicit) { basic_function_node conv_method = new basic_function_node(bft, to,false); basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name, from, SemanticTree.parameter_type.value, conv_method); conv_method.parameters.AddElement(bp); type_table.add_type_conversion_from_defined(from, to, conv_method, tc, is_implicit); //type_intersection_node inter_node = new type_intersection_node(tc); //inter_node.this_to_another = new type_conversion(conv_method,!is_implicit); //from.add_intersection_node(to, inter_node); add_stand_type(bft, conv_method); return conv_method; }
public static basic_function_node make_binary_operator(string operator_name, type_node to, SemanticTree.basic_function_type bft) { return make_binary_operator(operator_name, to, bft, to); }
public static basic_function_node make_unary_operator(string operator_name, type_node to, SemanticTree.basic_function_type bft, type_node ret_value_type) { basic_function_node bfn = new basic_function_node(bft, ret_value_type,true); basic_parameter par = new basic_parameter(compiler_string_consts.unary_param_name, to, SemanticTree.parameter_type.value, bfn); bfn.parameters.AddElement(par); to.add_name(operator_name, new SymbolInfo(bfn)); add_stand_type(bft, bfn); return bfn; }
private static basic_function_node make_unary_function(type_node param_type, SemanticTree.basic_function_type bft,type_node ret_val_type) { basic_function_node bfn = new basic_function_node(bft, ret_val_type, true); basic_parameter bpar = new basic_parameter(compiler_string_consts.unary_param_name, param_type, SemanticTree.parameter_type.value, bfn); bfn.parameters.AddElement(bpar); add_stand_type(bft, bfn); return bfn; }
public static basic_function_node find_operator(SemanticTree.basic_function_type bft) { return ht[bft]; }
public void CustomQueryOptionBinderTest() { var metadata = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.UntypedDataServiceProviderFactory); var testCases = new[] { new QueryOptionTestCase { Query = "/Customers?$foo=12", ExpectedExceptionMessage = "The system query option '$foo' is not supported." }, new QueryOptionTestCase { Query = "/Customers?a=b", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("a", "b") } }, new QueryOptionTestCase { Query = "/Customers?a=b&c=d", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("a", "b"), new CustomQueryOptionNode("c", "d") } }, new QueryOptionTestCase { Query = "/Customers?a=b&a=c", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("a", "b"), new CustomQueryOptionNode("a", "c") } }, new QueryOptionTestCase { Query = "/Customers?foo", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode(null, "foo") } }, new QueryOptionTestCase { Query = "/Customers?foo=", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("foo", string.Empty) } }, new QueryOptionTestCase { Query = "/Customers?&", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode(null, string.Empty), new CustomQueryOptionNode(null, string.Empty) } }, new QueryOptionTestCase { Query = "/Customers?a=b&", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("a", "b"), new CustomQueryOptionNode(null, string.Empty) } }, new QueryOptionTestCase { Query = "/Customers?&&", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode(null, string.Empty), new CustomQueryOptionNode(null, string.Empty), new CustomQueryOptionNode(null, string.Empty) } }, new QueryOptionTestCase { Query = "/Customers?a=b&&", ExpectedQueryOptions = new CustomQueryOptionNode[] { new CustomQueryOptionNode("a", "b"), new CustomQueryOptionNode(null, string.Empty), new CustomQueryOptionNode(null, string.Empty) } }, }; this.CombinatorialEngineProvider.RunCombinations( testCases, (testCase) => { TestExceptionUtils.ExpectedException <ODataException>( this.Assert, () => { SemanticTree actual = QueryNodeUtils.BindQuery(testCase.Query, metadata); QueryNodeUtils.VerifyQueryNodesAreEqual( testCase.ExpectedQueryOptions, actual.CustomQueryOptions, this.Assert); }, testCase.ExpectedExceptionMessage, null); }); }
public void check_name_free(string name,SemanticTree.ILocation name_loc) { SymbolInfo si=find_only_in_namespace(name); if (si==null) { return; } SemanticTree.ILocation first_loc=convertion_data_and_alghoritms.get_location(si.sym_info); //TODO: Можно передавать список всех повторных объявлений. throw new NameRedefinition(first_loc,name_loc); }
public static basic_function_node make_assign_operator(type_node ctn,SemanticTree.basic_function_type assign_method) { basic_function_node ret = make_object_operator(ctn, assign_method, compiler_string_consts.assign_name, ctn, SemanticTree.parameter_type.var); ret.operation_kind = special_operation_kind.assign; return ret; }
private void check_for_usage_attribute(definition_node dn, AttributeTargets targets, string name, location loc, SemanticTree.attribute_qualifier_kind qualifier) { switch (dn.semantic_node_type) { case semantic_node_type.common_type_node : { common_type_node ctn = dn as common_type_node; if (ctn.IsDelegate) { if ((targets & (AttributeTargets.Delegate)) != (AttributeTargets.Delegate)) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_DELEGATE", name); } else if (ctn.IsInterface) { if ((targets & AttributeTargets.Interface) != AttributeTargets.Interface) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_INTERFACE", name); } else if (ctn.IsEnum) { if ((targets & (AttributeTargets.Enum)) != (AttributeTargets.Enum)) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_ENUM", name); } else if (ctn.is_value_type) { if ((targets & AttributeTargets.Struct) != AttributeTargets.Struct) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_STRUCT", name); } else if ((targets & AttributeTargets.Class) != AttributeTargets.Class) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_CLASS", name); } break; case semantic_node_type.common_method_node: if ((dn as common_method_node).is_constructor) { if ((targets & AttributeTargets.Constructor) != AttributeTargets.Constructor) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_CONSTRUCTOR", name); } else if ((targets & AttributeTargets.Method) != AttributeTargets.Method && qualifier != SemanticTree.attribute_qualifier_kind.return_kind) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_METHOD", name); break; case semantic_node_type.common_namespace_function_node: if ((targets & AttributeTargets.Method) != AttributeTargets.Method && qualifier != SemanticTree.attribute_qualifier_kind.return_kind) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_METHOD", name); break; case semantic_node_type.class_field: if ((targets & AttributeTargets.Field) != AttributeTargets.Field) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_FIELD", name); break; case semantic_node_type.common_property_node: if ((targets & AttributeTargets.Property) != AttributeTargets.Property) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_PROPERTY", name); break; case semantic_node_type.common_namespace_event: case semantic_node_type.common_event: if ((targets & AttributeTargets.Event) != AttributeTargets.Event) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_EVENT", name); break; case semantic_node_type.common_parameter: if ((targets & AttributeTargets.Parameter) != AttributeTargets.Parameter) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_FIELD", name); break; case semantic_node_type.common_unit_node: if ((targets & AttributeTargets.Assembly) != AttributeTargets.Assembly) AddError(loc, "ATTRIBUTE_{0}_NOT_APPLICABLE_TO_ASSEMBLY", name); break; } }
private static void add_stand_type(SemanticTree.basic_function_type bft, basic_function_node bfn) { ht[bft] = bfn; }
/// <summary> /// Метод для обхода дерева посетителем. /// </summary> /// <param name="visitor">Класс - посетитель дерева.</param> public override void visit(SemanticTree.ISemanticVisitor visitor) { throw new PascalABCCompiler.TreeConverter.CompilerInternalError("Template class can't be visit."); }
public static basic_function_node make_common_binary_operation(string operator_name, type_node def_type,type_node left,type_node right, SemanticTree.basic_function_type bft,type_node ret_value_type) { basic_function_node bfn = new basic_function_node(bft, ret_value_type,true,operator_name); basic_parameter par_left = new basic_parameter(compiler_string_consts.left_param_name, left, SemanticTree.parameter_type.value, bfn); basic_parameter par_right = new basic_parameter(compiler_string_consts.right_param_name, right, SemanticTree.parameter_type.value, bfn); bfn.parameters.AddElement(par_left); bfn.parameters.AddElement(par_right); def_type.add_name(operator_name, new SymbolInfo(bfn)); add_stand_type(bft, bfn); return bfn; }
/// <summary> /// Конструктор узла. /// </summary> /// <param name="name">Имя функции.</param> /// <param name="ret_type"></param> /// <param name="loc">Расположение имени метода в программе.</param> /// <param name="cont_type">Тип, который содержит этот метод.</param> /// <param name="polymorphic_state">Обычный, виртуальный или статический метод.</param> /// <param name="field_access_level">Уровень доступа к методу.</param> /// <param name="scope">Пространство имен функции.</param> public common_method_node(string name,type_node ret_type, location loc, common_type_node cont_type, SemanticTree.polymorphic_state polymorphic_state, SemanticTree.field_access_level field_access_level, SymbolTable.Scope scope) : base(name,ret_type,loc,scope) { _cont_type=cont_type; _field_access_level = field_access_level; _polymorphic_state = polymorphic_state; }
public static basic_function_node make_binary_operator(string operator_name, type_node to, SemanticTree.basic_function_type bft, type_node ret_value_type) { return make_common_binary_operation(operator_name, to, to, to, bft, ret_value_type); }
public void set_access_level(SemanticTree.field_access_level fal) { _field_access_level = fal; }
public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft) { return make_type_conversion(from, to, tc, bft, true); }
/// <summary> /// Конструктор узла. /// </summary> /// <param name="bft">Тип базовой функции.</param> /// <param name="ret_type">Тип возвращаемого значения.</param> /// <param name="is_overload">Перегружена-ли функция.</param> public basic_function_node(SemanticTree.basic_function_type bft,type_node ret_type, bool is_overload) : base(ret_type) { _basic_function_type=bft; _overload = is_overload; }
public static basic_function_node make_generated_type_conversion(type_node from, type_node to, type_compare tc, SemanticTree.basic_function_type bft, bool is_implicit) { basic_function_node conv_method = new basic_function_node(bft, to, false); basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name, from, SemanticTree.parameter_type.value, conv_method); conv_method.parameters.AddElement(bp); type_table.add_generated_type_conversion_from_defined(from, to, conv_method, tc, is_implicit); return conv_method; }
/// <summary> /// Конструктор узла. /// </summary> /// <param name="bft">Тип базовой функции.</param> /// <param name="ret_type">Тип возвращаемого значения.</param> /// <param name="is_overload">Перегружена-ли функция.</param> /// <param name="name">Имя</param> public basic_function_node(SemanticTree.basic_function_type bft, type_node ret_type, bool is_overload, string name) : base(ret_type) { _basic_function_type = bft; _overload = is_overload; _name = name; }
private static basic_function_node create_dec_method(SemanticTree.basic_function_type bft, type_node type) { basic_function_node bfn = create_oti_method(bft, type, SemanticTree.parameter_type.var); bfn.compile_time_executor = dec_compile_time_executor; return bfn; }
/// <summary> /// Метод для обхода дерева посетителем. /// </summary> /// <param name="visitor">Класс - посетитель дерева.</param> public override void visit(SemanticTree.ISemanticVisitor visitor) { visitor.visit(this); }
private access_level convert_field_access_level(SemanticTree.field_access_level fal) { switch (fal) { case SemanticTree.field_access_level.fal_private: return access_level.al_private; case SemanticTree.field_access_level.fal_public: return access_level.al_public; case SemanticTree.field_access_level.fal_protected: return access_level.al_protected; case SemanticTree.field_access_level.fal_internal: return access_level.al_internal; default: return access_level.al_none; } }
private static basic_function_node make_object_operator(type_node ctn, SemanticTree.basic_function_type bas_ft, string name, type_node ret_type, SemanticTree.parameter_type first_parameter_type) { basic_function_node bfn = new basic_function_node(bas_ft, ret_type,true,name); basic_parameter to = new basic_parameter(compiler_string_consts.left_param_name, ctn, first_parameter_type, bfn); basic_parameter from = new basic_parameter(compiler_string_consts.right_param_name, ctn, SemanticTree.parameter_type.value, bfn); bfn.parameters.AddElement(to); bfn.parameters.AddElement(from); ctn.add_name(name, new SymbolInfo(bfn)); add_stand_type(bas_ft, bfn); return bfn; }
//сохранение отлад. информации private void WriteDebugInfo(BinaryWriter bw,SemanticTree.ILocation loc) { if (pcu_file.IncludeDebugInfo) { if (loc != null) { bw.Write(loc.begin_line_num); bw.Write(loc.begin_column_num); bw.Write(loc.end_line_num); bw.Write(loc.end_column_num); } else { bw.Write((int)-1); bw.Write((int)-1); bw.Write((int)-1); bw.Write((int)-1); } } }
private static basic_function_node make_object_operator(type_node ctn, SemanticTree.basic_function_type bas_ft, string name, type_node ret_type) { return make_object_operator(ctn, bas_ft, name, ret_type, SemanticTree.parameter_type.value); }