/// <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;
            }

            ProgramInitializer definition = new ProgramInitializer(sourceCodeService, methodSourceCodeService, new AstIntermediateInitializerCode(initializer));
            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;
        }
        /// <summary>
        /// Parse identifier list. Identifier list have the syntax: identifierList ::= stringDelimiter identifier* stringDelimiter
        /// </summary>
        /// <param name="token">Token containing the string with the identifier list.</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>A collection of sub-tokens if successful or null if token string is illegal.</returns>
        protected internal virtual IEnumerable<SourceReference<string>> ParseIdentifierList(StringToken token, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (token == null)
                throw new ArgumentNullException("token");
            if (parseErrorSink == null)
                throw new ArgumentNullException("parseErrorSink");
            if (sourceCodeService == null)
                throw new ArgumentNullException("sourceCodeService");

            List<SourceReference<string>> result = new List<SourceReference<string>>();
            if (token.Value.Length == 0)
                return result;

            Scanner scanner = new Scanner(new StringReader(token.Value));
            Token t = scanner.GetToken();
            while (!(t is EofToken))
            {
                // Skip whitespaces (incl. comments).
                if (!(t is WhitespaceToken))
                {
                    // Offset the token to the position within the original token. +1 is due to the opening string ' quote.
                    t.SetTokenValues(
                        new SourceLocation(t.StartPosition.Position + token.StartPosition.Position + 1,
                            t.StartPosition.Line + token.StartPosition.Line,
                            t.StartPosition.Column + token.StartPosition.Column + 1),
                        new SourceLocation(t.StopPosition.Position + token.StartPosition.Position + 1,
                            t.StopPosition.Line + token.StartPosition.Line,
                            t.StopPosition.Column + token.StartPosition.Column + 1),
                        t.ScanError);

                    if (t is IdentifierToken)
                    {
                        // identifier  OK
                        result.Add(new SourceReference<string>(((IdentifierToken)t).Value, t.StartPosition, t.StopPosition, sourceCodeService));
                    }
                    else
                    {
                        // Non-identifier, report error
                        parseErrorSink.AddParserError(t.StartPosition, t.StopPosition, "Expected identifier", t);
                        return null; // Error condition
                    }
                }
                t = scanner.GetToken();
            }
            return result;
        }
        /// <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.ParseClassDefinition() should have reported the error.
            if ((this.ClassName == null) || (this.SuperclassName == null) || (this.IndexedInstanceVariables == null)
                || (this.InstanceVariableNames == null) || (this.ClassVariableNames == null) || (this.SharedPools == null)
                || (this.ClassInstanceVariableNames == null))
                    return this;

            SmalltalkClass.InstanceStateEnum? instanceState = this.GetInstanceState(processor, parseErrorSink, sourceCodeService);
            if (instanceState == null)
                return this;

            IEnumerable<SourceReference<string>> civn = this.GetClassInstanceVariableNames(processor, parseErrorSink, sourceCodeService);
            if (civn == null)
                return this; // ParseIdentifierList() reported the error
            IEnumerable<SourceReference<string>> ivn = this.GetInstanceVariableNames(processor, parseErrorSink, sourceCodeService);
            if (ivn == null)
                return this; // ParseIdentifierList() reported the error
            IEnumerable<SourceReference<string>> cvn = this.GetClassVariableNames(processor, parseErrorSink, sourceCodeService);
            if (cvn == null)
                return this; // ParseIdentifierList() reported the error
            IEnumerable<SourceReference<string>> spn = this.GetSharedPoolNames(processor, parseErrorSink, sourceCodeService);
            if (spn == null)
                return this; // ParseIdentifierList() reported the error

            ClassDefinition definition = new ClassDefinition(
                processor.CreateSourceReference(this.ClassName.Value, this.ClassName, sourceCodeService),
                processor.CreateSourceReference(this.SuperclassName.Value, this.SuperclassName, sourceCodeService),
                processor.CreateSourceReference(instanceState.Value, this.IndexedInstanceVariables, sourceCodeService),
                civn, cvn, ivn, spn);
            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInClass(definition);

            return this;
        }
        /// <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.ParsePoolDefinition() should have reported the error.
            if (this.PoolName == null)
                return this;

            PoolDefinition definition = new PoolDefinition(processor.CreateSourceReference(this.PoolName.Value, this.PoolName, sourceCodeService));
            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInPool(definition);
            return this;
        }
        /// <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;
            }

            PoolVariableInitializer definition = new PoolVariableInitializer(
                processor.CreateSourceReference(this.PoolName.Value, this.PoolName, sourceCodeService),
                processor.CreateSourceReference(this.PoolVariableName.Value, this.PoolVariableName, sourceCodeService),
                sourceCodeService,
                methodSourceCodeService,
                new AstIntermediateInitializerCode(initializer));
            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;
        }
        /// <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");

            if ((this.AnnotatedNode == null) || (this.Key == null) || (this.Value == null))
                return this;

            if (this.AnnotatedNode.Definfition == null)
                // Not normal, means there was bug in the code that was supposed to create the definition,
                // but we don't want to add too much trouble to the developer, so we silently ignore
                // the annotation (to the buggy definition).
                return this;

            this.AnnotatedNode.Definfition.Annotate(this.Key.Value, this.Value.Value);
            return this;
        }
Exemple #7
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.ParseClassDefinition() should have reported the error.
            if ((this.ClassName == null) || (this.SuperclassName == null) || (this.IndexedInstanceVariables == null) ||
                (this.InstanceVariableNames == null) || (this.ClassVariableNames == null) || (this.SharedPools == null) ||
                (this.ClassInstanceVariableNames == null))
            {
                return(this);
            }

            SmalltalkClass.InstanceStateEnum?instanceState = this.GetInstanceState(processor, parseErrorSink, sourceCodeService);
            if (instanceState == null)
            {
                return(this);
            }

            IEnumerable <SourceReference <string> > civn = this.GetClassInstanceVariableNames(processor, parseErrorSink, sourceCodeService);

            if (civn == null)
            {
                return(this); // ParseIdentifierList() reported the error
            }
            IEnumerable <SourceReference <string> > ivn = this.GetInstanceVariableNames(processor, parseErrorSink, sourceCodeService);

            if (ivn == null)
            {
                return(this); // ParseIdentifierList() reported the error
            }
            IEnumerable <SourceReference <string> > cvn = this.GetClassVariableNames(processor, parseErrorSink, sourceCodeService);

            if (cvn == null)
            {
                return(this); // ParseIdentifierList() reported the error
            }
            IEnumerable <SourceReference <string> > spn = this.GetSharedPoolNames(processor, parseErrorSink, sourceCodeService);

            if (spn == null)
            {
                return(this); // ParseIdentifierList() reported the error
            }
            ClassDefinition definition = new ClassDefinition(
                processor.CreateSourceReference(this.ClassName.Value, this.ClassName, sourceCodeService),
                processor.CreateSourceReference(this.SuperclassName.Value, this.SuperclassName, sourceCodeService),
                processor.CreateSourceReference(instanceState.Value, this.IndexedInstanceVariables, sourceCodeService),
                civn, cvn, ivn, spn);

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

            return(this);
        }
Exemple #8
0
 protected virtual IEnumerable <SourceReference <string> > GetSharedPoolNames(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     return(processor.ParseIdentifierList(this.SharedPools, parseErrorSink, sourceCodeService));
 }
Exemple #9
0
 protected virtual SmalltalkClass.InstanceStateEnum?GetInstanceState(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     if (this.IndexedInstanceVariables.Value == "byte")
     {
         return(SmalltalkClass.InstanceStateEnum.ByteIndexable);
     }
     else if (this.IndexedInstanceVariables.Value == "object")
     {
         return(SmalltalkClass.InstanceStateEnum.ObjectIndexable);
     }
     else if (this.IndexedInstanceVariables.Value == "none")
     {
         return(SmalltalkClass.InstanceStateEnum.NamedObjectVariables);
     }
     else
     {
         parseErrorSink.AddParserError(this.IndexedInstanceVariables.StartPosition, this.IndexedInstanceVariables.StopPosition,
                                       "Invalid instance state type. Allowed values are: #byte, #object and #none.", this.IndexedInstanceVariables);
         return(null);
     }
 }
        /// <summary>
        /// Parse identifier list. Identifier list have the syntax: identifierList ::= stringDelimiter identifier* stringDelimiter
        /// </summary>
        /// <param name="token">Token containing the string with the identifier list.</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>A collection of sub-tokens if successful or null if token string is illegal.</returns>
        protected internal virtual IEnumerable <SourceReference <string> > ParseIdentifierList(StringToken token, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (parseErrorSink == null)
            {
                throw new ArgumentNullException("parseErrorSink");
            }
            if (sourceCodeService == null)
            {
                throw new ArgumentNullException("sourceCodeService");
            }

            List <SourceReference <string> > result = new List <SourceReference <string> >();

            if (token.Value.Length == 0)
            {
                return(result);
            }

            Scanner scanner = new Scanner(new StringReader(token.Value));
            Token   t       = scanner.GetToken();

            while (!(t is EofToken))
            {
                // Skip whitespaces (incl. comments).
                if (!(t is WhitespaceToken))
                {
                    // Offset the token to the position within the original token. +1 is due to the opening string ' quote.
                    t.SetTokenValues(
                        new SourceLocation(t.StartPosition.Position + token.StartPosition.Position + 1,
                                           t.StartPosition.Line + token.StartPosition.Line,
                                           t.StartPosition.Column + token.StartPosition.Column + 1),
                        new SourceLocation(t.StopPosition.Position + token.StartPosition.Position + 1,
                                           t.StopPosition.Line + token.StartPosition.Line,
                                           t.StopPosition.Column + token.StartPosition.Column + 1),
                        t.ScanError);

                    if (t is IdentifierToken)
                    {
                        // identifier  OK
                        result.Add(new SourceReference <string>(((IdentifierToken)t).Value, t.StartPosition, t.StopPosition, sourceCodeService));
                    }
                    else
                    {
                        // Non-identifier, report error
                        parseErrorSink.AddParserError(t.StartPosition, t.StopPosition, "Expected identifier", t);
                        return(null); // Error condition
                    }
                }
                t = scanner.GetToken();
            }
            return(result);
        }
Exemple #11
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");
            }

            if ((this.AnnotatedNode == null) || (this.Key == null) || (this.Value == null))
            {
                return(this);
            }

            if (this.AnnotatedNode.Definfition == null)
            {
                // Not normal, means there was bug in the code that was supposed to create the definition,
                // but we don't want to add too much trouble to the developer, so we silently ignore
                // the annotation (to the buggy definition).
                return(this);
            }

            this.AnnotatedNode.Definfition.Annotate(this.Key.Value, this.Value.Value);
            return(this);
        }
        /// <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);
        }
Exemple #13
0
 protected virtual void InitParser(TextReader reader)
 {
     this.Scanner = new Scanner(reader);
     this.Scanner.ErrorSink = this;
 }
        protected override SmalltalkClass.InstanceStateEnum?GetInstanceState(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            // TODO : Move constants out of code into a the InterchangeFormatConstants class
            // TODO : Move error messages out of code into a the InterchangeFormatErrors class

            if (this.IndexedInstanceVariables.Value == "native")
            {
                return(SmalltalkClass.InstanceStateEnum.Native);
            }
            return(base.GetInstanceState(processor, parseErrorSink, sourceCodeService));
        }
Exemple #15
0
 /// <summary>
 /// Parse identifier list. Identifier list have the syntax: identifierList ::= stringDelimiter identifier* stringDelimiter
 /// </summary>
 /// <param name="token">Token containing the string with the identifier list.</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>A collection of sub-tokens if successful or null if token string is illegal.</returns>
 public IEnumerable <SourceReference <string> > ParseIdentifierList(StringToken token, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     if (this.VersionService == null)
     {
         throw new InvalidOperationException("Processor cannot be used if version service is not set.");
     }
     return(this.VersionService.ParseIdentifierList(token, parseErrorSink, sourceCodeService));
 }
Exemple #16
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);
        }
Exemple #17
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.ParseInstance/ClassMethodDefinition() should have reported the error.
            if (this.ClassName == null)
            {
                return(this);
            }

            // <methodDefinition> ::= <className> ’method’ <elementSeparator>
            //      <method definition> <elementSeparator>
            // <classMethodDefinition> ::= <className> ’classMethod’ <elementSeparator>
            //      <method definition> <elementSeparator>

            // The methodSourceCodeService is used for translation positions inside the method body,
            // while the sourceCodeService is used for the method declaration (e.g. "Integer method").
            // In reality, most bugs will be in the method source code and therefore report errors
            // via the methodSourceCodeService.
            ISourceCodeReferenceService methodSourceCodeService;
            MethodNode method = processor.ParseMethod(out methodSourceCodeService);

            if (method == null)
            {
                return(this); // Processor/Parser should have reported errors
            }
            if (!method.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 method source code.");
                }
                return(this);
            }

            MethodDefinition definition = this.CreateDefinition(processor, sourceCodeService, methodSourceCodeService, method);

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

            return(this);
        }
Exemple #18
0
 protected virtual void InitParser(TextReader reader)
 {
     this.Scanner           = new Scanner(reader);
     this.Scanner.ErrorSink = this;
 }
 protected virtual SmalltalkClass.InstanceStateEnum? GetInstanceState(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     if (this.IndexedInstanceVariables.Value == "byte")
         return SmalltalkClass.InstanceStateEnum.ByteIndexable;
     else if (this.IndexedInstanceVariables.Value == "object")
         return SmalltalkClass.InstanceStateEnum.ObjectIndexable;
     else if (this.IndexedInstanceVariables.Value == "none")
         return SmalltalkClass.InstanceStateEnum.NamedObjectVariables;
     else
     {
         parseErrorSink.AddParserError(this.IndexedInstanceVariables.StartPosition, this.IndexedInstanceVariables.StopPosition,
             "Invalid instance state type. Allowed values are: #byte, #object and #none.", this.IndexedInstanceVariables);
         return null;
     }
 }
        /// <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.ParseInstance/ClassMethodDefinition() should have reported the error.
            if (this.ClassName == null)
                return this;

            // <methodDefinition> ::= <className> ’method’ <elementSeparator>
            //      <method definition> <elementSeparator>
            // <classMethodDefinition> ::= <className> ’classMethod’ <elementSeparator>
            //      <method definition> <elementSeparator>

            ISourceCodeReferenceService methodSourceCodeService;
            MethodNode method = processor.ParseMethod(out methodSourceCodeService);
            if (method == null)
                return this; // Processor/Parser should have reported errors
            if (!method.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 method source code.");
                return this;
            }

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

            return this;
        }
 protected virtual IEnumerable<SourceReference<string>> GetSharedPoolNames(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     return processor.ParseIdentifierList(this.SharedPools, parseErrorSink, sourceCodeService);
 }
Exemple #22
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 abstract InterchangeUnitNode FileIn(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService);
        /// <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.ParsePoolVariable/ConstantDefinition() should have reported the error.
            if ((this.PoolName == null) || (this.PoolVariableName == null))
            {
                return(this);
            }

            PoolValueDefinition definition = this.CreateDefinition(processor, sourceCodeService);

            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInPoolVariable(definition);
            return(this);
        }
 /// <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 abstract InterchangeUnitNode FileIn(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService);
 protected override SmalltalkClass.InstanceStateEnum? GetInstanceState(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
 {
     if (this.IndexedInstanceVariables.Value == "native")
         return SmalltalkClass.InstanceStateEnum.Native;
     return base.GetInstanceState(processor, parseErrorSink, sourceCodeService);
 }