From 5c87179327eacb2f291049423816dbe14ea92ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Thu, 12 Jul 2018 21:41:05 +0200 Subject: [PATCH] fix #969 --- CodeCompletion/DomSyntaxTreeVisitor.cs | 48 ++++++++++++++++++++++++-- CodeCompletion/SymTable.cs | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index 09e3846b0..61cdf85f4 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -1962,7 +1962,7 @@ namespace CodeCompletion } 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 != null? cnst_val.prim_val:_simple_const_definition.const_value.ToString(), cur_scope); + 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 != null? cnst_val.prim_val: get_constant_as_string(_simple_const_definition.const_value), cur_scope); es.is_static = true; cur_scope.AddName(_simple_const_definition.const_name.name, es); es.loc = get_location(_simple_const_definition.const_name); @@ -1974,6 +1974,50 @@ namespace CodeCompletion cnst_val.prim_val = null; } + private string get_constant_as_string(expression e) + { + if (e is pascal_set_constant || e is PascalABCCompiler.SyntaxTree.array_const) + { + List elems = new List(); + pascal_set_constant set = e as pascal_set_constant; + PascalABCCompiler.SyntaxTree.array_const arr = e as PascalABCCompiler.SyntaxTree.array_const; + expression_list values = null; + if (set != null) + values = set.values; + else + values = arr.elements; + if (values == null) + return "[]"; + if (values.Count > 10)//dlinnye konstanty ne pokazyvaem + return null;//prosto const c: + foreach (expression elem in values.expressions) + { + if (elem is ident || elem is int32_const || elem is char_const || elem is string_const) + elems.Add(get_constant_as_string(elem));//tolko primitivy + else + return null; + } + //govnostudia ne daet podkluchit Core.dll i ne mogu vyzvat Join. urody + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < elems.Count; i++) + { + sb.Append(elems[i]); + if (i < elems.Count - 1) + sb.Append(", "); + } + if (set != null) + return "[" + sb.ToString() + "]"; + else + return "(" + sb.ToString() + ")"; + } + else if (e is char_const) + return "'" + (e as char_const).cconst + "'"; + else if (e.ToString().Contains("PascalABCCompiler.SyntaxTree")) + return null; + else + return e.ToString(); + } + public override void visit(typed_const_definition _typed_const_definition) { //throw new Exception("The method or operation is not implemented."); @@ -1991,7 +2035,7 @@ namespace CodeCompletion File.AppendAllText("log.txt", e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine); #endif } - ElementScope es = new ElementScope(new SymInfo(_typed_const_definition.const_name.name, SymbolKind.Constant, _typed_const_definition.const_name.name), cnst_type, cnst_val.prim_val != null?cnst_val.prim_val: _typed_const_definition.const_value.ToString(), cur_scope); + ElementScope es = new ElementScope(new SymInfo(_typed_const_definition.const_name.name, SymbolKind.Constant, _typed_const_definition.const_name.name), cnst_type, cnst_val.prim_val != null?cnst_val.prim_val: get_constant_as_string(_typed_const_definition.const_value), cur_scope); cur_scope.AddName(_typed_const_definition.const_name.name, es); es.loc = get_location(_typed_const_definition); es.is_static = true; diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index 506ccf567..f69f4770d 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -3441,6 +3441,8 @@ namespace CodeCompletion public override bool IsConvertable(TypeScope ts) { + if (ts is NullTypeScope) + return false; return ts.IsConvertable(this); }