/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0-alpha-1
src/ScriptEngine/Compiler/AstBasedCompilerService.cs
93 строки
3 KB
EvilBeaver
Поле генерации доп. кода инициализируется не из опций, а из Engine. Пока оставим так
16 янв 2021, 22:23
16 янв 2021, 22:23
2c241d9
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System.Collections.Generic; using System.Linq; using OneScript.Language; using OneScript.Language.LexicalAnalysis; using OneScript.Language.SyntaxAnalysis; using OneScript.Language.SyntaxAnalysis.AstNodes; using ScriptEngine.Environment; namespace ScriptEngine.Compiler { internal class AstBasedCompilerService : CompilerServiceBase { private readonly CompilerOptions _сompilerOptions; internal AstBasedCompilerService(CompilerOptions сompilerOptions, ICompilerContext outerContext) : base(outerContext) { _сompilerOptions = сompilerOptions; } protected override ModuleImage CompileInternal(ICodeSource source, IEnumerable<string> preprocessorConstants, ICompilerContext context) { var codeGen = new AstBasedCodeGenerator(context) { ThrowErrors = true, ProduceExtraCode = ProduceExtraCode, DependencyResolver = _сompilerOptions.DependencyResolver }; var astBuilder = new DefaultAstBuilder(); _сompilerOptions.NodeBuilder = astBuilder; var handlers = _сompilerOptions.PreprocessorFactory.Create(_сompilerOptions); var lexer = CreatePreprocessor(source, preprocessorConstants, handlers); var parser = new DefaultBslParser( lexer, astBuilder, _сompilerOptions.ErrorSink, handlers); ModuleNode moduleNode; var mi = CreateModuleInformation(source, lexer); try { moduleNode = (ModuleNode)parser.ParseStatefulModule(); } catch (SyntaxErrorException e) { if (e.ModuleName == default) { e.ModuleName = mi.ModuleName; } throw; } return codeGen.CreateImage(moduleNode, mi); } private PreprocessingLexer CreatePreprocessor( ICodeSource source, IEnumerable<string> preprocessorConstants, PreprocessorHandlers handlers) { var baseLexer = new DefaultLexer { Iterator = new SourceCodeIterator(source.Code) }; var conditionals = handlers.Get<ConditionalDirectiveHandler>(); if (conditionals != default) { foreach (var constant in preprocessorConstants) { conditionals.Define(constant); } } var lexer = new PreprocessingLexer(baseLexer) { Handlers = handlers, ErrorSink = _сompilerOptions.ErrorSink }; return lexer; } } }