/// <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; }
public GlobalInitializer(SourceReference<string> globalName, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IntermediateInitializerCode code) : base(sourceCodeService, methodSourceCodeService, code) { if (globalName == null) throw new ArgumentNullException("globalName"); this.GlobalName = globalName; }
public DebugInfoService(ISourceCodeReferenceService sourceCodeService) { if (sourceCodeService == null) { throw new ArgumentNullException(); } this.SourceCodeService = sourceCodeService; }
/// <summary> /// It is expect the next chunk to contain an initializer. This method parses the next chunk /// as an initializer and returns the initializer parse node representing the initializer source. /// </summary> /// <returns>InitializerNode representing the parsed initializer.</returns> public InitializerNode ParseInitializer(out ISourceCodeReferenceService sourceCodeService) { if (this.VersionService == null) { throw new InvalidOperationException("Processor cannot be used if version service is not set."); } return(this.VersionService.ParseInitializer(this, out sourceCodeService)); }
public GlobalInitializer(SourceReference <string> globalName, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IGlobalInitializerFactory factory) : base(sourceCodeService, methodSourceCodeService, factory) { if (globalName == null) { throw new ArgumentNullException("globalName"); } this.GlobalName = globalName; }
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)); }
public RuntimeGlobalInitializerFactory(InitializerNode parseTree, ISourceCodeReferenceService sourceCodeService, string globalName) : base(parseTree, sourceCodeService) { if (String.IsNullOrWhiteSpace(globalName)) { throw new ArgumentNullException("globalName"); } this.GlobalName = globalName; }
public PoolVariableInitializer(SourceReference<string> poolName, SourceReference<string> variableName, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IntermediateInitializerCode code) : base(sourceCodeService, methodSourceCodeService, code) { if (poolName == null) throw new ArgumentNullException("poolName"); if (variableName == null) throw new ArgumentNullException("variableName"); this.PoolName = poolName; this.VariableName = variableName; }
public SourceReference(SourceLocation startPosition, SourceLocation stopPosition, ISourceCodeReferenceService service) { if (service == null) { throw new ArgumentNullException("service"); } this._StartPosition = startPosition; this._StopPosition = stopPosition; this.SourceCodeReferenceService = service; }
public IntermediateCodeValidationErrorSink(ISourceCodeReferenceService sourceCodeService, IDefinitionInstallerContext installer) { if (installer == null) { throw new ArgumentNullException(); } if (sourceCodeService == null) { throw new ArgumentNullException(); } this.Installer = installer; this.SourceCodeService = sourceCodeService; }
public RuntimeCodeFactory(TParseTree parseTree, ISourceCodeReferenceService sourceCodeService) { if (parseTree == null) { throw new ArgumentNullException("parseTree"); } if (sourceCodeService == null) { throw new ArgumentNullException("sourceCodeService"); } this.ParseTree = parseTree; this.SourceCodeService = sourceCodeService; }
public RuntimePoolVariableInitializerFactory(InitializerNode parseTree, ISourceCodeReferenceService sourceCodeService, string poolName, string poolItemName) : base(parseTree, sourceCodeService) { if (String.IsNullOrWhiteSpace(poolName)) { throw new ArgumentNullException("poolName"); } if (String.IsNullOrWhiteSpace(poolItemName)) { throw new ArgumentNullException("poolItemName"); } this.PoolName = poolName; this.PoolItemName = poolItemName; }
/// <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; }
public CodeBasedDefinition(ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, TFactory factory) { if (sourceCodeService == null) { throw new ArgumentNullException("sourceCodeService"); } if (methodSourceCodeService == null) { throw new ArgumentNullException("methodSourceCodeService"); } if (factory == null) { throw new ArgumentNullException("factory"); } this.SourceCodeService = sourceCodeService; this.MethodSourceCodeService = methodSourceCodeService; this.Factory = 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"); // 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 IEnumerable <SourceReference <string> > GetSharedPoolNames(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService) { return(processor.ParseIdentifierList(this.SharedPools, parseErrorSink, 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; } }
public RuntimeProgramInitializerFactory(InitializerNode parseTree, ISourceCodeReferenceService sourceCodeService) : base(parseTree, sourceCodeService) { }
/// <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); }
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 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> /// 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; }
public ClassMethodDefinition(SourceReference <string> className, SourceReference <string> selector, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IMethodFactory factory) : base(className, selector, sourceCodeService, methodSourceCodeService, factory) { }
protected abstract MethodDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, MethodNode parseTree);
public ProgramInitializer(ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IntermediateInitializerCode code) : base(sourceCodeService, methodSourceCodeService, code) { }
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))); }
protected abstract PoolValueDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService);
public InstanceMethodDefinition(SourceReference <string> className, SourceReference <string> selector, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IMethodFactory code) : base(className, selector, sourceCodeService, methodSourceCodeService, code) { }
/// <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); }
/// <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> /// Retrieve the next interchange chunk from the processor and parse it as an initializer. /// </summary> /// <param name="processor">Interchange format processor that can provide the interchange chunk for parsing.</param> /// <param name="sourceCodeService"></param> /// <remarks> /// The parser used here is capable of parsing interchange chunks containing initializers that follow the /// interchange version standard that this version service is supporting. /// </remarks> /// <returns>InitializerNode representing the parsed initializer source.</returns> protected internal virtual InitializerNode ParseInitializer(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 initializer definition."); return(null); } Parser parser = this.GetFunctionParser(); parser.ErrorSink = chunk; return(parser.ParseInitializer(new StringReader(chunk.SourceChunk))); }
public InitializerDefinition(ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IInitializerFactory factory) : base(sourceCodeService, methodSourceCodeService, factory) { }
public SourceReference(SourceLocation startPosition, SourceLocation stopPosition, ISourceCodeReferenceService service) { if (service == null) throw new ArgumentNullException("service"); this._startPosition = startPosition; this._stopPosition = stopPosition; this.SourceCodeReferenceService = service; }
/// <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);
public ProgramInitializer(ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IProgramInitializerFactory factory) : base(sourceCodeService, methodSourceCodeService, factory) { }
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)); }
public PoolVariableInitializer(SourceReference <string> poolName, SourceReference <string> variableName, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IPoolVariableInitializerFactory factory) : base(sourceCodeService, methodSourceCodeService, factory) { if (poolName == null) { throw new ArgumentNullException("poolName"); } if (variableName == null) { throw new ArgumentNullException("variableName"); } this.PoolName = poolName; this.VariableName = variableName; }
public MethodDefinition(SourceReference <string> className, SourceReference <string> selector, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IMethodFactory code) : base(sourceCodeService, methodSourceCodeService, code) { if (className == null) { throw new ArgumentNullException("className"); } if (selector == null) { throw new ArgumentNullException("selector"); } this.ClassName = className; this.Selector = selector; }
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"); } // <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); }
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)); }
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)); }
protected abstract GlobalDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService);
protected override GlobalDefinition CreateDefinition(InterchangeFormatProcessor processor, ISourceCodeReferenceService sourceCodeService) { return new GlobalConstantDefinition(processor.CreateSourceReference(this.GlobalName.Value, this.GlobalName, sourceCodeService)); }
public ClassMethodDefinition(SourceReference<string> className, SourceReference<string> selector, ISourceCodeReferenceService sourceCodeService, ISourceCodeReferenceService methodSourceCodeService, IntermediateMethodCode code) : base(className, selector, sourceCodeService, methodSourceCodeService, code) { }
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); }