Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Error.WriteLine("Use -g option to start GUI, or --help to show help for command line.");

            Parser.Default.ParseArguments <CommandLineOptions>(args)
            .WithParsed <CommandLineOptions>(o =>
            {
                DebugClass.Init();

                if (o.Verbose || o.GUI)
                {
                    DebugClass.Enabled = true;
                }

                if (o.Compile || o.GUI)
                {
                    TranslatorForPattern.IntializeTranslatorForPattern();
                }

                if (o.Compile)
                {
                    //DebugClass.LogStandard("")
                    DebugClass.LogStandard("Compile");
                    if (o.Files == null)
                    {
                        DebugClass.LogStandard("No files specified!");
                    }
                    else
                    {
                        Compile(o.Files);
                    }
                }

                if (o.GUI)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    var frm = new frmCompiler();
                    Application.Run(frm);
                    frm.Dispose();
                }
            });
        }
Ejemplo n.º 2
0
        public ExpressionSyntax GetExpression(ParseTree tree)
        {
            if (tree == null)
            {
                throw new ArgumentNullException(nameof(tree));
            }

            var asg = this.translator.Program.getASGElementRegistry().getASGElement(tree);

            if (TranslatorForPattern.CanTranslate(translator, tree))
            {
                return(TranslatorForPattern.TranslateExpression(this.translator, tree));
            }

            var goodChildren = GetGoodChildren(tree);

            if (goodChildren.Count == 1)
            {
                DebugClass.LogError("FORWARDED: " + VbToCsharpPattern.LookupNodeType(tree) + ": " + tree.getText());
                return(goodChildren[0]);
            }

            // TODO: optimize if too slow
            var methods = this.GetType().GetMethods();

            foreach (var method in methods)
            {
                if (method.Name.Equals("GetExpression", StringComparison.InvariantCulture))
                {
                    var methodParameters = method.GetParameters();

                    if (methodParameters.Length > 0 && asg != null && methodParameters[0].ParameterType == asg.GetType())
                    {
                        DebugClass.LogError("OBSOLETE: Invoking specific GetExpression on: " + tree.getText());
                        //statements.Add(SyntaxFactory.EmptyStatement().WithLeadingTrivia(SyntaxFactory.Comment("// Invoking GetExpression: " + asg.GetType().Name + ":" + asg.getCtx().depth())));
                        return((ExpressionSyntax)method.Invoke(this, new object[] { asg }));
                    }
                }
            }

            /*else if (tree is VisualBasic6Parser.TypeHintContext)
             * {
             *  return SyntaxFactory.CastExpression(
             *      SyntaxFactory.Token(SyntaxKind.OpenParenToken),
             *      SyntaxFactory.ParseTypeName("string"),
             *      SyntaxFactory.Token(SyntaxKind.CloseParenToken),
             *  );*/

            if (tree is TerminalNodeImpl)
            {
                return(null);
            }
            else if (tree is VisualBasic6Parser.CertainIdentifierContext ||
                     tree is VisualBasic6Parser.AmbiguousIdentifierContext ||
                     tree is VisualBasic6Parser.AmbiguousKeywordContext)
            {
                var name = tree.getText().Trim();
                if (!name.All(c => char.IsLetterOrDigit(c) || "_$".Contains(c)))
                {
                    throw new InvalidOperationException("Identifier was not alphanumeric: " + name);
                }
                return(SyntaxFactory.IdentifierName(name));
            }
            else if (tree is VisualBasic6Parser.ArgsCallContext)
            {
                return(GetFirstGoodChild(nameof(ConstantCallImpl), tree));
            }
            else if (tree is VisualBasic6Parser.BaseTypeContext btc)
            {
                return(HandleBaseTypeContext(btc));
            }
            else if (tree is VisualBasic6Parser.TypeHintContext)
            {
                // Ignore type hint context
                DebugClass.LogError("IGNORING TYPE HINT CONTEXT");
                return(null);
            }

            var explanation = "// " + VbToCsharpPattern.LookupNodeType(tree) + " not in [" + TranslatorForPattern.DocPatterns() + "]" + Translator.NewLine;

            DebugClass.LogError(nameof(GetExpression) + ": " + VbToCsharpPattern.LookupNodeType(tree) + ": " + tree.getText());
            DebugClass.LogError(explanation);
            if (asg != null)
            {
                DebugClass.LogError(nameof(GetExpression) + ": " + asg.GetType().Name);
            }
            // TODO: Reenable.
            throw new InvalidOperationException("Expression returned null");

            //return null;
        }