From 466ac552d834c9f92f3529880bf8e12a5485d9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 4 Nov 2018 12:06:43 +0100 Subject: [PATCH] fix #1446 --- Compiler/Compiler.cs | 22 ++++++++++++++++------ TestSuite/errors/err0300.pas | 4 ++++ bin/Lng/Eng/CompilerErrors.dat | 1 + bin/Lng/Rus/CompilerErrors.dat | 1 + bin/Lng/Ukr/CompilerErrors.dat | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 TestSuite/errors/err0300.pas diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 48c24d93f..6070ebd1b 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -303,7 +303,16 @@ namespace PascalABCCompiler this.source_context = sc; } } - + public class DuplicateDirective : CompilerCompilationError + { + public string DirectiveName; + public DuplicateDirective(string FileName, string DirectiveName, SyntaxTree.SourceContext sc) + : base(string.Format(StringResources.Get("COMPILATIONERROR_DUPLICATE_DIRECTIVE{0}"), DirectiveName), FileName) + { + this.DirectiveName = DirectiveName; + this.source_context = sc; + } + } public class UnitNotFound : CompilerCompilationError { public string UnitName; @@ -1076,18 +1085,20 @@ namespace PascalABCCompiler } } - private Dictionary> GetCompilerDirectives(List Units) + private Dictionary> GetCompilerDirectives(List Units) { Dictionary> Directives = new Dictionary>(StringComparer.CurrentCultureIgnoreCase); - + for (int i = 0; i < Units.Count; i++) { TreeRealization.common_unit_node cun = Units[i].SemanticTree as TreeRealization.common_unit_node; - if (cun!=null) + if (cun != null) foreach (TreeRealization.compiler_directive cd in cun.compiler_directives) { - if(!Directives.ContainsKey(cd.name)) + if (!Directives.ContainsKey(cd.name)) Directives.Add(cd.name, new List()); + else if (string.Compare(cd.name, "mainresource", true) == 0) + throw new DuplicateDirective(cd.location.doc.file_name, "mainresource", cd.location); Directives[cd.name].Insert(0, cd); } } @@ -1850,7 +1861,6 @@ namespace PascalABCCompiler TreeRealization.compiler_directive compilerDirective; - //TODO сделать это понормальному!!!!! if (compilerDirectives.ContainsKey(TreeConverter.compiler_string_consts.compiler_directive_apptype)) { string directive = compilerDirectives[TreeConverter.compiler_string_consts.compiler_directive_apptype][0].directive; diff --git a/TestSuite/errors/err0300.pas b/TestSuite/errors/err0300.pas new file mode 100644 index 000000000..bde8f9b37 --- /dev/null +++ b/TestSuite/errors/err0300.pas @@ -0,0 +1,4 @@ +{$mainresource '0.res'} +{$mainresource '1.res'} + +begin end. \ No newline at end of file diff --git a/bin/Lng/Eng/CompilerErrors.dat b/bin/Lng/Eng/CompilerErrors.dat index de3135ee7..51f1f0bae 100644 --- a/bin/Lng/Eng/CompilerErrors.dat +++ b/bin/Lng/Eng/CompilerErrors.dat @@ -13,6 +13,7 @@ UNDEFINED_SEMANTIC_ERROR{0}=Undefined semantic error : {0} RESOURCEFILE_{0}_NOT_FOUND=Resource file '{0}' not found DUPLICATE_USES_UNIT{0}=Duplicate identifier '{0}' in uses section MAINRESOURCE_NOT_ALLOWED=mainresource can not be used with the directives: product, version, company, trademark +DUPLICATE_DIRECTIVE{0}=Duplicate directive {0} %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 3ea9357cc..942945b9f 100644 --- a/bin/Lng/Rus/CompilerErrors.dat +++ b/bin/Lng/Rus/CompilerErrors.dat @@ -13,6 +13,7 @@ UNDEFINED_SEMANTIC_ERROR{0}=Неопределенная семантическ RESOURCEFILE_{0}_NOT_FOUND=Файл '{0}' не найден DUPLICATE_USES_UNIT{0}=Повторное подключение модуля {0} в секции uses MAINRESOURCE_NOT_ALLOWED=Недопустимо совместное использование директивы mainresource и директив product, version, company, trademark +DUPLICATE_DIRECTIVE{0}=Повторное объявление директивы {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 cfce889fb..5302a42b0 100644 --- a/bin/Lng/Ukr/CompilerErrors.dat +++ b/bin/Lng/Ukr/CompilerErrors.dat @@ -13,6 +13,7 @@ UNDEFINED_SEMANTIC_ERROR{0}=Невизначена семантична поми RESOURCEFILE_{0}_NOT_FOUND=Файл '{0}' не знайдено DUPLICATE_USES_UNIT{0}=Повторне підключення модуля {0} в секції uses MAINRESOURCE_NOT_ALLOWED=Неприпустимо сумісне використання директиви mainresource і директив product, version, company, trademark +DUPLICATE_DIRECTIVE{0}=Повторное объявление директивы {0} %PREFIX%= COMPILER_INTERNAL_ERROR_IN_UNIT_{0}_:{1}=Внутрішня помилка компілятора в модулі {0} :'{1}' \ No newline at end of file