Example #1
0
        protected override object VisitVariableDeclaration(VariableDeclarationSyntax node)
        {
            LangType t = _ResolveLangType(node.Type);

#if ROSLYN
            //if (t == null || t.DotnetType == null)
            //    throw new Exception("Roslyn powinien tozwiązać ten typ");
#endif
            var vars = node.Variables.Select(Visit).OfType <VariableDeclarator>().ToArray();
            if ((object)t.DotnetType == null)
            {
                if (vars.Any())
                {
                    t = new LangType(vars[0].Value.ValueType);
                }
                // Console.ForegroundColor
                Console.WriteLine("Brak typu dla {0} => {1}", node.ToString(), t);
            }
            return(new VariableDeclaration(t, vars));
        }
Example #2
0
        private List <string> visitDecl(VariableDeclarationSyntax node)
        {
            var    type = node.Type.ToString() != "var" ? GetMappedType(node.Type) : String.Empty;
            var    list = new List <string>();
            string format;

            if (node.Variables.SeparatorCount == 0)
            {
                foreach (var identifier in node.Variables)
                {
                    var initializer     = identifier.Initializer != null ? (" " + identifier.Initializer) : String.Empty;
                    var typeDeclaration = !string.IsNullOrEmpty(type) ? ": " + type : String.Empty;
                    list.Add(string.Format("let {0}{1}{2}", identifier.Identifier.Value, typeDeclaration,
                                           initializer));
                }
            }
            else
            {
                //                if (node.ToString() == "int i = 0, imax = t.childCount")
                //                    nop();
                //                {
                //                    var prefix = "var ";
                //                    var identifier = node.Variables.Last();
                //                    var initializer = identifier.Initializer != null ? (" " + identifier.Initializer) : String.Empty;
                //                    var typeDeclaration = !string.IsNullOrEmpty(type) ? ": " + type : String.Empty;
                //
                //                    string padding = new string(' ', prefix.Length);
                //                    var separator = String.Concat(",", Environment.NewLine, GetIndentation(), padding);
                //                    var enumerable = node.Variables.Select(
                //                        v => v.Identifier.Value
                //                    ).ToList();
                //                    var lines = prefix + String.Join(separator,
                //                                    enumerable);
                //                    list.Add(string.Format("{0}{1}{2};", lines, typeDeclaration, initializer));
                //                }
                if (node.ToString() == "int i = 0, imax = t.childCount")
                {
                    nop();
                }
                {
                    var prefix = "let ";

                    List <string> vars = new List <string>();
                    for (int i = 0; i < node.Variables.Count; i++)
                    {
                        var identifier      = node.Variables[i];
                        var typeDeclaration = !string.IsNullOrEmpty(type) ? ": " + type : String.Empty;
                        var initializer     = identifier.Initializer != null
                            ? (" " + identifier.Initializer)
                            : String.Empty;
                        var item = string.Format("{0}{1}{2}", identifier.Identifier.Value, typeDeclaration,
                                                 initializer);
                        vars.Add(item);
                    }

                    var @join = string.Join(",", vars.ToArray());
                    list.Add(string.Format("{0}{1}", prefix, @join));
                }
            }

            return(list);
        }