From 3e83d3e3b50f41b12748aed5eef43e3121e1d3a7 Mon Sep 17 00:00:00 2001 From: samuraiGH Date: Sun, 12 Mar 2023 16:37:50 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D0=B2=D1=8B=20TargetFramework?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Compiler/Compiler.cs | 15 +++++++++++++++ NETGenerator/NETGenerator.cs | 14 ++++++++++++++ .../TreeConversion/compiler_string_consts.cs | 1 + bin/Lng/Eng/CompilerErrors.dat | 1 + bin/Lng/Rus/CompilerErrors.dat | 1 + bin/Lng/Ukr/CompilerErrors.dat | 1 + 6 files changed, 33 insertions(+) diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 2407e2efe..e35e8d4d3 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -402,6 +402,14 @@ namespace PascalABCCompiler } } + public class UnsupportetTargetFramework: CompilerCompilationError + { + public UnsupportetTargetFramework(string FrameworkName, TreeRealization.location sl) + : base(string.Format(StringResources.Get("COMPILATIONERROR_UNSUPPORTED_TARGETFRAMEWORK_{0}"), FrameworkName)) + { + this.sourceLocation = new SourceLocation(sl.doc.file_name, sl.begin_line_num, sl.begin_column_num, sl.end_line_num, sl.end_column_num); + } + } public enum UnitState { BeginCompilation, InterfaceCompiled, Compiled } @@ -1988,6 +1996,13 @@ namespace PascalABCCompiler } if (this.compilerOptions.Only32Bit) cdo.platformtarget = NETGenerator.CompilerOptions.PlatformTarget.x86; + if (compilerDirectives.TryGetValue(TreeConverter.compiler_string_consts.compiler_directive_targetframework, out cds)) + { + cdo.TargetFramework = cds[0].directive; + if (!new string[] { "net40", "net403", "net45", "net451", "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48", "net481" } + .Contains(cdo.TargetFramework)) + ErrorsList.Add(new UnsupportetTargetFramework(cdo.TargetFramework, cds[0].location)); + } if (compilerDirectives.TryGetValue(TreeConverter.compiler_string_consts.product_string, out cds)) { cdo.Product = cds[0].directive; diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 762bb8c39..06f347d84 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -56,6 +56,14 @@ namespace PascalABCCompiler.NETGenerator set { _platformtarget = value; } } + private string _TargetFramework = ""; + + public string TargetFramework + { + get { return _TargetFramework; } + set { _TargetFramework = value; } + } + public string Product { get { return _Product; } @@ -1157,6 +1165,12 @@ namespace PascalABCCompiler.NETGenerator ab.SetCustomAttribute(new CustomAttributeBuilder(typeof(System.Reflection.AssemblyTitleAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { options.Title })); ab.SetCustomAttribute(new CustomAttributeBuilder(typeof(System.Reflection.AssemblyDescriptionAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { options.Description })); + + if (options.TargetFramework != "") + { + string frameworkVersion = string.Join(".", options.TargetFramework.Substring(3).AsEnumerable()); + ab.SetCustomAttribute(new CustomAttributeBuilder(typeof(TargetFrameworkAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { $".NETFramework,Version=v{frameworkVersion}" })); + } if (RunOnly) { diff --git a/TreeConverter/TreeConversion/compiler_string_consts.cs b/TreeConverter/TreeConversion/compiler_string_consts.cs index 2fa70d801..ebb8a24d1 100644 --- a/TreeConverter/TreeConversion/compiler_string_consts.cs +++ b/TreeConverter/TreeConversion/compiler_string_consts.cs @@ -332,6 +332,7 @@ namespace PascalABCCompiler.TreeConverter public static string compiler_directive_resource = "resource"; public static string compiler_directive_platformtarget = "platformtarget"; public static string compiler_directive_faststrings = "faststrings"; + public static string compiler_directive_targetframework = "targetframework"; // SSM (3.1.2011) Перене� �ти кон�танты �юда. public static string version_string = "version"; diff --git a/bin/Lng/Eng/CompilerErrors.dat b/bin/Lng/Eng/CompilerErrors.dat index ea7812857..12facc228 100644 --- a/bin/Lng/Eng/CompilerErrors.dat +++ b/bin/Lng/Eng/CompilerErrors.dat @@ -19,6 +19,7 @@ NAMESPACE_CAN_BE_COMPILED_ONLY_IN_PROJECTS=Files with namespaces can be compiled NAMESPACE_CANNOT_HAVE_IN_SECTION=Namespace cannot have 'in' section APPTYPE_DLL_IS_ALLOWED_ONLY_FOR_LIBRARIES= {$apptype dll} directive is allowed only for libraries USES_IN_WRONG_NAME=Unit name in uses-in ({0}) must be same as file name ({1}) +UNSUPPORTED_TARGETFRAMEWORK_{0}=TargetFramework '{0}' not supported %PREFIX%= COMPILER_INTERNAL_ERROR_IN_UNIT_{0}_:{1}=Internal compiler error in module {0} :'{1}' \ No newline at end of file diff --git a/bin/Lng/Rus/CompilerErrors.dat b/bin/Lng/Rus/CompilerErrors.dat index c337ebb0b..cd33adff6 100644 --- a/bin/Lng/Rus/CompilerErrors.dat +++ b/bin/Lng/Rus/CompilerErrors.dat @@ -19,6 +19,7 @@ FILE_{0}_NOT_FOUND=Файл '{0}' не найден NAMESPACE_CANNOT_HAVE_IN_SECTION=Дл� про�тран�тва имен не может указывать�� �екци� in APPTYPE_DLL_IS_ALLOWED_ONLY_FOR_LIBRARIES=Директива {$apptype dll} возможна только дл� библиотек USES_IN_WRONG_NAME=Им� модул� в uses-in ({0}) должно �овпадать � именем файла ({1}) +UNSUPPORTED_TARGETFRAMEWORK_{0}=TargetFramework '{0}' не поддерживает�� %PREFIX%= COMPILER_INTERNAL_ERROR_IN_UNIT_{0}_:{1}=Внутренн�� ошибка компил�тора в модуле {0} :'{1}' \ No newline at end of file diff --git a/bin/Lng/Ukr/CompilerErrors.dat b/bin/Lng/Ukr/CompilerErrors.dat index 2f7a82bff..8a3ac92fb 100644 --- a/bin/Lng/Ukr/CompilerErrors.dat +++ b/bin/Lng/Ukr/CompilerErrors.dat @@ -17,6 +17,7 @@ DUPLICATE_DIRECTIVE{0}=Повторное объ�вление директив FILE_{0}_NOT_FOUND=Файл '{0}' не знайдено NAMESPACE_CAN_BE_COMPILED_ONLY_IN_PROJECTS=Компил�ци� файлов � про�тран�твами имен допу�тима только в проектах USES_IN_WRONG_NAME=Ім'� модул� в uses-in ({0}) має збігати�� з ім'�м файлу ({1}) +UNSUPPORTED_TARGETFRAMEWORK_{0}=TargetFramework '{0}' не підтримуєть�� %PREFIX%= COMPILER_INTERNAL_ERROR_IN_UNIT_{0}_:{1}=Внутрішн� помилка компіл�тора в модулі {0} :'{1}' \ No newline at end of file From 4c814fd56c9876356a24621dc71fb08506237c02 Mon Sep 17 00:00:00 2001 From: samuraiGH Date: Sun, 12 Mar 2023 18:52:02 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PABCNetHelp/LangGuide/CompilerDirectives/index_directives.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PABCNetHelp/LangGuide/CompilerDirectives/index_directives.html b/PABCNetHelp/LangGuide/CompilerDirectives/index_directives.html index 1b5b1e6b7..cacb9047e 100644 --- a/PABCNetHelp/LangGuide/CompilerDirectives/index_directives.html +++ b/PABCNetHelp/LangGuide/CompilerDirectives/index_directives.html @@ -27,6 +27,7 @@ + @@ -84,6 +85,7 @@ x64} -

{$company <êîìïàíèÿ>} - êîìïàíèÿ

{$copyright <êîïèðàéò>} - êîïèðàéò

{$trademark <òîðãîâàÿ ìàðêà>} - òîðãîâàÿ ìàðêà

+

{$targetframework <âåðñèÿ>} - ìèíèìàëüíàÿ âåðñèÿ .NET Framework, òðåáóåìàÿ äëÿ çàïóñêà

Äèðåêòèâû $ifdef, $ifndef ñîâìåñòíî ñ äèðåêòèâàìè $else è $endif óïðàâëþò óñëîâíîé êîìïèëÿöèåé ÷àñòåé èñõîäíîãî ôàéëà. Êàæäîé äèðåêòèâå $ifdef, $ifndef äîëæíà ñîîòâåòñòâîâàòü çàâåðøàþùàÿ åå