diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f89e0b6e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +.vs + +*/**/bin +bin/Lib/*.pcu +bin/Lib/*.xml +bin/Lib/*.dll +bin/*.dll +bin/*.pdb +bin/*.config +bin/*.xml + +TestSuite/CompilationSamples/*.xml +TestSuite/exe +TestSuite/formatter_tests/output + +ReleaseGenerators/*.pdb +ReleaseGenerators/PABCRtl/*.dll +ReleaseGenerators/PABCRtl/*.pcu +ReleaseGenerators/PABCRtl/*.pdb + +**/obj + +ReleaseGenerators/RebuildStandartModules.exe +TestSuite/CompilationSamples/ClientServer.pas +TestSuite/CompilationSamples/PABCExtensions.pas +TestSuite/CompilationSamples/PT4MakerNetX.pas +TestSuite/CompilationSamples/Speech.pas +TestSuite/CompilationSamples/Робот.pas +TestSuite/CompilationSamples/Чертежник.pas +bin/PascalABCNET.exe +bin/System.Data.dll.txt +bin/System.Xml.dll.txt +bin/System.dll.txt +bin/mscorlib.txt +bin/pabcnetc.exe +bin/pabcnetcclear.exe \ No newline at end of file diff --git a/CodeCompletion/CodeFormatter.cs b/CodeCompletion/CodeFormatter.cs index b47c6a0cc..95ff19672 100644 --- a/CodeCompletion/CodeFormatter.cs +++ b/CodeCompletion/CodeFormatter.cs @@ -1680,25 +1680,30 @@ namespace CodeFormatters } public override void visit(class_members _class_members) - { + { if (_class_members.access_mod != null && _class_members.access_mod.source_context != null) { bool already_off = true; - if (_class_members.members.Count > 0 && _class_members.members[0].source_context != null && _class_members.access_mod.source_context.end_position.line_num == _class_members.members[0].source_context.begin_position.line_num) + declaration first_decl = null; + if (_class_members.members.Count > 0) + first_decl = _class_members.members[0]; + if (first_decl is short_func_definition) + first_decl = (first_decl as short_func_definition).procdef; + if (first_decl != null && first_decl.source_context != null && _class_members.access_mod.source_context.end_position.line_num == first_decl.source_context.begin_position.line_num) IncOffset(); else already_off = false; visit_node(_class_members.access_mod); - if (_class_members.members.Count > 0) - sb.Append(" "); + if (first_decl != null && !(_class_members.members[0] is short_func_definition)) + sb.Append(" "); if (!already_off) IncOffset(); } else - IncOffset(); + IncOffset(); foreach (declaration decl in _class_members.members) - { - visit_node(decl); + { + visit_node(decl); } DecOffset(); } @@ -1736,7 +1741,7 @@ namespace CodeFormatters } if (_class_definition.body != null) { - if (!(/*(_class_definition.keyword == class_keyword.Record || _class_definition.keyword == class_keyword.TemplateRecord) &&*/ (_class_definition.body.class_def_blocks.Count == 0 || _class_definition.body.class_def_blocks[0].members != null && _class_definition.body.class_def_blocks[0].members.Count == 0) && _class_definition.class_parents == null)) + if (!((_class_definition.body.class_def_blocks.Count == 0 || _class_definition.body.class_def_blocks[0].members != null && _class_definition.body.class_def_blocks[0].members.Count == 0) && _class_definition.class_parents == null)) { class_pred = false; visit_node(_class_definition.body); @@ -2741,6 +2746,7 @@ namespace CodeFormatters multiline_stack_push(_short_func_definition); add_space_after = true; + add_space_before = true; add_newline_after = false; visit_node(_short_func_definition.procdef.proc_header); bool tmp_in_procedure = in_procedure; diff --git a/CodeCompletion/DomConverter.cs b/CodeCompletion/DomConverter.cs index 738e30aee..3d8cae72a 100644 --- a/CodeCompletion/DomConverter.cs +++ b/CodeCompletion/DomConverter.cs @@ -425,8 +425,10 @@ namespace CodeCompletion } SymInfo[] elems = null; if (si == null) return null; - if (pattern == null || pattern == "") elems = si.GetNamesInAllTopScopes(all_names, new ExpressionVisitor(si, visitor), false); - else elems = si.GetNamesInAllTopScopes(all_names, new ExpressionVisitor(si, visitor), false); + if (pattern == null || pattern == "") + elems = si.GetNamesInAllTopScopes(all_names, new ExpressionVisitor(si, visitor), false); + else + elems = si.GetNamesInAllTopScopes(all_names, new ExpressionVisitor(si, visitor), false); List result_names = new List(); if (elems == null) return null; for (int i = 0; i < elems.Length; i++) @@ -522,7 +524,7 @@ namespace CodeCompletion if (elems == null) return null; for (int i = 0; i < elems.Length; i++) { - if (!elems[i].name.StartsWith("$") && (elems[i].kind == SymbolKind.Class || elems[i].kind == SymbolKind.Namespace) && elems[i].kind != SymbolKind.Interface) + if (!elems[i].name.StartsWith("$") && (elems[i].kind == SymbolKind.Class || elems[i].kind == SymbolKind.Struct || elems[i].kind == SymbolKind.Namespace) && elems[i].kind != SymbolKind.Interface) { if (expr != null && si != null && si is ElementScope && string.Compare(elems[i].name, (si as ElementScope).sc.si.name, true) == 0) @@ -930,7 +932,16 @@ namespace CodeCompletion else if (ss is TypeScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as TypeScope)); else if (ss is ProcScope) - ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as ProcScope)); + { + ProcScope ps = ss as ProcScope; + if (ps.original_function != null) + ps = ps.original_function; + if (ps is CompiledMethodScope) + ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ps as CompiledMethodScope).mi)); + else + ss.AddDocumentation(UnitDocCache.GetDocumentation(ps)); + } + else if (ss is InterfaceUnitScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as InterfaceUnitScope)); else if (ss is ElementScope && string.IsNullOrEmpty(ss.si.description) && (ss as ElementScope).sc is TypeScope) diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index 2c942fc15..d6f4c2d66 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -106,6 +106,42 @@ namespace CodeCompletion return false; } + private bool has_lambdas(expression node) + { + if (node is function_lambda_definition) + return true; + else if (node is dot_node) + { + dot_node dn = node as dot_node; + if (has_lambdas(dn.left)) + return true; + if (has_lambdas(dn.right)) + return true; + } + else if (node is method_call) + { + method_call mc = node as method_call; + if (has_lambdas(mc.dereferencing_value)) + return true; + if (mc.parameters != null) + foreach (expression e in mc.parameters.expressions) + { + if (has_lambdas(e)) + return true; + } + } + else if (node is tuple_node) + { + tuple_node tn = node as tuple_node; + foreach (expression e in tn.el.expressions) + { + if (has_lambdas(e)) + return true; + } + } + return false; + } + public override void visit(template_type_name node) { throw new Exception("The method or operation is not implemented."); @@ -141,13 +177,23 @@ namespace CodeCompletion public override void visit(assign _assign) { - //throw new Exception("The method or operation is not implemented."); - //if (_assign.to is ident && (_assign.to as ident).name == "result") - // _assign.from.visit(this); + if (_assign.from is function_lambda_definition) + { + _assign.to.visit(this); + TypeScope tmp_awaitedProcType = awaitedProcType; + if (returned_scope != null && returned_scope is TypeScope) + { + if (returned_scope is ProcScope) + returned_scope = new ProcType(returned_scope as ProcScope); + awaitedProcType = returned_scope as TypeScope; + } + _assign.from.visit(this); + awaitedProcType = tmp_awaitedProcType; + } + else if (has_lambdas(_assign.from)) + _assign.from.visit(this); } - - public override void visit(bin_expr _bin_expr) { try @@ -214,7 +260,7 @@ namespace CodeCompletion List meths = entry_scope.GetExtensionMethods(name, tleft); foreach (ProcScope meth in meths) lst.Add(meth); - ProcScope ps = select_method(lst.ToArray(), tleft, tright, null, _bin_expr.left, _bin_expr.right); + ProcScope ps = select_method(lst.ToArray(), tleft, tright, null, false, _bin_expr.left, _bin_expr.right); if (ps != null) returned_scope = ps.return_type; else @@ -352,9 +398,9 @@ namespace CodeCompletion if (returned_scope == null) { returned_scope = returned_scopes[0]; - if (returned_scope is ProcScope && (returned_scope as ProcScope).return_type == null ) + if (returned_scope is ProcScope && (returned_scope as ProcScope).return_type == null) returned_scope = new ProcType(returned_scope as ProcScope); - } + } else if (returned_scopes.Count > 0 && returned_scopes[0] is ProcScope && (returned_scopes[0] as ProcScope).return_type == null) returned_scope = new ProcType(returned_scopes[0] as ProcScope); } @@ -452,7 +498,8 @@ namespace CodeCompletion } public System.Collections.Hashtable vars = new System.Collections.Hashtable(); - + private TypeScope awaitedProcType; + public override void visit(var_def_statement _var_def_statement) { try @@ -463,7 +510,16 @@ namespace CodeCompletion if (_var_def_statement.vars_type == null && _var_def_statement.inital_value != null || _var_def_statement.inital_value is function_lambda_definition) { SymScope tmp_scope = returned_scope; + TypeScope tmp_awaitedProcType = awaitedProcType; + if (_var_def_statement.inital_value is function_lambda_definition) + { + if (tmp_scope is ProcScope) + tmp_scope = new ProcType(tmp_scope as ProcScope); + awaitedProcType = tmp_scope as TypeScope; + } + _var_def_statement.inital_value.visit(this); + awaitedProcType = tmp_awaitedProcType; if (tmp_scope != null && _var_def_statement.inital_value is function_lambda_definition) returned_scope = tmp_scope; } @@ -797,80 +853,99 @@ namespace CodeCompletion else if (attrs.proc_attributes[i].attribute_type == proc_attribute.attr_reintroduce) ps.is_reintroduce = true; } - - private ProcScope select_function_definition(ProcScope ps, formal_parameters prms, TypeScope return_type, TypeScope declType) + + private ProcScope select_function_definition(ProcScope ps, formal_parameters prms, TypeScope return_type, TypeScope declType, bool function=false) { - SymScope tmp = returned_scope; - List lst = new List(); - if (prms != null) - { - foreach (typed_parameters pars in prms.params_list) + SymScope tmp = returned_scope; + List lst = new List(); + if (prms != null) { - pars.vars_type.visit(this); - - if (returned_scope != null) - { - foreach (ident id in pars.idents.idents) - { - if (returned_scope is ProcScope) - returned_scope = new ProcType(returned_scope as ProcScope); - ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter,id.name),returned_scope,ps); - si.loc = get_location(id); - si.param_kind = pars.param_kind; - lst.Add(si); - } - } + foreach (typed_parameters pars in prms.params_list) + { + pars.vars_type.visit(this); + + if (returned_scope != null) + { + foreach (ident id in pars.idents.idents) + { + if (returned_scope is ProcScope) + returned_scope = new ProcType(returned_scope as ProcScope); + ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter, id.name), returned_scope, ps); + si.loc = get_location(id); + si.param_kind = pars.param_kind; + if (pars.inital_value != null) + { + cnst_val.prim_val = null; + if (pars.inital_value is nil_const) + si.cnst_val = "nil"; + else + { + pars.inital_value.visit(this); + if (cnst_val.prim_val != null) + si.cnst_val = cnst_val.prim_val; + else + si.cnst_val = pars.inital_value.ToString(); + } + + } + lst.Add(si); + } + } + } + while (ps != null) + { + if (ps.parameters != null) + { + if (ps.parameters.Count == lst.Count) + { + bool eq = true; + for (int i = 0; i < lst.Count; i++) + { + TypeScope left = ps.parameters[i].sc as TypeScope; + TypeScope right = lst[i].sc as TypeScope; + if (!left.IsEqual(right) || ps.parameters[i].param_kind != lst[i].param_kind) + { + eq = false; + break; + } + } + if (eq) + { + if (return_type == null) return ps; + if (ps.return_type != null && return_type != null) + { + if ((ps.return_type as TypeScope).IsEqual(return_type)) + return ps; + } + } + } + } + ps = ps.nextProc; + } } - while (ps != null) - { - if (ps.parameters != null) - { - if (ps.parameters.Count == lst.Count) - { - bool eq = true; - for (int i=0; i 0) { SymScope tmp_scope = cur_scope; - for (int i=0; i< _function_header.name.ln.Count; i++) + for (int i = 0; i < _function_header.name.ln.Count; i++) { tmp_scope = tmp_scope.FindName(_function_header.name.ln[i].name); if (tmp_scope == null) @@ -1228,17 +1281,17 @@ namespace CodeCompletion topScope = tmp_scope; } else - topScope = cur_scope.FindName(_function_header.name.class_name.name); - if (topScope != null) - { - ps = topScope.FindNameOnlyInThisType(meth_name) as ProcScope; + topScope = cur_scope.FindName(_function_header.name.class_name.name); + if (topScope != null) + { + ps = topScope.FindNameOnlyInThisType(meth_name) as ProcScope; if (ps != null && ps is CompiledMethodScope) ps = null; - if (ps == null) - { - ps = new ProcScope(meth_name, topScope); - - ps.head_loc = loc; + if (ps == null) + { + ps = new ProcScope(meth_name, topScope); + + ps.head_loc = loc; bool ext = false; if (topScope is CompiledScope || topScope is ArrayScope || topScope is TypeSynonim && ((topScope as TypeSynonim).actType is CompiledScope || (topScope as TypeSynonim).actType is ArrayScope || (topScope as TypeSynonim).actType is DiapasonScope)) ext = true; @@ -1247,7 +1300,7 @@ namespace CodeCompletion if (ext) { not_def = true; - ps.AddName("self", new ElementScope(new SymInfo("self",SymbolKind.Parameter,"self"),topScope,cur_scope)); + ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), topScope, cur_scope)); ps.declaringType = topScope as TypeScope; ps.is_extension = true; TypeScope ts = topScope as TypeScope; @@ -1256,57 +1309,61 @@ namespace CodeCompletion this.entry_scope.AddExtensionMethod(meth_name, ps, ts); topScope.AddExtensionMethod(meth_name, ps, ts); } - } - else ps = select_function_definition(ps,_function_header.parameters,return_type,topScope as TypeScope); - //while (ps != null && ps.already_defined) ps = ps.nextProc; - if (ps == null) - { - ps = new ProcScope(meth_name, cur_scope); - ps.head_loc = loc; + } + else + ps = select_function_definition(ps, _function_header.parameters, return_type, topScope as TypeScope, true); + //while (ps != null && ps.already_defined) ps = ps.nextProc; + if (ps == null) + { + ps = new ProcScope(meth_name, cur_scope); + ps.head_loc = loc; - } - if (ps.parameters.Count != 0 && _function_header.parameters != null && is_proc_realization) - { - ps.parameters.Clear(); - ps.already_defined = true; - } - if (impl_scope == null) - { - pr = new ProcRealization(ps, cur_scope); - pr.already_defined = true; - ps.proc_realization = pr; - pr.loc = cur_loc; - is_realization = true; - pr.head_loc = loc; - entry_scope.AddName("$method", pr); - } - else - { - pr = new ProcRealization(ps, impl_scope); - pr.already_defined = true; - ps.proc_realization = pr; - pr.loc = cur_loc; - pr.head_loc = loc; - is_realization = true; - impl_scope.AddName("$method",pr); - } - } - else - { - ps = new ProcScope(meth_name, cur_scope); - ps.head_loc = loc; - } - } - else - { - ps = new ProcScope(meth_name, cur_scope); - ps.head_loc = loc; + } + if (ps.parameters.Count != 0 && _function_header.parameters != null && is_proc_realization) + { + ps.parameters.Clear(); + ps.already_defined = true; + } + if (impl_scope == null) + { + pr = new ProcRealization(ps, cur_scope); + pr.already_defined = true; + ps.proc_realization = pr; + pr.loc = cur_loc; + is_realization = true; + pr.head_loc = loc; + entry_scope.AddName("$method", pr); + } + else + { + pr = new ProcRealization(ps, impl_scope); + pr.already_defined = true; + ps.proc_realization = pr; + pr.loc = cur_loc; + pr.head_loc = loc; + is_realization = true; + impl_scope.AddName("$method", pr); + } + } + else + { + ps = new ProcScope(meth_name, cur_scope); + ps.head_loc = loc; + } + } + else + { + ps = new ProcScope(meth_name, cur_scope); + ps.head_loc = loc; if (has_extensionmethod_attr(_function_header.proc_attributes.proc_attributes) && _function_header.parameters.params_list.Count > 0) { ps.is_extension = true; _function_header.parameters.params_list[0].vars_type.visit(this); topScope = returned_scope; + if (topScope is ProcScope) + topScope = new ProcType(topScope as ProcScope); ps.declaringType = topScope as TypeScope; + TypeScope ts = topScope as TypeScope; if (topScope is TypeSynonim) ts = (ts as TypeSynonim).actType; @@ -1353,7 +1410,7 @@ namespace CodeCompletion { //while ((ss as ProcScope).already_defined && (ss as ProcScope).nextProc != null) ss = (ss as ProcScope).nextProc; //ps = ss as ProcScope; - ps = select_function_definition(ss as ProcScope, _function_header.parameters, return_type, null); + ps = select_function_definition(ss as ProcScope, _function_header.parameters, return_type, null, true); if (ps == null) { ps = new ProcScope(meth_name, cur_scope); @@ -1418,20 +1475,20 @@ namespace CodeCompletion } } } - } - } - else - { - ps = new ProcScope("", cur_scope); - ps.head_loc = loc; - } - if ((!is_realization || not_def) && ps.loc == null) - ps.loc = cur_loc; - //ps.head_loc = loc; - ps.declaringUnit = entry_scope; + } + } + else + { + ps = new ProcScope("", cur_scope); + ps.head_loc = loc; + } + if ((!is_realization || not_def) && ps.loc == null) + ps.loc = cur_loc; + //ps.head_loc = loc; + ps.declaringUnit = entry_scope; SymScope tmp = cur_scope; if (_function_header.template_args != null && !ps.IsGeneric()) - { + { Dictionary where_types = new Dictionary(); if (_function_header.where_defs != null) { @@ -1446,86 +1503,100 @@ namespace CodeCompletion } } foreach (ident s in _function_header.template_args.idents) - { - ps.AddTemplateParameter(s.name); + { + ps.AddTemplateParameter(s.name); TypeScope where_ts = null; where_types.TryGetValue(s.name, out where_ts); if (where_ts == null) where_ts = TypeTable.obj_type; TemplateParameterScope tps = new TemplateParameterScope(s.name, where_ts, ps); - + tps.loc = get_location(s); ps.AddName(s.name, tps); - } + } if (ps.return_type == null) { cur_scope = ps; if (_function_header.return_type != null) _function_header.return_type.visit(this); return_type = returned_scope as TypeScope; - + cur_scope = tmp; } } - - SetAttributes(ps,_function_header.proc_attributes); - ps.is_static = _function_header.class_keyword; - if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_function_header)) - ps.AddDocumentation(this.converter.controller.docs[_function_header]); - if (is_proc_realization) + + SetAttributes(ps, _function_header.proc_attributes); + ps.is_static = _function_header.class_keyword; + if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_function_header)) + ps.AddDocumentation(this.converter.controller.docs[_function_header]); + if (is_proc_realization) { ps.already_defined = true; if (ps.loc == null) ps.loc = loc; - } - else - { - ps.loc = loc; - } + } + else + { + ps.loc = loc; + } if (_function_header.name == null || _function_header.name.class_name == null) - { - ps.acc_mod = cur_access_mod; - ps.si.acc_mod = cur_access_mod; - } - + { + ps.acc_mod = cur_access_mod; + ps.si.acc_mod = cur_access_mod; + } + cur_scope = ps; if (_function_header.parameters != null) - foreach (typed_parameters pars in _function_header.parameters.params_list) - { - pars.vars_type.visit(this); - if (returned_scope != null) - { - if (returned_scope is ProcScope) - returned_scope = new ProcType(returned_scope as ProcScope); - foreach (ident id in pars.idents.idents) - { - ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter,id.name),returned_scope,ps); - si.loc = get_location(id); - if (pars.inital_value != null) - { - pars.inital_value.visit(this); - si.cnst_val = cnst_val.prim_val; - } - ps.AddName(id.name,si); - si.param_kind = pars.param_kind; - si.MakeDescription(); - ps.AddParameter(si); - } - } - } + add_parameters(ps, _function_header.parameters); cur_scope = tmp; ps.return_type = return_type; //cur_scope = ps; - if (cur_scope is TypeScope && !ps.is_static) - ps.AddName("self",new ElementScope(new SymInfo("self", SymbolKind.Parameter,"self"),cur_scope,ps)); + if (cur_scope is TypeScope && !ps.is_static) + ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), cur_scope, ps)); returned_scope = ps; ps.AddName("Result", new ElementScope(new SymInfo("Result", SymbolKind.Variable, "Result"), ps.return_type, ps)); ps.Complete(); if (pr != null && not_def) - pr.Complete(); + pr.Complete(); } + private void add_parameters(ProcScope ps, formal_parameters parameters) + { + foreach (typed_parameters pars in parameters.params_list) + { + pars.vars_type.visit(this); + if (returned_scope != null) + { + if (returned_scope is ProcScope) + returned_scope = new ProcType(returned_scope as ProcScope); + foreach (ident id in pars.idents.idents) + { + ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter, id.name), returned_scope, ps); + si.loc = get_location(id); + if (pars.inital_value != null) + { + cnst_val.prim_val = null; + if (!(pars.inital_value is nil_const)) + { + pars.inital_value.visit(this); + if (cnst_val.prim_val != null) + si.cnst_val = cnst_val.prim_val; + else + si.cnst_val = pars.inital_value.ToString(); + } + else + si.cnst_val = "nil"; + } + ps.AddName(id.name, si); + si.param_kind = pars.param_kind; + si.MakeDescription(); + ps.AddParameter(si); + } + } + } + } + public override void visit(procedure_definition _procedure_definition) { @@ -1622,7 +1693,7 @@ namespace CodeCompletion //else if (returned_scope != null && returned_scope is TypeScope) { - if (!(_type_declaration.type_def is named_type_reference)) + if (!(_type_declaration.type_def is named_type_reference) && !(returned_scope is CompiledScope && _type_declaration.type_def is enum_type_definition)) { //(ret_tn as TypeScope).name = _type_declaration.type_name.name; returned_scope.si.name = _type_declaration.type_name.name; @@ -1632,7 +1703,12 @@ namespace CodeCompletion returned_scope.loc = get_location(_type_declaration);//new location(loc.begin_line_num,loc.begin_column_num,ret_tn.loc.end_line_num,ret_tn.loc.end_column_num,ret_tn.loc.doc); if (_type_declaration.type_def is class_definition) { - string key = this.converter.controller.Parser.LanguageInformation.GetClassKeyword((_type_declaration.type_def as class_definition).keyword); + class_definition cl_def = _type_declaration.type_def as class_definition; + string key = this.converter.controller.Parser.LanguageInformation.GetClassKeyword(cl_def.keyword); + if (cl_def.attribute == class_attribute.Auto) + key = "auto " + key; + else if (cl_def.attribute == class_attribute.Abstract) + key = "abstract " + key; if (key != null && returned_scope.body_loc != null) { returned_scope.head_loc = new location(returned_scope.body_loc.begin_line_num, returned_scope.body_loc.begin_column_num, returned_scope.body_loc.begin_line_num, returned_scope.body_loc.begin_column_num + key.Length, doc); @@ -1711,25 +1787,25 @@ namespace CodeCompletion public override void visit(simple_const_definition _simple_const_definition) { //throw new Exception("The method or operation is not implemented."); - try - { - _simple_const_definition.const_value.visit(this); - } - catch (Exception e) - { - - } - if (returned_scope != null /*&& cnst_val.prim_val != null*/) - { - ElementScope es = new ElementScope(new SymInfo(_simple_const_definition.const_name.name, SymbolKind.Constant,_simple_const_definition.const_name.name),returned_scope, cnst_val.prim_val,cur_scope); - cur_scope.AddName(_simple_const_definition.const_name.name, es); - es.loc = get_location(_simple_const_definition); - es.declaringUnit = entry_scope; - if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_simple_const_definition)) - es.AddDocumentation(this.converter.controller.docs[_simple_const_definition]); - } - returned_scope = null; - cnst_val.prim_val = null; + try + { + _simple_const_definition.const_value.visit(this); + } + catch (Exception e) + { + + } + if (returned_scope != null /*&& cnst_val.prim_val != null*/) + { + ElementScope es = new ElementScope(new SymInfo(_simple_const_definition.const_name.name, SymbolKind.Constant, _simple_const_definition.const_name.name), returned_scope, cnst_val.prim_val, cur_scope); + cur_scope.AddName(_simple_const_definition.const_name.name, es); + es.loc = get_location(_simple_const_definition); + es.declaringUnit = entry_scope; + if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_simple_const_definition)) + es.AddDocumentation(this.converter.controller.docs[_simple_const_definition]); + } + returned_scope = null; + cnst_val.prim_val = null; } public override void visit(typed_const_definition _typed_const_definition) @@ -2050,6 +2126,11 @@ namespace CodeCompletion if (_program_module.compiler_directives != null) foreach (PascalABCCompiler.SyntaxTree.compiler_directive dir in _program_module.compiler_directives) { +#if DEBUG + // SSM test 05.08.17 + if (dir == null) + File.AppendAllText("log.txt", "dir == null" + Environment.NewLine + _program_module.compiler_directives.Count + Environment.NewLine); +#endif if (dir.Name.text.ToLower() == "reference") { try @@ -2383,8 +2464,8 @@ namespace CodeCompletion TypeScope ts = returned_scope as TypeScope; if (returned_scope is ProcScope) ts = (returned_scope as ProcScope).return_type; - - returned_scope = ts.FindNameOnlyInType((_dot_node.right as ident).name); + if (ts != null) + returned_scope = ts.FindNameOnlyInType((_dot_node.right as ident).name); if (returned_scope == null) { List meths = entry_scope.GetExtensionMethods((_dot_node.right as ident).name, ts); @@ -2557,18 +2638,22 @@ namespace CodeCompletion return true; else return false; - if (args.Count == ps.parameters.Count) + if (args.Count == ps.parameters.Count || ps.IsExtension && args.Count == ps.parameters.Count - 1) { + int off = 0; + if (ps.IsExtension && args.Count == ps.parameters.Count - 1) + off = 1; for (int i = 0; i < args.Count; i++) { if (!(args[i] is TypeScope)) return false; TypeScope ts = args[i] as TypeScope; - if (!ts.IsEqual(ps.parameters[i].sc as TypeScope)) + ElementScope parameter = ps.parameters[i + off]; + if (!ts.IsEqual(parameter.sc as TypeScope)) { - if (ps.parameters[i].param_kind == parametr_kind.params_parametr) + if (parameter.param_kind == parametr_kind.params_parametr) { - if (!(ps.parameters[i].sc is ArrayScope && ts.IsEqual((ps.parameters[i].sc as ArrayScope).elementType))) + if (!(parameter.sc is ArrayScope && ts.IsEqual((parameter.sc as ArrayScope).elementType))) return false; } else @@ -2607,28 +2692,31 @@ namespace CodeCompletion } private SymScope[] selected_methods = null; + private bool disable_lambda_compilation = false; - private ProcScope select_method(SymScope[] meths, TypeScope tleft, TypeScope tright, TypeScope obj, params expression[] args) + private ProcScope select_method(SymScope[] meths, TypeScope tleft, TypeScope tright, TypeScope obj, bool obj_instanced, params expression[] args) { - List arg_types = new List(); + List arg_types = new List(); List arg_types2 = new List(); SymScope[] saved_selected_methods = selected_methods; selected_methods = meths; if (tleft != null || tright != null) { if (tleft != null) - { + { arg_types.Add(tleft); arg_types2.Add(tleft); } if (tright != null) - { + { arg_types.Add(tright); arg_types2.Add(tright); } } else if (args != null) { + bool tmp_disable_lambda_compilation = disable_lambda_compilation; + disable_lambda_compilation = true; foreach (expression e in args) { e.visit(this); @@ -2636,26 +2724,28 @@ namespace CodeCompletion arg_types.Add(returned_scope); arg_types2.Add(returned_scope as TypeScope); } + disable_lambda_compilation = false; + disable_lambda_compilation = tmp_disable_lambda_compilation; } selected_methods = saved_selected_methods; - List good_procs = new List(); - for (int i=0; i 1) - for (int i=0; i good_procs = new List(); + for (int i = 0; i < meths.Length; i++) + { + if (meths[i] is ProcScope) + { + if (is_good_overload(meths[i] as ProcScope, arg_types)) + good_procs.Add(meths[i] as ProcScope); + } + else if (meths[i] is ProcType) + { + if (is_good_overload((meths[i] as ProcType).target, arg_types)) + good_procs.Add((meths[i] as ProcType).target); + } + } + if (good_procs.Count > 1) + for (int i = 0; i < good_procs.Count; i++) + if (DomSyntaxTreeVisitor.is_good_exact_overload(good_procs[i] as ProcScope, arg_types)) + return good_procs[i].GetInstance(arg_types2); if (good_procs.Count == 0) { for (int i = 0; i < meths.Length; i++) @@ -2669,18 +2759,18 @@ namespace CodeCompletion } } } - if (good_procs.Count > 0) + if (good_procs.Count > 0) { if (obj != null) { - if (obj.GetElementType() != null && good_procs[0].IsExtension && !(good_procs[0].parameters[0].sc is TemplateParameterScope)) + if (!obj_instanced && obj.GetElementType() != null && good_procs[0].IsExtension && !(good_procs[0].parameters[0].sc is TemplateParameterScope)) obj = obj.GetElementType(); arg_types2.Insert(0, obj); } - + return good_procs[0].GetInstance(arg_types2); - } - return null; + } + return null; } public override void visit(method_call _method_call) @@ -2692,6 +2782,7 @@ namespace CodeCompletion SymScope[] names = returned_scopes.ToArray(); List parameters = new List(); TypeScope obj = null; + bool obj_instanced = false; if (names.Length > 0 && names[0] is TypeScope) { returned_scope = names[0]; @@ -2717,7 +2808,11 @@ namespace CodeCompletion { List generic_args = interf.GetInstances(); if (generic_args != null && generic_args.Count > 0) + { obj = generic_args[0]; + obj_instanced = true; + } + } } } @@ -2726,8 +2821,24 @@ namespace CodeCompletion } } if (_method_call.parameters != null) + { parameters.AddRange(_method_call.parameters.expressions); - ProcScope ps = select_method(names, null, null, obj, parameters.ToArray()); + } + List lambda_types = new List(); + ProcScope ps = select_method(names, null, null, obj, obj_instanced, parameters.ToArray()); + if (_method_call.parameters != null && ps != null) + for (int i = 0; i < _method_call.parameters.expressions.Count; i++) + { + expression e = _method_call.parameters.expressions[i]; + if (e is function_lambda_definition) + { + TypeScope tmp_awaitedProcType = awaitedProcType; + if (ps.parameters != null && ps.parameters.Count > i) + awaitedProcType = ps.parameters[i + (ps.IsExtension ? 1 : 0)].sc as TypeScope; + e.visit(this); + awaitedProcType = tmp_awaitedProcType; + } + } returned_scopes.Clear(); if (ps != null) @@ -2766,6 +2877,7 @@ namespace CodeCompletion returned_scope = ss; } } + cnst_val.prim_val = null; } public override void visit(pascal_set_constant _pascal_set_constant) @@ -3232,14 +3344,9 @@ namespace CodeCompletion public override void visit(procedure_call _procedure_call) { //throw new Exception("The method or operation is not implemented."); - method_call mc = _procedure_call.func_name as method_call; - if (mc != null && mc.parameters != null) + if (has_lambdas(_procedure_call.func_name)) { - foreach (expression arg in mc.parameters.expressions) - { - if (arg is function_lambda_definition) - arg.visit(this); - } + _procedure_call.func_name.visit(this); } } @@ -3535,7 +3642,10 @@ namespace CodeCompletion public override void visit(typecast_node _typecast_node) { - _typecast_node.type_def.visit(this); + if (_typecast_node.cast_op == op_typecast.is_op) + returned_scope = TypeTable.bool_type; + else + _typecast_node.type_def.visit(this); } public override void visit(interface_node _interface_node) @@ -4452,11 +4562,35 @@ namespace CodeCompletion { ProcScope ps = new ProcScope(_function_lambda_definition.lambda_name, this.cur_scope); ps.loc = get_location(_function_lambda_definition); - cur_scope.AddName(_function_lambda_definition.lambda_name, ps); + if (!disable_lambda_compilation) + cur_scope.AddName(_function_lambda_definition.lambda_name, ps); if (_function_lambda_definition.ident_list != null) - foreach (ident id in _function_lambda_definition.ident_list.idents) + for (int i=0; i<_function_lambda_definition.ident_list.idents.Count; i++) { + ident id = _function_lambda_definition.ident_list.idents[i]; TypeScope param_type = new UnknownScope(new SymInfo("T", SymbolKind.Type, "T")); + if (awaitedProcType != null) + { + if (awaitedProcType is TypeSynonim) + awaitedProcType = (awaitedProcType as TypeSynonim).actType; + if (awaitedProcType is ProcType) + { + if ((awaitedProcType as ProcType).target.parameters.Count > 0) + param_type = (awaitedProcType as ProcType).target.parameters[i].sc as TypeScope; + } + else if (awaitedProcType.IsDelegate && awaitedProcType.instances != null && awaitedProcType.instances.Count > 0) + { + param_type = awaitedProcType.instances[i]; + } + else if (awaitedProcType.IsDelegate) + { + var invokeMeth = awaitedProcType.FindNameOnlyInType("Invoke") as ProcScope; + if (invokeMeth != null && invokeMeth.parameters != null && invokeMeth.parameters.Count > i) + { + param_type = invokeMeth.parameters[i].sc as TypeScope; + } + } + } /*if (selected_methods != null) { foreach (ProcScope meth in selected_methods) @@ -4473,10 +4607,23 @@ namespace CodeCompletion ps.AddParameter(es); es.loc = get_location(id); } - _function_lambda_definition.proc_body.visit(this); + SymScope tmp = cur_scope; + cur_scope = ps; + if (!disable_lambda_compilation) + { + statement_list sl = _function_lambda_definition.proc_body as statement_list; + if (sl != null && sl.list.Count == 1 && sl.list[0] is assign && (sl.list[0] as assign).to is ident + && ((sl.list[0] as assign).to as ident).name.ToLower() == "result") + (sl.list[0] as assign).from.visit(this); + else + _function_lambda_definition.proc_body.visit(this); + } + + cur_scope = tmp; ps.return_type = returned_scope as TypeScope; returned_scope = new ProcType(ps); } + public override void visit(function_lambda_call _function_lambda_call) { // @@ -4510,7 +4657,7 @@ namespace CodeCompletion { SymScope tmp = cur_scope; TypeScope ts = null; - cur_scope = ts = new TypeScope(SymbolKind.Class, tmp, null); + cur_scope = ts = new TypeScope(SymbolKind.Class, entry_scope, null); tmp.AddName("class", cur_scope); ts.loc = get_location(_unnamed_type_object); ts.si = new SymInfo("class", SymbolKind.Class, ""); @@ -4568,6 +4715,16 @@ namespace CodeCompletion mc.visit(this); } + public override void visit(slice_expr _slice_expr) + { + _slice_expr.v.visit(this); + } + + public override void visit(slice_expr_question _slice_expr_question) + { + _slice_expr_question.v.visit(this); + } + public override void visit(modern_proc_type _modern_proc_type) { template_type_reference ttr = new template_type_reference(); diff --git a/CodeCompletion/ExpressionEvaluator.cs b/CodeCompletion/ExpressionEvaluator.cs index b5c3ea430..6ffa10ce6 100644 --- a/CodeCompletion/ExpressionEvaluator.cs +++ b/CodeCompletion/ExpressionEvaluator.cs @@ -444,206 +444,206 @@ namespace CodeCompletion eval_stack.Push(res); } - - public void EvalMult() - { - RetValue right = eval_stack.Pop(); - RetValue left = eval_stack.Pop(); - RetValue res = new RetValue(); - if (left.prim_val != null && right.prim_val != null) - { - TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType()); - TypeCode rcode = Type.GetTypeCode(right.prim_val.GetType()); - switch (lcode) - { - case TypeCode.Int32: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (int)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (int)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (int)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (int)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((int)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (int)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (int)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (int)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (int)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((int)left.prim_val) * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (int)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Double: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (double)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (double)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (double)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (double)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((double)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (double)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (double)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (double)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (double)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (double)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (double)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Byte: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (byte)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (byte)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (byte)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (byte)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((byte)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (byte)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (byte)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (byte)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (byte)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (byte)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (byte)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Int16: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Int16)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Int16)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Int16)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Int16)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Int16)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Int16)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Int16)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Int16)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Int16)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((System.Int16)left.prim_val) * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.Int16)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Int64: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Int64)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Int64)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Int64)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Int64)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Int64)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Int64)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Int64)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Int64)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Int64)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.Int64)left.prim_val * (System.Int64)((System.UInt64)right.prim_val); break; - case TypeCode.Single : res.prim_val = (System.Int64)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - - case TypeCode.SByte: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.SByte)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.SByte)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.SByte)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.SByte)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.SByte)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.SByte)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.SByte)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.SByte)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.SByte)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((System.SByte)left.prim_val) * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.SByte)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt16: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt16)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt16)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.UInt16)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.UInt16)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt16)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt16)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.UInt16)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.UInt16)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt16)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt16)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt16)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt32: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt32)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt32)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.UInt32)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.UInt32)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt32)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt32)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.UInt32)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.UInt32)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt32)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt32)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt32)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt64: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt64)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((int)right.prim_val); break; - case TypeCode.Double : res.prim_val = (System.UInt64)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (long)((System.UInt64)left.prim_val) * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt64)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((System.Int16)right.prim_val); break; - case TypeCode.SByte : res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((sbyte)right.prim_val); break; - case TypeCode.UInt16 : res.prim_val = (System.UInt64)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt64)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt64)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Single: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Single)left.prim_val * (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Single)left.prim_val * (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Single)left.prim_val * (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Single)left.prim_val * (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Single)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Single)left.prim_val * (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Single)left.prim_val * (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Single)left.prim_val * (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Single)left.prim_val * (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.Single)left.prim_val * (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.Single)left.prim_val * (System.Single)right.prim_val; break; - } - } - break; - - } - - } - - eval_stack.Push(res); - } + + public void EvalMult() + { + RetValue right = eval_stack.Pop(); + RetValue left = eval_stack.Pop(); + RetValue res = new RetValue(); + if (left.prim_val != null && right.prim_val != null) + { + TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType()); + TypeCode rcode = Type.GetTypeCode(right.prim_val.GetType()); + switch (lcode) + { + case TypeCode.Int32: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (int)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (int)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (int)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (int)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((int)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (int)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (int)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (int)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (int)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt64)((int)left.prim_val) * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (int)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.Double: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (double)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (double)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (double)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (double)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((double)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (double)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (double)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (double)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (double)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (double)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (double)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.Byte: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (byte)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (byte)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (byte)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (byte)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((byte)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (byte)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (byte)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (byte)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (byte)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (byte)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (byte)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.Int16: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.Int16)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.Int16)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.Int16)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.Int16)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.Int16)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.Int16)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.Int16)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.Int16)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.Int16)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.Int16)left.prim_val) * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.Int16)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.Int64: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.Int64)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.Int64)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.Int64)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.Int64)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.Int64)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.Int64)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.Int64)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.Int64)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.Int64)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.Int64)left.prim_val * (System.Int64)((System.UInt64)right.prim_val); break; + case TypeCode.Single: res.prim_val = (System.Int64)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + + case TypeCode.SByte: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.SByte)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.SByte)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.SByte)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.SByte)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.SByte)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.SByte)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.SByte)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.SByte)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.SByte)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.SByte)left.prim_val) * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.SByte)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.UInt16: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.UInt16)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.UInt16)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.UInt16)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.UInt16)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.UInt16)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.UInt16)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.UInt16)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.UInt16)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.UInt16)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt16)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.UInt16)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.UInt32: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.UInt32)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.UInt32)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.UInt32)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.UInt32)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.UInt32)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.UInt32)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.UInt32)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.UInt32)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.UInt32)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt32)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.UInt32)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.UInt64: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.UInt64)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((int)right.prim_val); break; + case TypeCode.Double: res.prim_val = (System.UInt64)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (long)((System.UInt64)left.prim_val) * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.UInt64)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((System.Int16)right.prim_val); break; + case TypeCode.SByte: res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)((sbyte)right.prim_val); break; + case TypeCode.UInt16: res.prim_val = (System.UInt64)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.UInt64)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.UInt64)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.UInt64)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + case TypeCode.Single: + { + switch (rcode) + { + case TypeCode.Byte: res.prim_val = (System.Single)left.prim_val * (byte)right.prim_val; break; + case TypeCode.Int32: res.prim_val = (System.Single)left.prim_val * (int)right.prim_val; break; + case TypeCode.Double: res.prim_val = (System.Single)left.prim_val * (double)right.prim_val; break; + case TypeCode.Int64: res.prim_val = (System.Single)left.prim_val * (long)right.prim_val; break; + //case TypeCode.String : res.prim_val = ((System.Single)left.prim_val).ToString() + (string)right.prim_val; break; + case TypeCode.Int16: res.prim_val = (System.Single)left.prim_val * (System.Int16)right.prim_val; break; + case TypeCode.SByte: res.prim_val = (System.Single)left.prim_val * (sbyte)right.prim_val; break; + case TypeCode.UInt16: res.prim_val = (System.Single)left.prim_val * (System.UInt16)right.prim_val; break; + case TypeCode.UInt32: res.prim_val = (System.Single)left.prim_val * (System.UInt32)right.prim_val; break; + case TypeCode.UInt64: res.prim_val = (System.Single)left.prim_val * (System.UInt64)right.prim_val; break; + case TypeCode.Single: res.prim_val = (System.Single)left.prim_val * (System.Single)right.prim_val; break; + } + } + break; + + } + + } + + eval_stack.Push(res); + } public void EvalDiv() { @@ -652,192 +652,7 @@ namespace CodeCompletion RetValue res = new RetValue(); if (left.prim_val != null && right.prim_val != null) { - TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType()); - TypeCode rcode = Type.GetTypeCode(right.prim_val.GetType()); - switch (lcode) - { - case TypeCode.Int32: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (int)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (int)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (int)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (int)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((int)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (int)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (int)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (int)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (int)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((int)left.prim_val) / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (int)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Double: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (double)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (double)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (double)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (double)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((double)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (double)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (double)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (double)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (double)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (double)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (double)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Byte: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (byte)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (byte)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (byte)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (byte)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((byte)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (byte)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (byte)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (byte)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (byte)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (byte)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (byte)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Int16: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Int16)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Int16)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Int16)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Int16)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Int16)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Int16)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Int16)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Int16)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Int16)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((System.Int16)left.prim_val) / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.Int16)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Int64: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Int64)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Int64)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Int64)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Int64)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Int64)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Int64)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Int64)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Int64)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Int64)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.Int64)left.prim_val / (System.Int64)((System.UInt64)right.prim_val); break; - case TypeCode.Single : res.prim_val = (System.Int64)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - - case TypeCode.SByte: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.SByte)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.SByte)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.SByte)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.SByte)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.SByte)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.SByte)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.SByte)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.SByte)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.SByte)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)((System.SByte)left.prim_val) / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.SByte)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt16: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt16)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt16)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.UInt16)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.UInt16)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt16)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt16)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.UInt16)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.UInt16)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt16)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt16)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt16)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt32: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt32)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt32)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.UInt32)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.UInt32)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt32)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt32)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.UInt32)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.UInt32)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt32)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt32)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt32)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.UInt64: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.UInt64)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.UInt64)left.prim_val / (System.UInt64)((int)right.prim_val); break; - case TypeCode.Double : res.prim_val = (System.UInt64)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (long)((System.UInt64)left.prim_val) / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.UInt64)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.UInt64)left.prim_val / (System.UInt64)((System.Int16)right.prim_val); break; - case TypeCode.SByte : res.prim_val = (System.UInt64)left.prim_val / (System.UInt64)((sbyte)right.prim_val); break; - case TypeCode.UInt16 : res.prim_val = (System.UInt64)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.UInt64)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.UInt64)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.UInt64)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - case TypeCode.Single: - { - switch(rcode) - { - case TypeCode.Byte : res.prim_val = (System.Single)left.prim_val / (byte)right.prim_val; break; - case TypeCode.Int32 : res.prim_val = (System.Single)left.prim_val / (int)right.prim_val; break; - case TypeCode.Double : res.prim_val = (System.Single)left.prim_val / (double)right.prim_val; break; - case TypeCode.Int64 : res.prim_val = (System.Single)left.prim_val / (long)right.prim_val; break; - //case TypeCode.String : res.prim_val = ((System.Single)left.prim_val).ToString() + (string)right.prim_val; break; - case TypeCode.Int16 : res.prim_val = (System.Single)left.prim_val / (System.Int16)right.prim_val; break; - case TypeCode.SByte : res.prim_val = (System.Single)left.prim_val / (sbyte)right.prim_val; break; - case TypeCode.UInt16 : res.prim_val = (System.Single)left.prim_val / (System.UInt16)right.prim_val; break; - case TypeCode.UInt32 : res.prim_val = (System.Single)left.prim_val / (System.UInt32)right.prim_val; break; - case TypeCode.UInt64 : res.prim_val = (System.Single)left.prim_val / (System.UInt64)right.prim_val; break; - case TypeCode.Single : res.prim_val = (System.Single)left.prim_val / (System.Single)right.prim_val; break; - } - } - break; - } + res.prim_val = Convert.ToDouble(left.prim_val) / Convert.ToDouble(right.prim_val); eval_stack.Push(res); } } diff --git a/CodeCompletion/ExpressionVisitor.cs b/CodeCompletion/ExpressionVisitor.cs index 65b70f098..ba303605d 100644 --- a/CodeCompletion/ExpressionVisitor.cs +++ b/CodeCompletion/ExpressionVisitor.cs @@ -297,7 +297,7 @@ namespace CodeCompletion if (returned_scope == null) returned_scope = returned_scopes[0]; } - if (returned_scope == null && entry_scope.topScope == null) + /*if (returned_scope == null && entry_scope.topScope == null) { try { @@ -313,17 +313,13 @@ namespace CodeCompletion try { returned_scope = entry_scope.topScope.FindNameInAnyOrder(_ident.name); - /*if (ret_scope != null) - { - if (!ret_scope.IsInScope(ret_scope.loc,_ident.source_context.begin_position.line_num,_ident.source_context.begin_position.column_num)) - ret_scope = null; - }*/ + } catch (Exception e) { } - } + }*/ if (returned_scope != null) { if (returned_scope is ProcScope) @@ -930,14 +926,26 @@ namespace CodeCompletion } if (good_procs.Count > 0) { + int ind = 0; if (obj != null) { + for (int i = 0; i < good_procs.Count; i++) + { + TypeScope param_type = good_procs[i].parameters[0].sc as TypeScope; + if (param_type.original_type != null) + param_type = param_type.original_type; + if (good_procs[i].IsExtension && param_type.IsEqual(obj)) + { + ind = i; + break; + } + } if (obj.GetElementType() != null && good_procs[0].IsExtension && !(good_procs[0].parameters[0].sc is TemplateParameterScope)) obj = obj.GetElementType(); arg_types2.Insert(0, obj); } - return good_procs[0].GetInstance(arg_types2); + return good_procs[ind].GetInstance(arg_types2); } return null; } @@ -1008,10 +1016,13 @@ namespace CodeCompletion ProcScope proc = ss as ProcScope; if (_method_call.dereferencing_value is dot_node) { + bool tmp = by_dot; + by_dot = true; (_method_call.dereferencing_value as dot_node).left.visit(this); if (returned_scope is ElementScope) returned_scope = (returned_scope as ElementScope).sc; obj = returned_scope as TypeScope; + by_dot = tmp; if (obj != null && proc.parameters != null && proc.parameters.Count > 0 && !(proc.parameters[0].sc is TemplateParameterScope || proc.parameters[0].sc is UnknownScope)) { TypeScope param_type = proc.parameters[0].sc as TypeScope; @@ -1235,7 +1246,7 @@ namespace CodeCompletion public override void visit(procedure_call _procedure_call) { - throw new NotImplementedException(); + _procedure_call.func_name.visit(this); } public override void visit(class_predefinition _class_predefinition) @@ -1692,7 +1703,40 @@ namespace CodeCompletion public override void visit(ident_with_templateparams node) { node.name.visit(this); - if (this.returned_scope != null) + if (returned_scopes.Count > 0 && returned_scopes[0] is ProcScope) + { + ProcScope ps = returned_scopes[0] as ProcScope; + List template_params = new List(); + foreach (type_definition td in node.template_params.params_list) + { + td.visit(this); + if (returned_scope is TypeScope) + template_params.Add(returned_scope as TypeScope); + else + { + return; + } + } + returned_scopes[0] = ps.GetInstance(template_params); + } + else if (returned_scope is ProcScope) + { + ProcScope ps = returned_scope as ProcScope; + List template_params = new List(); + foreach (type_definition td in node.template_params.params_list) + { + td.visit(this); + if (returned_scope is TypeScope) + template_params.Add(returned_scope as TypeScope); + else + { + returned_scope = ps; + return; + } + } + returned_scope = ps.GetInstance(template_params); + } + /*else if (this.returned_scope != null) { if (this.returned_scope is TypeScope) { @@ -1706,7 +1750,7 @@ namespace CodeCompletion } returned_scope = ts.GetInstance(instances); } - } + }*/ } public override void visit(bracket_expr _bracket_expr) diff --git a/CodeCompletion/FindReferences.cs b/CodeCompletion/FindReferences.cs index 988516553..369b581c2 100644 --- a/CodeCompletion/FindReferences.cs +++ b/CodeCompletion/FindReferences.cs @@ -68,7 +68,15 @@ namespace CodeCompletion if (cur_scope == null) cur_scope = tmp; foreach (statement stmt in _statement_list.subnodes) + { + IBaseScope tmp2 = cur_scope; + cur_scope = cur_scope.FindScopeByLocation(stmt.source_context.begin_position.line_num, stmt.source_context.begin_position.column_num); + if (cur_scope == null) + cur_scope = tmp2; stmt.visit(this); + cur_scope = tmp2; + } + cur_scope = tmp; } diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index ce286f31f..fa7bd5bc4 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -384,31 +384,38 @@ namespace CodeCompletion tmp_ts = tmp_ts.baseScope; } if (ts.implemented_interfaces != null && !(ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr)) - foreach (TypeScope int_ts in ts.implemented_interfaces) { - TypeScope int_ts2 = int_ts; - if (int_ts is CompiledScope && (int_ts as CompiledScope).CompiledType.IsGenericType && !(int_ts as CompiledScope).CompiledType.IsGenericTypeDefinition) - int_ts2 = TypeTable.get_compiled_type((int_ts as CompiledScope).CompiledType.GetGenericTypeDefinition()); - if (extension_methods.TryGetValue(int_ts2, out meths)) + List implemented_interfaces = new List(); + implemented_interfaces.AddRange(ts.implemented_interfaces); + if (ts is ArrayScope) + implemented_interfaces.Add((ts as ArrayScope).ilist); + foreach (TypeScope int_ts in implemented_interfaces) { - lst.AddRange(meths); - } - else - { - foreach (TypeScope t in extension_methods.Keys) + TypeScope int_ts2 = int_ts; + if (int_ts is CompiledScope && (int_ts as CompiledScope).CompiledType.IsGenericType && !(int_ts as CompiledScope).CompiledType.IsGenericTypeDefinition) + int_ts2 = TypeTable.get_compiled_type((int_ts as CompiledScope).CompiledType.GetGenericTypeDefinition()); + if (extension_methods.TryGetValue(int_ts2, out meths)) { - if (t.GenericTypeDefinition == int_ts2.GenericTypeDefinition || t.IsEqual(int_ts2) || - (t is ArrayScope && int_ts2.IsArray && t.Rank == int_ts2.Rank) || - (int_ts2 is ArrayScope && t.IsArray && int_ts2.Rank == t.Rank) || - t is FileScope && int_ts2 is FileScope) - { - lst.AddRange(extension_methods[t]); - //break; - } + lst.AddRange(meths); + } + else + { + foreach (TypeScope t in extension_methods.Keys) + { + if (t.GenericTypeDefinition == int_ts2.GenericTypeDefinition || t.IsEqual(int_ts2) || + (t is ArrayScope && int_ts2.IsArray && t.Rank == int_ts2.Rank) || + (int_ts2 is ArrayScope && t.IsArray && int_ts2.Rank == t.Rank) || + t is FileScope && int_ts2 is FileScope) + { + lst.AddRange(extension_methods[t]); + //break; + } + } + } - } } + } if (this.used_units != null) for (int i = 0; i < this.used_units.Count; i++) @@ -443,7 +450,8 @@ namespace CodeCompletion public void AddUsedUnit(SymScope unit) { - used_units.Add(unit); + if (this.si.name != "PABCSystem") + used_units.Add(unit); } public virtual string GetFullName() @@ -645,7 +653,10 @@ namespace CodeCompletion { res = ss; SymScope tmp = ss.FindScopeByLocation(line, column); - if (tmp != null) return res = tmp; + if (tmp != null) + return tmp; + else + return res; } else if (!(ss is CompiledScope)) { @@ -672,6 +683,15 @@ namespace CodeCompletion return lst.ToArray(); } + protected bool IsClassMember(SymScope scope) + { + if (scope is ProcScope && (scope as ProcScope).declaringType != null) + return true; + if (scope is ElementScope && (scope as ElementScope).declaringUnit is TypeScope) + return true; + return false; + } + protected bool IsAfterDefinition(int def_line, int def_col) { if (cur_line == -1 || cur_col == -1) return true; @@ -791,7 +811,7 @@ namespace CodeCompletion { if (string.Compare(ss.loc.doc.file_name, loc.doc.file_name, true) == 0 && this != ss) { - if (IsAfterDefinition(ss.loc.begin_line_num, ss.loc.begin_column_num)) + if (IsClassMember(ss) || IsAfterDefinition(ss.loc.begin_line_num, ss.loc.begin_column_num)) { return ss; } @@ -809,7 +829,7 @@ namespace CodeCompletion { if (string.Compare(ss.loc.doc.file_name, loc.doc.file_name, !CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive) == 0 && this != ss) { - if (IsAfterDefinition(ss.loc.begin_line_num, ss.loc.begin_column_num)) + if (IsClassMember(ss) || IsAfterDefinition(ss.loc.begin_line_num, ss.loc.begin_column_num)) { return ss; } @@ -1303,12 +1323,17 @@ namespace CodeCompletion public override SymScope FindName(string s) { + if (string.Compare(si.name, s, true) == 0) + return this; return sc.FindNameOnlyInType(s); } public override List FindOverloadNames(string name) { - return sc.FindOverloadNamesOnlyInType(name); + List names = sc.FindOverloadNames(name); + if (topScope != null) + names.AddRange(topScope.FindOverloadNames(name)); + return names; } public override TypeScope GetElementType() @@ -1735,6 +1760,7 @@ namespace CodeCompletion public bool is_extension = false; public List generic_params; public List generic_args; + public ProcScope original_function; public ProcScope() { @@ -1795,6 +1821,14 @@ namespace CodeCompletion } } + public bool OfTypeInstance + { + get + { + return original_function != null || declaringType != null && declaringType.instances != null && declaringType.instances.Count > 0; + } + } + public virtual bool IsStatic { get @@ -1883,6 +1917,7 @@ namespace CodeCompletion return this; ProcScope instance = new ProcScope(this.name, this.topScope, this.is_constructor); instance.is_extension = this.is_extension; + instance.original_function = this; instance.loc = this.loc; instance.body_loc = this.body_loc; instance.parameters = new List(this.parameters.Count); @@ -1915,7 +1950,8 @@ namespace CodeCompletion gen_args.RemoveRange(i, gen_args.Count - i); } instance.si = this.si; - instance.return_type = this.return_type.GetInstance(gen_args); + if (this.return_type != null) + instance.return_type = this.return_type.GetInstance(gen_args); return instance; } @@ -2660,7 +2696,9 @@ namespace CodeCompletion TypeScope original_type = actType; if (actType.original_type != null) original_type = actType.original_type; - return original_type.GetInstance(gen_args); + TypeScope ts = original_type.GetInstance(gen_args); + ts.aliased = true; + return ts; } public override void AddIndexer(TypeScope ts) @@ -2881,6 +2919,7 @@ namespace CodeCompletion public TypeScope[] indexes; private bool _is_dynamic_arr = false; private bool _is_multi_dyn_arr = false; + internal TypeScope ilist; public ArrayScope() { @@ -2914,7 +2953,8 @@ namespace CodeCompletion lst.Add(elementType); this.implemented_interfaces = new List(); this.implemented_interfaces.Add(CompiledScope.get_type_instance(typeof(IEnumerable<>), lst)); - this.implemented_interfaces.Add(CompiledScope.get_type_instance(typeof(IList<>), lst)); + ilist = CompiledScope.get_type_instance(typeof(IList<>), lst); + //this.implemented_interfaces.Add(CompiledScope.get_type_instance(typeof(IList<>), lst)); } this.si = new SymInfo("$" + this.ToString(), SymbolKind.Type, this.ToString()); this.members = new List(); @@ -3050,6 +3090,8 @@ namespace CodeCompletion public override SymScope FindName(string name) { + if (string.Compare(si.name, name, true) == 0) + return this; if (!is_dynamic_arr && !IsMultiDynArray) return null; SymScope sc = null; @@ -3130,26 +3172,17 @@ namespace CodeCompletion if (ts is NullTypeScope && is_dynamic_arr) return true; ArrayScope arrs = ts as ArrayScope; + if (ts is CompiledScope && (ts as CompiledScope).IsArray) + { + return this.elementType.IsEqual(ts.GetElementType()); + } if (arrs == null || !arrs.is_dynamic_arr) if (ts is TypeSynonim) return this.IsEqual((ts as TypeSynonim).actType); else return false; if (arrs.elementType == null) return true; if (!this.elementType.IsEqual(arrs.elementType)) return false; return true; - if (this.indexes == null && arrs.indexes == null) return true;//????? - if (this.indexes != null && arrs.indexes != null) - { - if (this.indexes.Length != arrs.indexes.Length) return false; - for (int i = 0; i < this.indexes.Length; i++) - if (this.indexes[i] == null && arrs.indexes[i] == null) - continue; - else if (this.indexes[i] == null && arrs.indexes[i] != null || this.indexes[i] != null && arrs.indexes[i] == null) - return false; - else - if (!this.indexes[i].IsEqual(arrs.indexes[i])) return false; - return true; - } - return false; + } public override ProcScope GetConstructor() @@ -3789,6 +3822,12 @@ namespace CodeCompletion { ts.elementType = internalInstance(this.elementType, gen_args); } + if (implemented_interfaces != null) + { + ts.implemented_interfaces = new List(); + for (int j = 0; j < this.implemented_interfaces.Count; j++) + ts.implemented_interfaces.Add(internalInstance(this.implemented_interfaces[j], gen_args)); + } if (this.indexers != null && this.indexers.Count > 0) { ts.indexers = new List(); @@ -3898,6 +3937,8 @@ namespace CodeCompletion return true; if (this.IsGenericParameter && ts.IsGenericParameter && this.Name == ts.Name) return true; + if (ts is TemplateParameterScope) + return true; TypeScope tmp = this.baseScope; while (tmp != null) if (tmp.IsEqual(ts)) @@ -4894,8 +4935,8 @@ namespace CodeCompletion sc.generic_params.Add(gen_args[i].si.name); sc.instances.Add(this.instances[i].GetInstance(gen_args)); } - - } + + } } else for (int i = 0; i < gen_args.Count; i++) @@ -4904,6 +4945,10 @@ namespace CodeCompletion sc.generic_params.Add(gen_args[i].si.name); sc.instances.Add(gen_args[i]); } + sc.implemented_interfaces = new List(); + if (this.implemented_interfaces != null) + for (int i = 0; i < this.implemented_interfaces.Count; i++) + sc.implemented_interfaces.Add(this.implemented_interfaces[i].GetInstance(gen_args)); sc.si.description = sc.GetDescription(); return sc; } @@ -5058,6 +5103,8 @@ namespace CodeCompletion public override bool IsConvertable(TypeScope ts) { CompiledScope cs = ts as CompiledScope; + if (ts == null) + return true; if (ts is NullTypeScope && !ctn.IsValueType) return true; if (cs == null) @@ -5104,6 +5151,10 @@ namespace CodeCompletion if (this.ctn.IsSubclassOf(cs.ctn)) return true; + if (implemented_interfaces != null) + foreach (TypeScope interf in implemented_interfaces) + if (interf.IsEqual(ts)) + return true; TypeCode code1 = Type.GetTypeCode(this.ctn); TypeCode code2 = Type.GetTypeCode(cs.ctn); bool left = false; @@ -6696,7 +6747,10 @@ namespace CodeCompletion public override SymInfo[] GetNames() { - return return_type.GetNames(); + if (return_type != null) + return return_type.GetNames(); + else + return new SymInfo[0]; } // public override SymInfo[] GetNames(ExpressionVisitor ev) @@ -6706,7 +6760,10 @@ namespace CodeCompletion public override SymScope FindName(string name) { - return return_type.FindName(name); + if (return_type != null) + return return_type.FindName(name); + else + return null; } public override SymScope FindNameOnlyInType(string name) diff --git a/CodeCompletion/Testing.cs b/CodeCompletion/Testing.cs index b84ddf304..f7330e0cf 100644 --- a/CodeCompletion/Testing.cs +++ b/CodeCompletion/Testing.cs @@ -369,8 +369,13 @@ namespace CodeCompletion off = test_str.Length; s = parser.LanguageInformation.FindExpression(off,test_str,line,col,out keyw); assert(s.Trim('\n',' ','\t')==test_str); - - int num_param = 0; + + test_str = "()->(obj as string).Trim"; + off = test_str.Length; + s = parser.LanguageInformation.FindExpression(off, test_str, line, col, out keyw); + assert(s.Trim('\n', ' ', '\t') == "(obj as string).Trim"); + + int num_param = 0; //testirovanie nazhatija skobki test_str = "writeln"; off = test_str.Length; @@ -460,8 +465,14 @@ namespace CodeCompletion s = parser.LanguageInformation.FindExpressionForMethod(off,test_str,line,col,'(',ref num_param); assert(s == test_str); assert(num_param==0); - - test_str = "test; \n sin"; + + test_str = "()->(obj as string).Trim"; + off = test_str.Length; + s = parser.LanguageInformation.FindExpressionForMethod(off, test_str, line, col, '(', ref num_param); + assert(s == "(obj as string).Trim"); + assert(num_param == 0); + + test_str = "test; \n sin"; off = test_str.Length; s = parser.LanguageInformation.FindExpressionForMethod(off,test_str,line,col,'(',ref num_param); assert(s.Trim(' ','\n','\t') == "sin"); @@ -653,8 +664,15 @@ namespace CodeCompletion s = parser.LanguageInformation.FindExpressionForMethod(off,test_str,line,col,',',ref num_param); assert(s.Trim(' ','\n','\t') == "new RGB"); assert(num_param == 2); - - string str = null; + + test_str = "Power(10 div 2"; + off = test_str.Length; + num_param = 1; + s = parser.LanguageInformation.FindExpressionForMethod(off, test_str, line, col, ',', ref num_param); + assert(s.Trim(' ', '\n', '\t') == "Power"); + assert(num_param == 2); + + string str = null; //mouse hover test_str = "sin(2)"; off = 1; diff --git a/CodeCompletion/TypeTable.cs b/CodeCompletion/TypeTable.cs index 1325beec8..e4b23d3b1 100644 --- a/CodeCompletion/TypeTable.cs +++ b/CodeCompletion/TypeTable.cs @@ -119,7 +119,8 @@ namespace CodeCompletion private static ProcScope char_smeq; private static ProcScope char_gr; private static ProcScope char_greq; - + private static ProcScope char_plus; + private static ProcScope string_plus; private static ProcScope string_eq; private static ProcScope string_noteq; @@ -798,7 +799,7 @@ namespace CodeCompletion int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, int64_plus); int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name, int64_minus); int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.mul_name, int64_mul); - int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.div_name, int64_div); + int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.idiv_name, int64_div); int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.mod_name, int64_mod); int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.shl_name, int64_shl); int_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.shr_name, int64_shr); @@ -968,6 +969,23 @@ namespace CodeCompletion ps.AddParameter(right); char_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.gr_name, ps); + ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, char_type); + char_plus = ps; + left = new ElementScope(new SymInfo("", SymbolKind.Parameter, ""), char_type, char_type); + right = new ElementScope(new SymInfo("", SymbolKind.Parameter, ""), char_type, char_type); + ps.return_type = string_type; + ps.AddParameter(left); + ps.AddParameter(right); + char_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, ps); + + ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, char_type); + left = new ElementScope(new SymInfo("", SymbolKind.Parameter, ""), char_type, char_type); + right = new ElementScope(new SymInfo("", SymbolKind.Parameter, ""), string_type, char_type); + ps.return_type = string_type; + ps.AddParameter(left); + ps.AddParameter(right); + char_type.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, ps); + //string type ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.plus_name, string_type); string_plus = ps; diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 01da74be9..105d619e2 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -260,6 +260,24 @@ namespace PascalABCCompiler } + public class IncludeNamespaceInUnit: CompilerCompilationError + { + public IncludeNamespaceInUnit(string FileName, SyntaxTree.SourceContext sc) + : base(string.Format(StringResources.Get("COMPILATIONERROR_INCLUDE_NAMESPACE_IN_UNIT")), FileName) + { + this.source_context = sc; + } + } + + public class NamespaceModuleExpected : CompilerCompilationError + { + public NamespaceModuleExpected(SyntaxTree.SourceContext sc) + : base(string.Format(StringResources.Get("COMPILATIONERROR_NAMESPACE_MODULE_EXPECTED"))) + { + this.source_context = sc; + } + } + public class MainResourceNotAllowed : CompilerCompilationError { public MainResourceNotAllowed(TreeRealization.location sl) @@ -1789,7 +1807,7 @@ namespace PascalABCCompiler //Console.WriteLine("Compile Implementation "+UnitName);//DEBUG //TODO: Избавиться от преобразования типа. - AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, null); #if DEBUG if (InternalDebug.SemanticAnalysis) @@ -2645,8 +2663,8 @@ namespace PascalABCCompiler { TreeRealization.location loc = cd.location; SyntaxTree.SourceContext sc = null; - if (loc!=null) - sc = new SyntaxTree.SourceContext(loc.begin_line_num,loc.begin_column_num,loc.end_line_num,loc.end_column_num,0,0); + if (loc != null) + sc = new SyntaxTree.SourceContext(loc.begin_line_num, loc.begin_column_num, loc.end_line_num, loc.end_column_num, 0, 0); string UnitName = null; try { @@ -2656,7 +2674,7 @@ namespace PascalABCCompiler { throw; } - catch(Exception ex) + catch (Exception ex) { throw new InvalidAssemblyPathError(CurrentCompilationUnit.SyntaxTree.file_name, sc); } @@ -2670,9 +2688,146 @@ namespace PascalABCCompiler } else //throw new DLLReadingError(UnitName); - throw new AssemblyReadingError(CurrentCompilationUnit.SyntaxTree.file_name,UnitName,sc); + throw new AssemblyReadingError(CurrentCompilationUnit.SyntaxTree.file_name, UnitName, sc); } - + + private bool HasIncludeNamespacesDirective(CompilationUnit Unit) + { + var directives = ConvertDirectives(Unit.SyntaxTree); + foreach (TreeRealization.compiler_directive cd in directives) + { + if (cd.name.ToLower() == TreeConverter.compiler_string_consts.include_namespace_directive) + { + return true; + } + } + return false; + } + + private Dictionary IncludeNamespaces(CompilationUnit Unit) + { + if (HasIncludeNamespacesDirective(Unit) && Unit.SyntaxTree is SyntaxTree.unit_module && (Unit.SyntaxTree as SyntaxTree.unit_module).unit_name.HeaderKeyword != SyntaxTree.UnitHeaderKeyword.Library) + throw new IncludeNamespaceInUnit(CurrentCompilationUnit.SyntaxTree.file_name, CurrentCompilationUnit.SyntaxTree.source_context); + var directives = ConvertDirectives(Unit.SyntaxTree); + SyntaxTree.unit_module main_library = Unit.SyntaxTree as SyntaxTree.unit_module; + SyntaxTree.program_module main_program = Unit.SyntaxTree as SyntaxTree.program_module; + List files = new List(); + + foreach (TreeRealization.compiler_directive cd in directives) + { + if (cd.name.ToLower() == TreeConverter.compiler_string_consts.include_namespace_directive) + { + string directive = cd.directive.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); + + if (directive == "*.pas" || directive.EndsWith(Path.DirectorySeparatorChar + "*.pas")) + { + string dir = Path.Combine(Path.GetDirectoryName(Unit.SyntaxTree.file_name), directive.Replace(Path.DirectorySeparatorChar + "*.pas", "")); + foreach (string file in Directory.EnumerateFiles(dir, "*.pas")) + files.Add(file); + } + else + files.Add(Path.Combine(Path.GetDirectoryName(Unit.SyntaxTree.file_name), directive)); + + + } + } + Dictionary namespaces = new Dictionary(); + List namespace_modules = new List(); + foreach (string file in files) + { + if (!File.Exists(file)) + throw new FileNotFound(file); + SyntaxTree.compilation_unit tree = GetNamespaceSyntaxTree(file); + if (!(tree is SyntaxTree.unit_module)) + throw new NamespaceModuleExpected(tree.source_context); + SyntaxTree.unit_module unit = tree as SyntaxTree.unit_module; + if (unit.unit_name.HeaderKeyword != SyntaxTree.UnitHeaderKeyword.Namespace) + throw new NamespaceModuleExpected(unit.unit_name.source_context); + if (unit.implementation_part != null) + throw new NamespaceModuleExpected(unit.implementation_part.source_context); + if (unit.finalization_part != null) + throw new NamespaceModuleExpected(unit.finalization_part.source_context); + if (unit.initialization_part != null && unit.initialization_part.list.Count > 0) + throw new NamespaceModuleExpected(unit.initialization_part.source_context); + SyntaxTree.syntax_namespace_node ns = null; + if (!namespaces.TryGetValue(unit.unit_name.idunit_name.name, out ns)) + { + ns = new SyntaxTree.syntax_namespace_node(unit.unit_name.idunit_name.name); + ns.referenced_units = new TreeRealization.unit_node_list(); + namespaces[unit.unit_name.idunit_name.name] = ns; + } + if (unit.interface_part.interface_definitions != null) + { + foreach (SyntaxTree.declaration decl in unit.interface_part.interface_definitions.defs) + { + ns.defs.Add(decl); + } + if (unit.interface_part.uses_modules != null) + { + checkDuplicateUsesUnit(unit.interface_part.uses_modules.units); + foreach (SyntaxTree.unit_or_namespace name_space in unit.interface_part.uses_modules.units) + { + if (IsPossibleNamespace(name_space, false)) + { + ns.referenced_units.AddElement(new TreeRealization.namespace_unit_node(GetNamespace(name_space))); + } + else + { + namespace_modules.Add(name_space); + } + } + } + } + } + foreach (string s in namespaces.Keys) + { + if (main_library != null) + main_library.interface_part.interface_definitions.Insert(0, namespaces[s]); + else + main_program.program_block.defs.Insert(0, namespaces[s]); + } + SyntaxTree.uses_list main_uses = null; + if (main_library != null) + { + if (main_library.interface_part.uses_modules != null) + main_uses = main_library.interface_part.uses_modules; + } + else if (main_program.used_units != null) + main_uses = main_program.used_units; + if (main_uses == null) + main_uses = new SyntaxTree.uses_list(); + Dictionary dict = new Dictionary(); + foreach (SyntaxTree.unit_or_namespace name_space in namespace_modules) + { + string name = SyntaxTree.Utils.IdentListToString(name_space.name.idents, ".").ToLower(); + if (!dict.ContainsKey(name)) + { + main_uses.Add(name_space); + dict.Add(name, name); + } + } + if (main_library != null) + main_library.interface_part.uses_modules = main_uses; + else + main_program.used_units = main_uses; + return namespaces; + } + + private SyntaxTree.compilation_unit GetNamespaceSyntaxTree(string FileName) + { + string SourceText = GetSourceFileText(FileName); + List DefinesList = new List(); + if (!compilerOptions.Debug && !compilerOptions.ForDebugging) + DefinesList.Add("RELEASE"); + else + DefinesList.Add("DEBUG"); + SyntaxTree.compilation_unit SyntaxTree = InternalParseText(FileName, SourceText, errorsList, warnings, DefinesList); + if (errorsList.Count > 0) + throw errorsList[0]; + SyntaxTree = syntaxTreeConvertersController.Convert(SyntaxTree) as SyntaxTree.compilation_unit; + return SyntaxTree; + } + public TreeRealization.unit_node_list GetReferences(CompilationUnit Unit) { //TODO переделать, ConvertDirectives определена дважды и вызывается дважды! @@ -2763,9 +2918,9 @@ namespace PascalABCCompiler return new TreeRealization.using_namespace(SyntaxTree.Utils.IdentListToString(_name_space.name.idents, ".")); } - private TreeRealization.using_namespace GetNamespace(TreeRealization.using_namespace_list using_list, string full_namespace_name, SyntaxTree.unit_or_namespace _name_space, bool possible_is_unit) + private TreeRealization.using_namespace GetNamespace(TreeRealization.using_namespace_list using_list, string full_namespace_name, SyntaxTree.unit_or_namespace _name_space, bool possible_is_unit, Dictionary pabc_namespaces) { - if (!NetHelper.NetHelper.NamespaceExists(full_namespace_name)) + if (!NetHelper.NetHelper.NamespaceExists(full_namespace_name) && !(pabc_namespaces != null && pabc_namespaces.ContainsKey(full_namespace_name))) { if (possible_is_unit) if (!full_namespace_name.Contains(".")) @@ -2775,16 +2930,16 @@ namespace PascalABCCompiler return new TreeRealization.using_namespace(full_namespace_name); } - public void AddNamespaces(TreeRealization.using_namespace_list using_list, List namespaces, bool possible_is_units) + public void AddNamespaces(TreeRealization.using_namespace_list using_list, List namespaces, bool possible_is_units, Dictionary pabc_namespaces) { foreach (SyntaxTree.unit_or_namespace ns in namespaces) - using_list.AddElement(GetNamespace(using_list, SyntaxTree.Utils.IdentListToString(ns.name.idents, "."), ns, possible_is_units)); + using_list.AddElement(GetNamespace(using_list, SyntaxTree.Utils.IdentListToString(ns.name.idents, "."), ns, possible_is_units, pabc_namespaces)); } public void AddNamespaces(TreeRealization.using_namespace_list using_list, SyntaxTree.using_list ul) { if (ul != null) - AddNamespaces(using_list, ul.namespaces, false); + AddNamespaces(using_list, ul.namespaces, false, null); } public SyntaxTree.using_list GetInterfaceSyntaxUsingList(SyntaxTree.compilation_unit cu) @@ -2912,19 +3067,6 @@ namespace PascalABCCompiler string SourceFileName = FindSourceFileName(Path.Combine(Path.GetDirectoryName(UnitName), Path.GetFileNameWithoutExtension(UnitName))); try { - //TODO: подумать как это нормально сделать - /*if (CompilerOptions.Debug) - { - PCUReader.PCUFileHeadState PCUFileHeadState = PCUReader.GetPCUFileHeadState(UnitName); - if (PCUFileHeadState.IsPCUFile && - PCUFileHeadState.SupportedVersion && - !PCUFileHeadState.IncludetDebugInfo && - SourceFileName != null) - { - //перекомпилируем файл для получения отладочной информации - throw new Exception(""); - } - }*/ if ((CurrentUnit = ReadPCU(UnitName)) != null) { Units.AddElement(CurrentUnit.SemanticTree); @@ -2979,6 +3121,7 @@ namespace PascalABCCompiler if (errorsList.Count == 0) // SSM 2/05/16 - для преобразования синтаксических деревьев извне { CurrentUnit.SyntaxTree = syntaxTreeConvertersController.Convert(CurrentUnit.SyntaxTree) as SyntaxTree.compilation_unit; + } if (errorsList.Count == 0 && need_gen_doc(CurrentUnit.SyntaxTree)) @@ -3053,7 +3196,7 @@ namespace PascalABCCompiler } } TreeRealization.unit_node_list References = GetReferences(CurrentUnit); - + var namespaces = IncludeNamespaces(CurrentUnit); if (SyntaxUsesList != null) { @@ -3098,9 +3241,9 @@ namespace PascalABCCompiler CurrentUnit.InterfaceUsedUnits.AddRange(References); - AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, namespaces); AddNamespaces(CurrentUnit.InterfaceUsingNamespaceList, GetInterfaceSyntaxUsingList(CurrentUnit.SyntaxTree)); - + //Console.WriteLine("Compile Interface "+UnitName);//DEBUG #if DEBUG if (InternalDebug.SemanticAnalysis) @@ -3163,7 +3306,7 @@ namespace PascalABCCompiler CurrentCompilationUnit = CurrentUnit; - AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true); + AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, CurrentUnit.PossibleNamespaces, true, namespaces); AddNamespaces(CurrentUnit.ImplementationUsingNamespaceList, GetImplementationSyntaxUsingList(CurrentUnit.SyntaxTree)); if (!interfcompile) diff --git a/Compiler/Compiler.csproj b/Compiler/Compiler.csproj index 3796bd0e0..ded532985 100644 --- a/Compiler/Compiler.csproj +++ b/Compiler/Compiler.csproj @@ -96,7 +96,7 @@ - ..\bin\ICSharpCode.NRefactory.dll + ..\Libraries\ICSharpCode.NRefactory.dll False @@ -105,7 +105,7 @@ False - ..\bin\Microsoft.Scripting.dll + ..\Libraries\Microsoft.Scripting.dll System diff --git a/Compiler/PCU/PCUReader.cs b/Compiler/PCU/PCUReader.cs index b18e7bcd1..e84247ebe 100644 --- a/Compiler/PCU/PCUReader.cs +++ b/Compiler/PCU/PCUReader.cs @@ -477,9 +477,10 @@ namespace PascalABCCompiler.PCU type_node tn = GetSpecialTypeReference(names[i].offset); if (tn is compiled_type_node) { - if ((tn as compiled_type_node).scope == null) - (tn as compiled_type_node).init_scope(); - (tn as compiled_type_node).scope.AddSymbol(names[i].name, si); + compiled_type_node ctn = tn as compiled_type_node; + if (ctn.scope == null) + ctn.init_scope(); + ctn.scope.AddSymbol(names[i].name, si); } else if (tn is generic_instance_type_node) tn.Scope.AddSymbol(names[i].name, si); @@ -2532,12 +2533,6 @@ namespace PascalABCCompiler.PCU private void RestoreAllFields(common_type_node ctn) { //восстанавливаем все методы - - //(ssyy) Внимание!!! Данный код удваивает все методы! - //Я изменил его. - //DarkStar - посмотри: NETGenerator после этого кода - //дважды переводит каждую функцию. - //DarkStar: Да, Ты прав!. Метод я переписал. string[] mnames = class_names[ctn]; WrappedClassScope wcs = ctn.scope as WrappedClassScope; foreach (string mname in mnames) @@ -2908,10 +2903,6 @@ namespace PascalABCCompiler.PCU for (int i=0; i=255) then + dgr := - dgr; + View3D.BackgroundColor := RGB(gr,gr,gr); + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/pr3.pas b/InstallerSamples/Graph3D/pr3.pas new file mode 100644 index 000000000..5641cf14e --- /dev/null +++ b/InstallerSamples/Graph3D/pr3.pas @@ -0,0 +1,16 @@ +uses Graph3D; + +begin + View3D.Title := ' '; + var t := Teapot(0, 0, 1, Colors.Green); + OnKeyDown := k -> begin + case k of + Key.Left: t.X += 1; + Key.Right: t.X -= 1; + Key.Down: t.Y += 1; + Key.Up: t.Y -= 1; + Key.PageUp: t.Z += 1; + Key.PageDown: t.Z -= 1; + end; + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/pr4_Planes.pas b/InstallerSamples/Graph3D/pr4_Planes.pas new file mode 100644 index 000000000..d19e5da1d --- /dev/null +++ b/InstallerSamples/Graph3D/pr4_Planes.pas @@ -0,0 +1,22 @@ +uses Graph3D; + +begin + View3D.ShowGridLines := False; + + Camera.Position := P3D(12,16,24); + Camera.LookDirection := Camera.Position.Multiply(-1).ToVector3D; + + var sz := 12; + var alpha := 100; + var planeXZ := Rectangle3D(0,0,0,sz,sz,V3D(0,1,0),Colors.Green.ChangeAlpha(alpha)); + var planeXY := Rectangle3D(0,0,0,sz,sz,V3D(0,0,1),Colors.Blue.ChangeAlpha(alpha)); + var planeYZ := Rectangle3D(0,0,0,sz,sz,V3D(1,0,0),V3D(0,1,0),Colors.Red.ChangeAlpha(alpha)); + BillboardText(sz/2,sz/2,0,'XY',20); + BillboardText(0,sz/2,sz/2,'YZ',20); + BillboardText(sz/2,0,sz/2,'XZ',20); + var len := 8; + CoordinateSystem(len,0.3); + BillboardText(len+0.5,0,0,'X',20); + BillboardText(0,len+0.5,0,'Y',20); + BillboardText(0,0,len+0.5,'Z',20); +end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/pr5_cam.pas b/InstallerSamples/Graph3D/pr5_cam.pas new file mode 100644 index 000000000..a04dde906 --- /dev/null +++ b/InstallerSamples/Graph3D/pr5_cam.pas @@ -0,0 +1,27 @@ +uses Graph3D; + +begin + Window.Title := ' '; + var tp := Teapot(0,0,2,Colors.Green); + tp.Scale(2); + Camera.Position := P3D(8,16,20); + Camera.LookDirection := Camera.Position.Multiply(-1).ToVector3D; + var d := 26.0; + {loop 200 do + begin + Sleep(20); + Camera.SetDistanse(d); + d -= 0.05; + end;} + var t := 0.0; + while True do + begin + Sleep(10); + Camera.Position := P3D(15*cos(t),15*sin(t),10); + Camera.UpDirection := V3D(0,0,1); + //Camera.LookDirection := Camera.Position.Multiply(-1).ToVector3D; + t += 2*Pi/360/2; + end; + + Camera.LookDirection := Camera.Position.Multiply(-1).ToVector3D; +end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/Часы.pas b/InstallerSamples/Graph3D/Часы.pas new file mode 100644 index 000000000..21e641040 --- /dev/null +++ b/InstallerSamples/Graph3D/Часы.pas @@ -0,0 +1,23 @@ +uses Graph3D; + +begin + View3D.ShowGridLines := False; + var := Cylinder(0,0,-0.4,0.2,6,Colors.DeepPink); + var := Arrow(0,0,0,0,-5.5,0,0.2,Colors.Yellow); + var := Arrow(0,0,0,0,-6.0,0,0.3,Colors.Red); + + var a := 0; + var r := 5.8; + loop 60 do + begin + Sphere(r*cos(a*Pi/180),r*sin(a*Pi/180),-0.2,0.1,Colors.White); + a += 6; + end; + + while True do + begin + Sleep(10); + .Rotate(v3D(0,0,1),-6); + .Rotate(v3D(0,0,1),-6/60); + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/ArcSector.pas b/InstallerSamples/Graphics/GraphWPF/ArcSector.pas new file mode 100644 index 000000000..d2cea5b0c --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/ArcSector.pas @@ -0,0 +1,15 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + var (x,y) := (200,Window.Height/2); + Circle(x,y,5); + for var i:=1 to 18*2 do + Arc(x,y,5*i,0,10*i); + (x,y) := (600,Window.Height/2); + for var i:=1 to 12 do + begin + Brush.Color := RandomColor; + Sector(x,y,180,30*(i-1),30*i); + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/Clock.pas b/InstallerSamples/Graphics/GraphWPF/Clock.pas new file mode 100644 index 000000000..dab908f30 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/Clock.pas @@ -0,0 +1,12 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Font.Size := 180; + while True do + begin + DrawText(Window.ClientRect,System.DateTime.Now.ToLongTimeString,Colors.Red); + Sleep(1000); + Window.Clear; + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas b/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas new file mode 100644 index 000000000..eed3c7c04 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas @@ -0,0 +1,36 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Pen.Width := 0.5; + Brush.Color := RGB(128,200,100); + Ellipse(100,100,30,20); + Brush.Color := RandomColor; + Circle(170,100,20); + Brush.Color := RandomColor; + Rectangle(220,80,70,50); + Line(220,80,220+70,80+50); + //DrawImage(200,140,'cofe.jpg'); + Brush.Color := RGB(200,200,255); + Polygon(Arr(Pnt(20,20),Pnt(20,120),Pnt(120,20))); + Brush.Color := Colors.Black; + for var i:=0 to 400 do + Rectangle(1+2*i,2,0,0); + Font.Size := 30; + Font.Color := Colors.Red; + TextOut(0,0,'Hello'); + Font.Size := 40; + Font.Color := Colors.Blue; + Font.Name := 'Times New Roman'; + Font.Style := FontStyle.BoldItalic; + TextOut(200,0,''); + Sleep(1000); + Window.Save('1.png'); + Window.Title := ''; + Sleep(1000); + Window.Clear; + Window.Title := ''; + Sleep(1000); + Window.Load('1.png'); + Window.Title := ''; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas b/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas new file mode 100644 index 000000000..2580ba67d --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas @@ -0,0 +1,11 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + var ww := Window.Width / 2; + var hh := Window.Height / 2; + DrawGraph(x -> sin(4 * x) + cos(3 * x), -5, 5, 0, 0, ww, hh); + DrawGraph(x -> x * x, -5, 5, ww - 1, 0, ww, hh); + DrawGraph(x -> exp(x), -5, 5, 0, hh-1, ww, hh); + DrawGraph(x -> x*cos(2*x-1), -5, 5, ww - 1, hh-1, ww, hh); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas b/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas new file mode 100644 index 000000000..564874776 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas @@ -0,0 +1,7 @@ +uses GraphWPF; + +begin + Pen.Width := 1; + Rectangle(0,0,Window.Width-1,Window.Height-1); + Ellipse((Window.Width-1)/2,(Window.Height-1)/2,(Window.Width-1)/2,(Window.Height-1)/2); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/Ellipses.pas b/InstallerSamples/Graphics/GraphWPF/Ellipses.pas new file mode 100644 index 000000000..8a75e5b89 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/Ellipses.pas @@ -0,0 +1,14 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Pen.Width := 1; + var n := 20000; + for var i:=1 to n do + begin + if i mod 10000 = 0 then + Println(i,MillisecondsDelta); + Brush.Color := RandomColor; + Ellipse(Random(800),Random(600),Random(20),Random(20)); + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/anim1.pas b/InstallerSamples/Graphics/GraphWPF/anim1.pas new file mode 100644 index 000000000..8d4d92903 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/anim1.pas @@ -0,0 +1,16 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + var x := 30; + Brush.Color := Colors.Beige; + Circle(x,50,20); + loop 600 do + begin + Sleep(10); + Window.Clear; + x += 1; + Circle(x,50,20); + Window.Title := '' + (Milliseconds div 100)/10; + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/anim2.pas b/InstallerSamples/Graphics/GraphWPF/anim2.pas new file mode 100644 index 000000000..adab6e7a5 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/anim2.pas @@ -0,0 +1,25 @@ +uses GraphWPF; + +begin + Window.Title := ' . '; + Brush.Color := Colors.Beige; + var x := 400.0; + var y := 300.0; + var dx := 2.1; + var dy := -1.2; + Circle(x,y,20); + while True do + begin + Sleep(10); + Window.Clear; + x += dx; + y += dy; + if not x.Between(0,Window.Width) then + dx := -dx; + if not y.Between(0,Window.Height) then + dy := -dy; + Circle(x,y,20); + if Milliseconds>2000 then + Window.Title := ': ' + (Milliseconds div 100)/10; + end; +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/anim4.pas b/InstallerSamples/Graphics/GraphWPF/anim4.pas new file mode 100644 index 000000000..a61561d05 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/anim4.pas @@ -0,0 +1,45 @@ +uses GraphWPF; + +function RandomReal(a,b: real): real := Random*(b-a)+a; + +type + BallInfo = auto class + x,y,r,dx,dy: real; + c: Color; + procedure Move := (x,y) := (x+dx,y+dy); + procedure Draw := FillCircle(x,y,r,c); + procedure CheckDirection; + begin + if not x.Between(r,Window.Width-r) then + dx := -dx; + if not y.Between(r,Window.Height-r) then + dy := -dy; + end; + procedure Step; + begin + Move; + CheckDirection; + Draw; + end; + class function CreateRandomBallArray(n: integer): array of BallInfo; + begin + var rr := 20; + Result := ArrGen(n,i->new BallInfo(RandomReal(rr,Window.Width-rr), + RandomReal(rr,Window.Height-rr),RandomReal(5,15), + RandomReal(-3,3),RandomReal(-3,3),RandomColor)); + end; + end; + +begin + Window.Title := ' . '; + + var n := 1000; + var a := BallInfo.CreateRandomBallArray(n); + + BeginFrameBasedAnimation(()-> + foreach var ball in a do + ball.Step + ); + + //BeginFrameBasedAnimation(()->a.ForEach(ball->ball.Step)); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/mouse1.pas b/InstallerSamples/Graphics/GraphWPF/mouse1.pas new file mode 100644 index 000000000..59f22dc9f --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/mouse1.pas @@ -0,0 +1,6 @@ +uses GraphWPF; + +begin + OnMouseDown := (x,y,mb) -> if mb=1 then Circle(x,y,5); + OnKeyDown := k -> Print(k); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/mouse2.pas b/InstallerSamples/Graphics/GraphWPF/mouse2.pas new file mode 100644 index 000000000..4cddff0c6 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/mouse2.pas @@ -0,0 +1,10 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Pen.Color := Colors.Blue; + Pen.Width := 3; + OnMouseDown := (x,y,mb) -> MoveTo(x,y); + OnMouseMove := (x,y,mb) -> if mb=1 then LineTo(x,y); + OnKeyDown := k -> if k = Key.Space then Window.Save('a.png'); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas b/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas new file mode 100644 index 000000000..cc5df21eb --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas @@ -0,0 +1,12 @@ +uses GraphWPF; + +procedure (x0,y0,r: real; n: integer); +begin + var q := Partition(0,2*Pi,n).Select(a->Pnt(x0 + r * Cos(a), y0 - r * Sin(a))); + q.Cartesian(q).ForEach(p->Line(p[0].x,p[0].y,p[1].x,p[1].y,RandomColor)); +end; + +begin + Pen.Width := 0.5; + (400,300,290,30) +end. diff --git a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas new file mode 100644 index 000000000..d5c6671b1 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas @@ -0,0 +1,30 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Font.Size := 20; + var (x,y) := (200,200); + var (w,h) := (400,200); + DrawRectangle(x,y,w,h); + DrawText(x,y,w,h,'LeftTop',Alignment.LeftTop); + DrawText(x,y,w,h,'LeftCenter',Alignment.LeftCenter); + DrawText(x,y,w,h,'LeftBottom',Alignment.LeftBottom); + DrawText(x,y,w,h,'CenterTop',Alignment.CenterTop); + DrawText(x,y,w,h,'Center'); + DrawText(x,y,w,h,'CenterBottom',Alignment.CenterBottom); + DrawText(x,y,w,h,'RightTop',Alignment.RightTop); + DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); + DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); + // + TextOut(150,100,'PointRightBottom',Alignment.RightBottom); + TextOut(150,100,'PointRightTop',Alignment.RightTop); + TextOut(150,100,'PointLeftTop',Alignment.LeftTop); + TextOut(150,100,'PointLeftBottom',Alignment.LeftBottom); + FillCircle(150,100,5,Colors.Red); + TextOut(600,100,'PointCenterTop',Alignment.CenterTop); + TextOut(600,100,'PointCenterBottom',Alignment.CenterBottom); + FillCircle(600,100,5,Colors.Red); + TextOut(400,500,'PointLeftCenter',Alignment.LeftCenter); + TextOut(400,500,'PointRightCenter',Alignment.RightCenter); + FillCircle(400,500,5,Colors.Red); +end. diff --git a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas new file mode 100644 index 000000000..a39daf9f2 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas @@ -0,0 +1,34 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Font.Size := 20; + + var sc := 40; + SetMathematicCoords; + + var (x,y) := (-5,-2); + var (w,h) := (10,4); + DrawRectangle(x,y,w,h); + DrawText(x,y,w,h,'LeftTop',Alignment.LeftTop); + DrawText(x,y,w,h,'LeftCenter',Alignment.LeftCenter); + DrawText(x,y,w,h,'LeftBottom',Alignment.LeftBottom); + DrawText(x,y,w,h,'CenterTop',Alignment.CenterTop); + DrawText(x,y,w,h,'Center'); + DrawText(x,y,w,h,'CenterBottom',Alignment.CenterBottom); + DrawText(x,y,w,h,'RightTop',Alignment.RightTop); + DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); + DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); + // + TextOut(-5,5,'PointRightBottom',Alignment.RightBottom); + TextOut(-5,5,'PointRightTop',Alignment.RightTop); + TextOut(-5,5,'PointLeftTop',Alignment.LeftTop); + TextOut(-5,5,'PointLeftBottom',Alignment.LeftBottom); + FillCircle(-5,5,0.1,Colors.Red); + TextOut(5,5,'PointCenterTop',Alignment.CenterTop); + TextOut(5,5,'PointCenterBottom',Alignment.CenterBottom); + FillCircle(5,5,0.1,Colors.Red); + TextOut(5,-5,'PointLeftCenter',Alignment.LeftCenter); + TextOut(5,-5,'PointRightCenter',Alignment.RightCenter); + FillCircle(5,-5,0.1,Colors.Red); +end. diff --git a/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas b/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas new file mode 100644 index 000000000..d77b27529 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas @@ -0,0 +1,20 @@ +uses GraphWPF; + +procedure (x0,y0,r: real; n: integer); +begin + var a := Pi / 2; + MoveTo(x0 + r * Cos(a), y0 - r * Sin(a)); + loop n do + begin + a += 2 * Pi / n; + //FillCircle(x0 + r * Cos(a), y0 - r * Sin(a),3,Colors.Black); + LineTo(x0 + r * Cos(a), y0 - r * Sin(a)); + end; +end; + +begin + var (x0,y0) := (400.0,300.0); + var r := 30.0; + for var n := 3 to 11 do + (x0,y0,r+(n-3)*30,n) +end. diff --git a/InstallerSamples/Graphics/GraphWPF/Светофор.pas b/InstallerSamples/Graphics/GraphWPF/Светофор.pas new file mode 100644 index 000000000..6dceb3ac2 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/Светофор.pas @@ -0,0 +1,19 @@ +uses GraphWPF; + +procedure (x,y,r: real); +begin + Rectangle(x,y,4*r,10*r,Colors.LightGray); + x += 2*r; + y += 2*r; + var dy := 3*r; + + Circle(x,y,r,Colors.Red); + Circle(x,y + dy,r,Colors.Yellow); + Circle(x,y + 2*dy,r,Colors.Green); +end; + +begin + Pen.Width := 2; + Window.Title := ''; + (150,40,50); +end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/Система координат.pas b/InstallerSamples/Graphics/GraphWPF/Система координат.pas new file mode 100644 index 000000000..91cf94b45 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/Система координат.pas @@ -0,0 +1,18 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Font.Size := 20; + + // SetMathematicCoords; // + // SetMathematicCoords(-10,10); // + SetMathematicCoords(-10,10,-9.2); + DrawGrid; + + Print(' :',XMin,XMax,YMin,YMax); + + Polygon(Arr((-3,2),(2,1),(-2,-4)),ARGB(100,255,228,196)); + TextOut(-3,2,'A(-3,2)',Alignment.RightBottom); + TextOut(2,1,'B(2,1)',Alignment.LeftBottom); + TextOut(-2,-4,'C(-2,-4)',Alignment.CenterTop); +end. diff --git a/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas b/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas new file mode 100644 index 000000000..26ec5e100 --- /dev/null +++ b/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas @@ -0,0 +1,16 @@ +uses GraphWPF; + +begin + Window.Title := ' '; + Font.Size := 16; + var n := 9; + var w := 40; + var (x0,y0) := (50,50); + for var i:=0 to n-1 do + for var j:=0 to n-1 do + begin + var (xx,yy) := (x0+i*w,y0+j*w); + Rectangle(xx,yy,w,w); + DrawText(xx,yy,w,w,(i+1)*(j+1)); + end; +end. diff --git a/bin/AvalonDock.dll b/Libraries/AvalonDock.dll similarity index 100% rename from bin/AvalonDock.dll rename to Libraries/AvalonDock.dll diff --git a/bin/Debugger.Core.dll b/Libraries/Debugger.Core.dll similarity index 100% rename from bin/Debugger.Core.dll rename to Libraries/Debugger.Core.dll diff --git a/bin/ICSharpCode.AvalonEdit.dll b/Libraries/ICSharpCode.AvalonEdit.dll similarity index 100% rename from bin/ICSharpCode.AvalonEdit.dll rename to Libraries/ICSharpCode.AvalonEdit.dll diff --git a/bin/ICSharpCode.NRefactory.dll b/Libraries/ICSharpCode.NRefactory.dll similarity index 100% rename from bin/ICSharpCode.NRefactory.dll rename to Libraries/ICSharpCode.NRefactory.dll diff --git a/bin/ICSharpCode.SharpZipLib.dll b/Libraries/ICSharpCode.SharpZipLib.dll similarity index 100% rename from bin/ICSharpCode.SharpZipLib.dll rename to Libraries/ICSharpCode.SharpZipLib.dll diff --git a/bin/ICSharpCode.TextEditor.dll b/Libraries/ICSharpCode.TextEditor.dll similarity index 100% rename from bin/ICSharpCode.TextEditor.dll rename to Libraries/ICSharpCode.TextEditor.dll diff --git a/bin/Microsoft.Dynamic.dll b/Libraries/Microsoft.Dynamic.dll similarity index 100% rename from bin/Microsoft.Dynamic.dll rename to Libraries/Microsoft.Dynamic.dll diff --git a/bin/Microsoft.Scripting.dll b/Libraries/Microsoft.Scripting.dll similarity index 100% rename from bin/Microsoft.Scripting.dll rename to Libraries/Microsoft.Scripting.dll diff --git a/bin/Mono.Cecil.dll b/Libraries/Mono.Cecil.dll similarity index 100% rename from bin/Mono.Cecil.dll rename to Libraries/Mono.Cecil.dll diff --git a/bin/Mono.Debugger.Soft.dll b/Libraries/Mono.Debugger.Soft.dll similarity index 100% rename from bin/Mono.Debugger.Soft.dll rename to Libraries/Mono.Debugger.Soft.dll diff --git a/bin/Mono.Debugging.Soft.dll b/Libraries/Mono.Debugging.Soft.dll similarity index 100% rename from bin/Mono.Debugging.Soft.dll rename to Libraries/Mono.Debugging.Soft.dll diff --git a/bin/Mono.Debugging.dll b/Libraries/Mono.Debugging.dll similarity index 100% rename from bin/Mono.Debugging.dll rename to Libraries/Mono.Debugging.dll diff --git a/bin/PascalABCAspects.dll b/Libraries/PascalABCAspects.dll similarity index 100% rename from bin/PascalABCAspects.dll rename to Libraries/PascalABCAspects.dll diff --git a/bin/SharpDisasm.dll b/Libraries/SharpDisasm.dll similarity index 100% rename from bin/SharpDisasm.dll rename to Libraries/SharpDisasm.dll diff --git a/bin/ShiftReduceParser.dll b/Libraries/ShiftReduceParser.dll similarity index 100% rename from bin/ShiftReduceParser.dll rename to Libraries/ShiftReduceParser.dll diff --git a/bin/WeifenLuo.WinFormsUI.Docking.dll b/Libraries/WeifenLuo.WinFormsUI.Docking.dll similarity index 100% rename from bin/WeifenLuo.WinFormsUI.Docking.dll rename to Libraries/WeifenLuo.WinFormsUI.Docking.dll diff --git a/Localization/DefaultLang.resources b/Localization/DefaultLang.resources index 48027b085..9d5a83811 100644 Binary files a/Localization/DefaultLang.resources and b/Localization/DefaultLang.resources differ diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index a5e635c95..1772faf0e 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -193,14 +193,16 @@ namespace PascalABCCompiler.NETGenerator return true; } - public void EnterSafeBlock() + public bool EnterSafeBlock() { + bool tmp = safe_block; safe_block = true; + return tmp; } - public void LeaveSafeBlock() + public void LeaveSafeBlock(bool value) { - safe_block = false; + safe_block = value; } protected void MarkSequencePoint(SemanticTree.ILocation Location) @@ -1258,7 +1260,7 @@ namespace PascalABCCompiler.NETGenerator private void AddTypeWithoutConvert(ICommonTypeNode t) { if (helper.GetTypeReference(t) != null) return; - TypeBuilder tb = mb.DefineType(cur_unit + "." + t.name, ConvertAttributes(t), null, new Type[0]); + TypeBuilder tb = mb.DefineType(BuildTypeName(t.name), ConvertAttributes(t), null, new Type[0]); helper.AddType(t, tb); //(ssyy) обрабатываем generics if (t.is_generic_type_definition) @@ -1862,6 +1864,13 @@ namespace PascalABCCompiler.NETGenerator } } + private string BuildTypeName(string type_name) + { + if (type_name.IndexOf(".") == -1) + return cur_unit + "." + type_name; + return type_name; + } + //Перевод заголовка типа private void ConvertTypeHeader(ICommonTypeNode value) { @@ -1924,7 +1933,7 @@ namespace PascalABCCompiler.NETGenerator ta = TypeAttributes.Public; if (value.type_access_level == type_access_level.tal_internal) ta = TypeAttributes.NotPublic; - EnumBuilder emb = mb.DefineEnum(cur_unit + "." + value.name, ta, TypeFactory.Int32Type); + EnumBuilder emb = mb.DefineEnum(BuildTypeName(value.name), ta, TypeFactory.Int32Type); //int num = 0; foreach (IClassConstantDefinitionNode ccfn in value.constants) { @@ -1938,7 +1947,7 @@ namespace PascalABCCompiler.NETGenerator { if (not_exist) { - tb = mb.DefineType(cur_unit + "." + value.name, ta, null, interfaces); + tb = mb.DefineType(BuildTypeName(value.name), ta, null, interfaces); } else { @@ -2351,7 +2360,7 @@ namespace PascalABCCompiler.NETGenerator funcs.Add(func); //здесь наверное дублирование MethodBuilder tmp = cur_meth; cur_meth = methb; - ConvertCommonFunctionConstantDefinitions(func.constants); + //если функция не содержит вложенных процедур, то //переводим переменные как локальные if (func.functions_nodes.Length > 0) @@ -2413,6 +2422,7 @@ namespace PascalABCCompiler.NETGenerator il = cur_meth.GetILGenerator(); smi.Push(mi); funcs.Add(func); + ConvertCommonFunctionConstantDefinitions(func.constants); if (func.functions_nodes.Length == 0) ConvertLocalVariables(func.var_definition_nodes); @@ -5326,7 +5336,10 @@ namespace PascalABCCompiler.NETGenerator { if (save_debug_info) { - MarkSequencePoint(value.LeftLogicalBracketLocation); + if (gen_left_brackets) + MarkSequencePoint(value.LeftLogicalBracketLocation); + else + il.MarkSequencePoint(doc, 0xFeeFee, 0xFeeFee, 0xFeeFee, 0xFeeFee); //il.MarkSequencePoint(doc,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF); il.Emit(OpCodes.Nop); } @@ -5368,14 +5381,16 @@ namespace PascalABCCompiler.NETGenerator public override void visit(SemanticTree.IStatementsListNode value) { - //TODO: переделать. придумать как. + IStatementNode[] statements = value.statements; if (save_debug_info) { - MarkSequencePoint(value.LeftLogicalBracketLocation); - //il.MarkSequencePoint(doc,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF); + if (gen_left_brackets || value.LeftLogicalBracketLocation == null) + MarkSequencePoint(value.LeftLogicalBracketLocation); + else + il.MarkSequencePoint(doc, 0xFeeFee, 0xFeeFee, 0xFeeFee, 0xFeeFee); il.Emit(OpCodes.Nop); } - IStatementNode[] statements = value.statements; + ILocalBlockVariableNode[] localVariables = value.LocalVariables; for (int i = 0; i < localVariables.Length; i++) { @@ -5482,11 +5497,9 @@ namespace PascalABCCompiler.NETGenerator } private bool gen_right_brackets = true; + private bool gen_left_brackets = true; public override void visit(SemanticTree.IForNode value) { - //if (save_debug_info) - // MarkSequencePoint(value.Location); - Label l1 = il.DefineLabel(); Label l2 = il.DefineLabel(); Label lcont = il.DefineLabel(); @@ -5507,18 +5520,14 @@ namespace PascalABCCompiler.NETGenerator labels.Push(lbreak); clabels.Push(lcont); bool tmp_rb = gen_right_brackets; + bool tmp_lb = gen_left_brackets; gen_right_brackets = false; + gen_left_brackets = false; ConvertStatement(value.body); gen_right_brackets = tmp_rb; - + gen_left_brackets = tmp_lb; il.MarkLabel(lcont); - - //tmp = save_debug_info; - //save_debug_info = false; - //if (save_debug_info) MarkForCicles(value.Location, value.increment_statement.Location); tmp = save_debug_info; - //if (save_debug_info) MarkSequencePoint(il, value.initialization_statement.Location.begin_line_num, 0, value.initialization_statement.Location.begin_line_num,20); - //save_debug_info = false; if (value.init_while_expr == null) { @@ -5527,7 +5536,6 @@ namespace PascalABCCompiler.NETGenerator ConvertStatement(value.increment_statement); save_debug_info = tmp; } - //save_debug_info = tmp; il.MarkLabel(l1); MarkSequencePoint(il, value.increment_statement.Location); value.while_expr.visit(this); @@ -5545,10 +5553,7 @@ namespace PascalABCCompiler.NETGenerator il.Emit(OpCodes.Br, l2); il.MarkLabel(l3); } - //if (value.IsBoolCycle) - //ConvertStatement(value.increment_statement); il.MarkLabel(lbreak); - //il.Emit(OpCodes.Pop); labels.Pop(); clabels.Pop(); } @@ -5586,7 +5591,10 @@ namespace PascalABCCompiler.NETGenerator il.Emit(OpCodes.Brfalse, FalseLabel); labels.Push(FalseLabel);//break clabels.Push(TrueLabel);//continue + bool tmp_lb = gen_left_brackets; + gen_left_brackets = false; ConvertStatement(value.body); + gen_left_brackets = tmp_lb; il.Emit(OpCodes.Br, TrueLabel); il.MarkLabel(FalseLabel); clabels.Pop(); @@ -5596,9 +5604,9 @@ namespace PascalABCCompiler.NETGenerator public override void visit(SemanticTree.ITryBlockNode value) { Label exBl = il.BeginExceptionBlock(); - EnterSafeBlock(); + var safe_block = EnterSafeBlock(); ConvertStatement(value.TryStatements); - LeaveSafeBlock(); + LeaveSafeBlock(safe_block); if (value.ExceptionFilters.Length != 0) { foreach (SemanticTree.IExceptionFilterBlockNode iefbn in value.ExceptionFilters) @@ -5622,17 +5630,17 @@ namespace PascalABCCompiler.NETGenerator { il.Emit(OpCodes.Pop); } - EnterSafeBlock(); + safe_block = EnterSafeBlock(); ConvertStatement(iefbn.ExceptionHandler); - LeaveSafeBlock(); + LeaveSafeBlock(safe_block); } } if (value.FinallyStatements != null) { il.BeginFinallyBlock(); - EnterSafeBlock(); + safe_block = EnterSafeBlock(); ConvertStatement(value.FinallyStatements); - LeaveSafeBlock(); + LeaveSafeBlock(safe_block); } il.EndExceptionBlock(); } @@ -5647,7 +5655,10 @@ namespace PascalABCCompiler.NETGenerator public override void visit(IGotoStatementNode value) { Label lab = helper.GetLabel(value.label, il); - il.Emit(OpCodes.Br, lab); + if (safe_block) + il.Emit(OpCodes.Leave, lab); + else + il.Emit(OpCodes.Br, lab); } private Stack