/// <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> /// 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 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"); } // 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); }
protected override MethodDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, MethodNode parseTree) { return new InstanceMethodDefinition( processor.CreateSourceReference(this.ClassName.Value, this.ClassName, sourceCodeService), processor.CreateSourceReference(parseTree.Selector, parseTree.SelectorParts[0].StartPosition, parseTree.SelectorParts.Last().StopPosition, sourceCodeService), sourceCodeService, methodSourceCodeService, new AstIntermediateMethodCode(parseTree)); }
/// <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); }
/// <summary> /// Create a new interchange chunk. /// </summary> /// <param name="processor">Interchange processor that created and owns this chunk.</param> /// <param name="sourceChunk">The source code string that is contained in this chunk.</param> /// <param name="startPosition">Start position of this chunk in the interchange file.</param> public InterchangeChunk(InterchangeFormatProcessor processor, string sourceChunk, SourceLocation startPosition) { if (processor == null) throw new ArgumentNullException("processor"); if (sourceChunk == null) throw new ArgumentNullException("sourceChunk"); this.Processor = processor; this.SourceChunk = sourceChunk; this.StartPosition = startPosition; }
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)); }
/// <summary> /// Create a new interchange chunk. /// </summary> /// <param name="processor">Interchange processor that created and owns this chunk.</param> /// <param name="sourceChunk">The source code string that is contained in this chunk.</param> /// <param name="startPosition">Start position of this chunk in the interchange file.</param> public InterchangeChunk(InterchangeFormatProcessor processor, string sourceChunk, SourceLocation startPosition) { if (processor == null) { throw new ArgumentNullException("processor"); } if (sourceChunk == null) { throw new ArgumentNullException("sourceChunk"); } this.Processor = processor; this.SourceChunk = sourceChunk; this.StartPosition = startPosition; }
protected override MethodDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, MethodNode parseTree) { // 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. RuntimeCompiledMethodFactory factory = new RuntimeCompiledMethodFactory(parseTree, methodSourceCodeService); return(new ClassMethodDefinition( processor.CreateSourceReference(this.ClassName.Value, this.ClassName, sourceCodeService), processor.CreateSourceReference(parseTree.Selector, parseTree.SelectorParts[0].StartPosition, parseTree.SelectorParts.Last().StopPosition, sourceCodeService), sourceCodeService, methodSourceCodeService, factory)); }
/// <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); }
/// <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; }
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); } }
public InterchangeInstallerContext ReadFiles(string[] paths, IInterchangeErrorSink errorSink) { if (paths == null) throw new ArgumentNullException("paths"); InterchangeInstallerContext installer = this.CreateInstallerContext(); foreach (string path in paths) { // Issue - expects UTF-8 encoding using (StreamReader sourceFileReader = File.OpenText(path)) { InterchangeFormatProcessor processor = new InterchangeFormatProcessor(sourceFileReader, installer, this.VersionServicesMap); processor.ErrorSink = errorSink; processor.ProcessInterchangeFile(); } } return installer; }
/// <summary> /// Report that an error has occured during parsing of the source code. /// </summary> /// <param name="processor">Interchange format processor whos error-sink is used to report the error.</param> /// <param name="parseErrorMessage">Error message.</param> protected void ReportError(InterchangeFormatProcessor processor, string parseErrorMessage) { if (processor == null) throw new ArgumentNullException(); if (processor.ErrorSink != null) processor.ErrorSink.AddInterchangeError(processor.SourcePosition, processor.SourcePosition, parseErrorMessage); }
protected abstract PoolValueDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService);
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; } }
protected virtual IEnumerable<SourceReference<string>> GetSharedPoolNames(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService) { return processor.ParseIdentifierList(this.SharedPools, parseErrorSink, sourceCodeService); }
protected abstract MethodDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, MethodNode parseTree);
protected virtual IEnumerable <SourceReference <string> > GetSharedPoolNames(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService) { return(processor.ParseIdentifierList(this.SharedPools, parseErrorSink, 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 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); }
protected override GlobalDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService) { return new GlobalConstantDefinition(processor.CreateSourceReference(this.GlobalName.Value, this.GlobalName, sourceCodeService)); }
protected abstract GlobalDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService);
protected override PoolValueDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService) { return(new PoolVariableDefinition( processor.CreateSourceReference(this.PoolName.Value, this.PoolName, sourceCodeService), processor.CreateSourceReference(this.PoolVariableName.Value, this.PoolVariableName, sourceCodeService))); }
public InterchangeInstallerContext ReadSources(string[] interchangeCode, IInterchangeErrorSink errorSink) { if (interchangeCode == null) throw new ArgumentNullException("interchangeCode"); InterchangeInstallerContext installer = this.CreateInstallerContext(); foreach (string code in interchangeCode) { InterchangeFormatProcessor processor = new InterchangeFormatProcessor(new StringReader(code), installer, this.VersionServicesMap); processor.ErrorSink = errorSink; processor.ProcessInterchangeFile(); } return installer; }
/// <summary> /// Retereive the next interchange chunk from the processor and parse it as a method. /// </summary> /// <param name="processor">Interchange format processor that can provide the interchange chunk for parsing.</param> /// <remarks> /// The parser used here is capable of parsing interchange chunks containg methods that follow the /// interchange version standard that this version service is supporting. /// </remarks> /// <returns>MethodNode representing the parsed method source.</returns> protected internal virtual MethodNode ParseMethod(InterchangeFormatProcessor processor, out ISourceCodeReferenceService sourceCodeService) { InterchangeChunk chunk = this.GetNextChunk(processor); sourceCodeService = chunk; if (chunk == null) { // Must have an interchange element that contains <initializer definition>. this.ReportError(processor, "Expected method definition."); return null; } Parser parser = this.GetFunctionParser(); parser.ErrorSink = chunk; return parser.ParseMethod(new StringReader(chunk.SourceChunk)); }
/// <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> /// Process the interchange elements (chunks) provided by the given interchange format processor. /// </summary> /// <param name="processor">Interchange format processor that can provide interchange chunks for processing.</param> protected internal virtual void ProcessInterchangeElements(InterchangeFormatProcessor processor) { InterchangeChunk chunk = this.GetNextChunk(processor); if (chunk == null) { // Must have at least ONE interchange unit. this.ReportError(processor, InterchangeFormatErrors.ExpectedInterchangeUnit); return; } InterchangeUnitNode node = null; while (chunk != null) { node = this.ProcessInterchangeElement(processor, node, chunk); chunk = this.GetNextChunk(processor); } }
/// <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; }
/// <summary> /// Get the next interchage chunk to be processor. /// </summary> /// <param name="processor">Interchange format processor that contains the interchange sources.</param> /// <returns></returns> protected InterchangeChunk GetNextChunk(InterchangeFormatProcessor processor) { if (processor == null) throw new ArgumentNullException(); return processor.GetNextChunk(); }
/// <summary> /// Process a given interchange element (chunk). /// </summary> /// <param name="processor"></param> /// <param name="node">Last node that was parsed. This is used for annotations.</param> /// <param name="chunk">Interchange chunk to be processed.</param> /// <returns>Returns the new interchange parse node (or null in case of error).</returns> protected virtual InterchangeUnitNode ProcessInterchangeElement(InterchangeFormatProcessor processor, InterchangeUnitNode node, InterchangeChunk chunk) { InterchangeFormatParser parser = this.GetInterchangeParser(chunk); InterchangeElementNode nodeForAnnotation = (node == null) ? null : node.GetAnnotatedNode(); node = parser.ParseInterchangeElement(nodeForAnnotation); if (node == null) return null; return node.FileIn(processor, chunk, chunk); }
protected override GlobalDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService) { return(new GlobalConstantDefinition(processor.CreateSourceReference(this.GlobalName.Value, this.GlobalName, sourceCodeService))); }
protected override PoolValueDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService) { return new PoolConstantDefinition( processor.CreateSourceReference(this.PoolName.Value, this.PoolName, sourceCodeService), processor.CreateSourceReference(this.PoolVariableName.Value, this.PoolVariableName, sourceCodeService)); }