/// <summary>
 /// On all blocknodes, all types are added. No other scope information exists once this finishes
 /// </summary>
 public static AstData CollectTypes(AstData data, SideeffectHelper helper)
 {
     return(new AstData(
                data.TokenStream,
                data.Filename,
                new FirstScopePassVisitor().Visit(data.Tree.RootNode).OwningTree));
 }
 /// <summary>
 /// Adds everything else to scope (Variables, methods)
 /// </summary>
 internal static AstData SecondScopePass(AstData withoutScope, SideeffectHelper notused)
 {
     return(new AstData(
                withoutScope.TokenStream,
                withoutScope.Filename,
                new AddScopeVisitor().Visit(withoutScope.Tree.RootNode).OwningTree));
 }
        /// <summary>
        /// Changes parameters to ref where possible to avoid deep cloning.
        /// </summary>
        internal static AstData RefWherePossible(AstData astData, SideeffectHelper helper)
        {
            var visitor = new RefParametersVisitor();
            var newTree = visitor.Visit(astData.Tree.RootNode).OwningTree;

            return(new AstData(astData.TokenStream, astData.Filename, newTree));
        }
 /// <summary>
 /// Adds type to all typenodes. Outputs error messages if types are not found. No regard for private types atm
 /// </summary>
 internal static AstData PutTypes(AstData arg, SideeffectHelper helper)
 {
     return(new AstData(
                arg.TokenStream,
                arg.Filename,
                new PutTypeVisitor(helper.CompilationMessages, arg.TokenStream, arg.Filename).Visit(arg.Tree.RootNode)
                .OwningTree));
 }
        internal static AstData FoldConstants(AstData astData, SideeffectHelper helper)
        {
            var constantFoldingVisitor = new ConstantFoldingVisitor();
            var operandSortingVisitor  = new OperandSortingVisitor();

            var newTree = astData.Tree.RootNode;

            do
            {
                constantFoldingVisitor.OptimizationsWereMade = false;
                newTree = operandSortingVisitor.Visit(newTree);
                newTree = constantFoldingVisitor.Visit(newTree);
            } while (constantFoldingVisitor.OptimizationsWereMade);

            return(new AstData(astData.TokenStream, astData.Filename, newTree.OwningTree));
        }
            public AstData AddExport(AstData arg, SideeffectHelper helper)
            {
                var tu = ((TranslationUnitNode)arg.Tree.RootNode);

                try
                {
                    return(new AstData(
                               arg.TokenStream,
                               arg.Filename,
                               tu
                               .WithImportedNamespaces(
                                   Namespace.Merge(tu.Imports.Select(TryGetNamespace).ToArray())
                                   )
                               .OwningTree
                               ));
                }
                catch (NamespaceNotFoundException nsnfe)
                {
                    throw helper.FailWith(CompilationMessage.Create(arg.TokenStream, nsnfe.FaultyNode.Interval,
                                                                    MessageCode.NamespaceNotFound, arg.Filename));
                }
            }
 /// <summary>
 /// Checks that variables are only used after they are declared
 /// </summary>
 internal static AstData DeclerationOrderCheck(AstData arg, SideeffectHelper helper)
 {
     new CheckDeclerationOrderVisitor(helper.CompilationMessages, arg).Visit(arg.Tree.RootNode);
     return(arg);
 }
 /// <summary>
 /// Finishes parsing types
 /// </summary>
 public static AstData FinishTypes(AstData arg1, SideeffectHelper arg2)
 {
     new FinishTypesVisitor().Visit(arg1.Tree.RootNode);
     return(arg1);
 }
        /// <summary>
        /// Check that expressions are used on correct types.
        /// </summary>
        internal static AstData TypeCheck(AstData tree, SideeffectHelper notused)
        {
            var newTree = new TypeVisitor().Visit(tree.Tree.RootNode).OwningTree;

            return(new AstData(tree.TokenStream, tree.Filename, newTree));
        }