public void Visit(InitializerNode node)
 {
     // REVIEW: do we ever get here?
     if (node != null)
     {
         DoesRequire = true;
     }
 }
Beispiel #2
0
        /// <summary>
        /// File-in and process the actions contained in the node.
        /// </summary>
        /// <param name="processor">Interchange format processor responsible for the processing context.</param>
        /// <param name="parseErrorSink">Error sink for reporting parse errors.</param>
        /// <param name="sourceCodeService">Source code service that can convert tokens to source code span and reports issues.</param>
        /// <returns>Return an interchange unit node for annotation, usually just self.</returns>
        public override InterchangeUnitNode FileIn(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }
            if (parseErrorSink == null)
            {
                throw new ArgumentNullException("parseErrorSink");
            }
            if (sourceCodeService == null)
            {
                throw new ArgumentNullException("sourceCodeService");
            }
            // ALL instance vars must be set. If one is missing, then source code bug, and
            //   InterchangeFormatParser.ParsePoolValueInitialization() should have reported the error.
            if ((this.PoolName == null) || (this.PoolVariableName == null))
            {
                return(this);
            }

            // <poolValueInitialization> ::= <poolName> ’initializerFor:’ <poolVariableNameString>
            //      <elementSeparator> <variableInitializer> <elementSeparator>
            // <variableInitializer> ::= <initializer definition>

            ISourceCodeReferenceService methodSourceCodeService;
            InitializerNode             initializer = processor.ParseInitializer(out methodSourceCodeService);

            if (initializer == null)
            {
                return(this); // Processor/Parser should have reported errors
            }
            if (!initializer.Accept(IronSmalltalk.Compiler.Visiting.ParseTreeValidatingVisitor.Current))
            {
                // We expect the parser to have reported the errors. Just in case, we do it once more to the installer.
                // Bad practice here is to use the 'processor.SourcePosition', but we don't have anything better :-/
                if (processor.ErrorSink != null)
                {
                    processor.ErrorSink.AddInterchangeError(processor.SourcePosition, processor.SourcePosition, "Invalid initializer source code.");
                }
                return(this);
            }

            RuntimePoolVariableInitializerFactory factory = new RuntimePoolVariableInitializerFactory(initializer, methodSourceCodeService, this.PoolName.Value, this.PoolVariableName.Value);

            PoolVariableInitializer definition = new PoolVariableInitializer(
                processor.CreateSourceReference(this.PoolName.Value, this.PoolName, sourceCodeService),
                processor.CreateSourceReference(this.PoolVariableName.Value, this.PoolVariableName, sourceCodeService),
                sourceCodeService,
                methodSourceCodeService,
                factory);

            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInPoolVariableInitializer(definition);

            return(this);
        }
 public RuntimePoolItemInitializer(InitializerNode parseTree, IDebugInfoService debugInfoService, PoolVariableOrConstantBinding binding, string poolName)
     : base(InitializerType.PoolVariableInitializer, binding, parseTree, debugInfoService)
 {
     if (String.IsNullOrWhiteSpace(poolName))
     {
         throw new ArgumentNullException("poolName");
     }
     this.PoolName = poolName;
 }
Beispiel #4
0
        /// <summary>
        /// Visits the Initializer (Expression) node.
        /// </summary>
        /// <param name="node">The node to visit.</param>
        public virtual TResult VisitInitializer(InitializerNode node)
        {
            foreach (TemporaryVariableNode tmp in node.Temporaries)
            {
                tmp.Accept(this);
            }

            if (node.Statements != null)
            {
                node.Statements.Accept(this);
            }

            return(default(TResult));            // The default naive implementation
        }
        public virtual void Visit(InitializerNode node)
        {
            if (node != null)
            {
                if (node.Binding != null)
                {
                    node.Binding.Accept(this);
                }

                if (node.Initializer != null)
                {
                    node.Initializer.Accept(this);
                }
            }
        }
        protected override List <Expression> GenerateExpressions(InitializerNode node, out StatementVisitor visitor)
        {
            List <Expression> expressions = base.GenerateExpressions(node, out visitor);

            if (expressions.Count == 0)
            {
                NameBinding binding = this.Context.GetBinding(SemanticConstants.Self);
                if (binding.IsErrorBinding)
                {
                    binding = this.Context.GetBinding(SemanticConstants.Nil);
                }
                expressions.Add(binding.GenerateReadExpression(this));
            }

            return(expressions);
        }
        /// <summary>
        /// File-in and process the actions contained in the node.
        /// </summary>
        /// <param name="processor">Interchange format processor responsible for the processing context.</param>
        /// <param name="parseErrorSink">Error sink for reporting parse errors.</param>
        /// <param name="sourceCodeService">Source code service that can convert tokens to source code span and reports issues.</param>
        /// <returns>Return an interchange unit node for annotation, usually just self.</returns>
        public override InterchangeUnitNode FileIn(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }
            if (parseErrorSink == null)
            {
                throw new ArgumentNullException("parseErrorSink");
            }
            if (sourceCodeService == null)
            {
                throw new ArgumentNullException("sourceCodeService");
            }

            // <programInitialization> ::= ’Global’ ’initializer’ <elementSeparator>
            //      <programInitializer> <elementSeparator>
            //  <programInitializer> ::= <initializer definition>

            ISourceCodeReferenceService methodSourceCodeService;
            InitializerNode             initializer = processor.ParseInitializer(out methodSourceCodeService);

            if (initializer == null)
            {
                return(this); // Processor/Parser should have reported errors
            }
            if (!initializer.Accept(IronSmalltalk.Compiler.Visiting.ParseTreeValidatingVisitor.Current))
            {
                // We expect the parser to have reported the errors. Just in case, we do it once more to the installer.
                // Bad practice here is to use the 'processor.SourcePosition', but we don't have anything better :-/
                if (processor.ErrorSink != null)
                {
                    processor.ErrorSink.AddInterchangeError(processor.SourcePosition, processor.SourcePosition, "Invalid initializer source code.");
                }
                return(this);
            }

            RuntimeProgramInitializerFactory factory = new RuntimeProgramInitializerFactory(initializer, methodSourceCodeService);

            ProgramInitializer definition = new ProgramInitializer(sourceCodeService, methodSourceCodeService, factory);

            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInProgramInitializer(definition);

            return(this);
        }
Beispiel #8
0
        /// <summary>
        /// Parses the source code within a specified compiler context.
        /// The source unit to parse is held on by the context.
        /// </summary>
        /// <returns><b>null</b> on failure.</returns>
        /// <remarks>Could also set the code properties and line/file mappings on the source unit.</remarks>
        public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
        {
            if (sourceUnit == null)
            {
                throw new ArgumentNullException("sourceUnit");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (errorSink == null)
            {
                throw new ArgumentNullException("errorSink");
            }
            if (sourceUnit.LanguageContext != this)
            {
                throw new ArgumentException("Language context mismatch");
            }

            // Ensure that sources are installed into the image.
            this.EnsureInitialized();


            // THE CODE BELOW NEEDS CLEAN-UP !!!
            // 1. Parse the code to an AST
            Parser parser = new Parser();

            parser.ErrorSink = new ErrorSinkWrapper(sourceUnit, errorSink);
            InitializerNode node = parser.ParseInitializer(sourceUnit.GetReader());

            if ((node == null) || !node.Accept(ParseTreeValidatingVisitor.Current))
            {
                return(null); // Failed to compile the code, return null
            }
            // 2. Compile the AST to RuntimeProgramInitializer
            RuntimeProgramInitializer code = new RuntimeProgramInitializer(node, null);

            if (code.Validate(this.SmalltalkEnvironment.Runtime.GlobalScope, new ErrorSinkWrapper(sourceUnit, errorSink)))
            {
                return(null); // Failed to compile the code, return null
            }
            // 3. Create a script-source that wraps the Lambda Expression and compiles it to a delegate
            return(new SmalltalkScriptCode(code, this.SmalltalkEnvironment.Runtime, sourceUnit));
        }
        private Expression <Func <object, ExecutionContext, object> > JitExpression()
        {
            if (this.Environment == null)
            {
                MessageBox.Show("First, create the environment.");
                return(null);
            }

            Properties.Settings.Default.LastWorkspaceInstallSource = this.textInstall.Text;
            Properties.Settings.Default.LastWorkspaceEvalSource    = this.textEvaluate.Text;
            Properties.Settings.Default.Save();

            this.textResultEvaluate.Text = null;

            string txt = this.textEvaluate.SelectedText;

            if (String.IsNullOrEmpty(txt))
            {
                txt = this.textEvaluate.Text;
            }
            StringReader reader = new StringReader(txt);

            ErrorSink errorSink = new ErrorSink(this.textResultEvaluate);
            Parser    parser    = new Parser();

            parser.ErrorSink = errorSink;
            InitializerNode node = parser.ParseInitializer(reader);

            if (errorSink.HadErrors)
            {
                return(null);
            }

            RuntimeProgramInitializer code = new RuntimeProgramInitializer(node, null);
            var compilationResult          = code.Compile(this.Environment.Runtime);

            if (compilationResult == null)
            {
                return(null);
            }
            return(compilationResult);
        }
Beispiel #10
0
        private void btnParseInitializer_Click(object sender, EventArgs e)
        {
            this.treeParseNodes.Nodes.Clear();
            this.listProperties.Items.Clear();

            string txt = this.txtSource.SelectedText;

            if (String.IsNullOrEmpty(txt))
            {
                txt = this.txtSource.Text;
            }
            StringReader reader = new StringReader(txt);

            parser           = new VseCompatibleParser();
            this.Errors      = new Dictionary <object, List <string> >();
            parser.ErrorSink = new ErrorSink(this);
            InitializerNode node = parser.ParseInitializer(reader);

            this.VisitNode(node, null, null);
        }
Beispiel #11
0
        /// <summary>
        /// Visits the Initializer (Expression) node.
        /// </summary>
        /// <param name="node">The node to visit.</param>
        public override bool VisitInitializer(InitializerNode node)
        {
            if ((node.LeftBar == null) ^ (node.RightBar == null))
            {
                return(false);
            }

            foreach (TemporaryVariableNode tmp in node.Temporaries)
            {
                if (!tmp.Accept(this))
                {
                    return(false);
                }
            }

            if ((node.Statements != null) && !node.Statements.Accept(this))
            {
                return(false);
            }

            return(true);
        }
Beispiel #12
0
        protected virtual InitializerNode ParseInitializer()
        {
            // PARSE: <initializer definition> ::= [<temporaries>] [<statements>]
            InitializerNode result = new InitializerNode();
            Token           token  = this.GetNextTokenxx(Preference.VerticalBar | Preference.NegativeSign);

            // PARSE: [<temporaries>]
            ParseTemporariesResult ptr = this.ParseTemporaries(result, token);

            // PARSE: <statements>
            token = this.GetNextTokenxx(Preference.NegativeSign);
            StatementNode statements = this.ParseStatement(result, token);

            // Should be done.
            token = this.GetNextTokenxx(Preference.Default);
            if (!(token is EofToken))
            {
                this.ReportParserError(result, SemanticErrors.UnexpectedCodeAfterInitializer, token);
            }

            result.SetContents(ptr.LeftBar, ptr.Temporaries, ptr.RightBar, statements);
            return(result);
        }
        public override Expression <Func <object, ExecutionContext, object> > VisitInitializer(InitializerNode node)
        {
            Expression body = this.InternalVisitFunction(node);

            return(Expression.Lambda <Func <object, ExecutionContext, object> >(body, this.InitializerName,
                                                                                new ParameterExpression[] { (ParameterExpression)this.Context.Self, (ParameterExpression)this.Context.ExecutionContextArgument }));
        }
 protected override void DefineArguments(InitializerNode node)
 {
     // Initializers have no arguments
 }
Beispiel #15
0
 public void Visit(InitializerNode node)
 {
     // invalid! ignore
     IsValid = false;
 }
 public RuntimeProgramInitializer(InitializerNode parseTree, IDebugInfoService debugInfoService)
     : base(InitializerType.ProgramInitializer, null, parseTree, debugInfoService)
 {
 }
Beispiel #17
0
 public void Visit(InitializerNode node)
 {
     // recurse the value, not the initializer
     node.IfNotNull(n => n.Binding.IfNotNull(v => v.Accept(this)));
 }
 public RuntimeGlobalInitializer(InitializerNode parseTree, IDebugInfoService debugInfoService, GlobalVariableOrConstantBinding binding)
     : base(InitializerType.GlobalInitializer, binding, parseTree, debugInfoService)
 {
 }
Beispiel #19
0
 public List <InitializerNode> makeInitializerList(List <InitializerNode> list, DesignationNode desinode, InitializerNode initnode)
 {
     return(null);
 }
 public RuntimeGlobalInitializer(InitializerNode parseTree, IDebugInfoService debugInfoService, ClassBinding binding)
     : base(InitializerType.ClassInitializer, binding, parseTree, debugInfoService)
 {
 }
 protected RuntimeCompiledInitializer(InitializerType type, IDiscreteBinding binding, InitializerNode parseTree, IDebugInfoService debugInfoService)
     : base(type, binding)
 {
     if (parseTree == null)
     {
         throw new ArgumentNullException();
     }
     this.ParseTree        = parseTree;
     this.DebugInfoService = debugInfoService;
 }
Beispiel #22
0
 public void Visit(InitializerNode node)
 {
     Debug.Fail("shouldn't get here");
 }
Beispiel #23
0
        public bool Evaluate()
        {
            string       txt    = this.Client.EvaluateSourceCode;
            StringReader reader = new StringReader(txt);

            ErrorSink errorSink = new ErrorSink(this.Client);
            Parser    parser    = new Parser();

            parser.ErrorSink = errorSink;
            InitializerNode node = parser.ParseInitializer(reader);

            if (errorSink.HadErrors)
            {
                return(false);
            }

            try
            {
                RuntimeProgramInitializer code = new RuntimeProgramInitializer(node, null);
                if (!code.Validate(this.Environment.Runtime.GlobalScope, errorSink))
                {
                    return(false);
                }
                this.LastResult = code.Execute(null, new ExecutionContext(this.Environment.Runtime));
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkDefinitionException ex)
            {
                if (this.Client != null)
                {
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                }
                return(false);
            }
            catch (IronSmalltalk.Runtime.Internal.SmalltalkRuntimeException ex)
            {
                if (this.Client != null)
                {
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                }
                return(false);
            }
            catch (Exception ex)
            {
                if (this.Client != null)
                {
                    this.Client.ReportError(ex.Message, SourceLocation.Invalid, SourceLocation.Invalid);
                }
                return(false);
            }
            this.PrintResult(this.LastResult);


            //dynamic rt = this.Environment.Runtime;
            //string x = rt.GetTestString();
            //dynamic x = this.LastResult;
            //dynamic y = x.PrintString();
            //y = x.PrintString;
            //int z = x.Hash();

            return(true);
        }
Beispiel #24
0
        //- declarations --------------------------------------------------------

        public void makeDeclarationNode(DeclSpecNode declarspecs, DeclaratorNode declarator, InitializerNode initializer)
        {
            VarDeclNode vardecl = new VarDeclNode();

            vardecl.varType = declarspecs.baseType;
            DeclaratorNode dnode = declarator;

            while (dnode != null)
            {
                if (dnode is IdentDeclaratorNode)
                {
                    vardecl.name = ((IdentDeclaratorNode)dnode).ident;
                }
                dnode = dnode.next;
            }
            vardecl.initializer = initializer;
            symbolTable.addSymbol(vardecl.name, vardecl);

            //add decl to either global or local decl list
            if (curFunc != null)
            {
                curFunc.locals.Add(vardecl);
            }
            else
            {
                curModule.globals.Add(vardecl);
            }

            if (initializer != null && curBlock != null)
            {
                DeclarInitStatementNode dstmt = new DeclarInitStatementNode(vardecl, initializer.initExpr);
                addStmtToBlock(dstmt);
                vardecl.initializer = null;
            }
        }
 public void Visit(InitializerNode node)
 {
     // not applicable; terminate
 }
Beispiel #26
0
        //- initializers ------------------------------------------------------

        public InitializerNode makeInitializerNode(ExprNode expr)
        {
            InitializerNode node = new InitializerNode(expr);

            return(node);
        }
Beispiel #27
0
 /// <summary>
 /// Visits the Initializer (Expression) node.
 /// </summary>
 /// <param name="node">The node to visit.</param>
 public virtual TResult VisitInitializer(InitializerNode node)
 {
     throw new NotImplementedException();
 }
        public Expression <Func <object, ExecutionContext, object> > CompileInitializer(InitializerNode parseTree, string initializerName)
        {
            if (parseTree == null)
            {
                throw new ArgumentNullException("parseTree");
            }

            ParameterExpression    self             = Expression.Parameter(typeof(object), "self");
            ParameterExpression    executionContext = Expression.Parameter(typeof(ExecutionContext), "executionContext");
            RootCompilationContext context          = new RootCompilationContext(this, this.GlobalScope, this.ReservedScope, self, executionContext, new ParameterExpression[0], null, initializerName);
            InitializerVisitor     visitor          = new InitializerVisitor(context, initializerName);
            Expression <Func <object, ExecutionContext, object> > code = parseTree.Accept(visitor);

            return(code);
        }