Skip to content

Commit

Permalink
Merge branch 'test' of https://github.com/spectatorBH/pascalabcnet in…
Browse files Browse the repository at this point in the history
…to test
  • Loading branch information
spectatorBH committed Jan 7, 2024
2 parents 020ddc9 + aad4d4f commit 721bcb8
Show file tree
Hide file tree
Showing 95 changed files with 4,192 additions and 3,811 deletions.
3 changes: 2 additions & 1 deletion CodeCompletion/CodeCompletionPCUReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private static bool ReadPCUHead(PCUFile pcu_file, BinaryReader br)
if (Header[i] != PCUFile.Header[i])
return false;
pcu_file.Version = br.ReadInt16();
pcu_file.Revision = br.ReadInt32();
pcu_file.CRC = br.ReadInt64();
pcu_file.IncludeDebugInfo = br.ReadBoolean();
return true;
Expand All @@ -96,7 +97,7 @@ private void InvalidUnitDetected()
{
//(ssyy) DarkStar - Ïî÷åìó áû â ýòîì ñëó÷àå ïðîñòî íå ïåðåêîìïèëèðîâàòü ìîäóëü?
CloseUnit();
throw new InvalidPCUFule(unit_name);
throw new InvalidPCUFile(unit_name);
}

private void ReadPCUHeader()
Expand Down
11 changes: 10 additions & 1 deletion CodeCompletion/CodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3504,8 +3504,17 @@ public override void visit(foreach_stmt_formatting fe)
if (need_off)
DecOffset();
}
public override void visit(let_var_expr lvex)
{
sb.Append("(var ");

visit_node(lvex.id);
add_space_after = true;
add_space_before = true;
visit_node(lvex.ex);
}
#endregion
}


}
6 changes: 6 additions & 0 deletions CodeCompletion/DomSyntaxTreeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5980,6 +5980,12 @@ public override void visit(bigint_const bi)
var ne = new new_expr(ntr, new expression_list(new uint64_const(bi.val)), bi.source_context);
ne.visit(this);
}

public override void visit(let_var_expr _let_var_expr)
{
var_def_statement vds = new var_def_statement(_let_var_expr.id, _let_var_expr.ex, _let_var_expr.source_context);
vds.visit(this);
}
}
}

13 changes: 13 additions & 0 deletions CodeCompletion/FindReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ public override void visit(var_def_statement _var_def_statement)
_var_def_statement.inital_value.visit(this);
}

public override void visit(let_var_expr _let_var_expr)
{
if (for_refactoring)
{
IBaseScope ss = entry_scope.FindScopeByLocation(_let_var_expr.id.source_context.begin_position.line_num, _let_var_expr.id.source_context.begin_position.column_num);
if (ss != null && ss.IsEqual(founded_scope))
pos_list.Add(get_position(_let_var_expr.id));
}

if (_let_var_expr.ex != null)
_let_var_expr.ex.visit(this);
}

public override void visit(declaration _declaration)
{
throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion CodeCompletion/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CodeCompletion")]
[assembly: AssemblyCopyright("Copyright © 2005-2023 by Ivan Bondarev, Stanislav Mikhalkovich")]
[assembly: AssemblyCopyright("Copyright © 2005-2024 by Ivan Bondarev, Stanislav Mikhalkovich")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
16 changes: 8 additions & 8 deletions CodeCompletion/SymTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ public virtual bool IsReintroduce

public void MakeDescription()
{
si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this);
si.description = CodeCompletionController.CurrentParser?.LanguageInformation.GetDescription(this);
if (!string.IsNullOrEmpty(documentation))
si.description += Environment.NewLine + documentation;
}
Expand Down Expand Up @@ -1686,7 +1686,7 @@ public override bool IsEqual(SymScope ts)

public override string ToString()
{
return CodeCompletionController.CurrentParser.LanguageInformation.GetSimpleDescription(this);
return CodeCompletionController.CurrentParser?.LanguageInformation.GetSimpleDescription(this);
}
}

Expand Down Expand Up @@ -2151,7 +2151,7 @@ public override bool IsEqual(SymScope ts)

public override string ToString()
{
return CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this);
return CodeCompletionController.CurrentParser?.LanguageInformation.GetDescription(this);
}
}

Expand Down Expand Up @@ -2486,15 +2486,15 @@ public virtual bool IsConstructor()
public override void MakeSynonimDescription()
{
//aliased = true;
si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetSynonimDescription(this);
si.description = CodeCompletionController.CurrentParser?.LanguageInformation.GetSynonimDescription(this);
}

//zavershenie opisanija, vyzyvaetsja kogda parametry razobrany
public void Complete()
{
if (documentation != null && documentation.Length > 0 && documentation[0] == '-') return;
this.si.description = this.ToString();
this.si.addit_name = CodeCompletionController.CurrentParser.LanguageInformation.GetShortName(this);
this.si.addit_name = CodeCompletionController.CurrentParser?.LanguageInformation.GetShortName(this);
if (documentation != null) this.si.description += "\n" + this.documentation;
}

Expand Down Expand Up @@ -2720,8 +2720,8 @@ public override string GetDescriptionWithoutDoc()

public override string ToString()
{
simp_descr = CodeCompletionController.CurrentParser.LanguageInformation.GetSimpleDescription(this);
return CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this);
simp_descr = CodeCompletionController.CurrentParser?.LanguageInformation.GetSimpleDescription(this);
return CodeCompletionController.CurrentParser?.LanguageInformation.GetDescription(this);
}
}

Expand Down Expand Up @@ -3775,7 +3775,7 @@ public override TypeScope GetElementType()

public override string ToString()
{
return CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this);
return CodeCompletionController.CurrentParser?.LanguageInformation.GetDescription(this);
}
}

Expand Down
21 changes: 20 additions & 1 deletion Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,23 @@ void semanticTreeConvertersController_ChangeState(SemanticTreeConvertersControll
}
}

private static HashSet<string> knownDirectives = new HashSet<string>(new string[] { PascalABCCompiler.TreeConverter.compiler_string_consts.main_resource_string,
PascalABCCompiler.TreeConverter.compiler_string_consts.trademark_string, PascalABCCompiler.TreeConverter.compiler_string_consts.copyright_string,
PascalABCCompiler.TreeConverter.compiler_string_consts.company_string, PascalABCCompiler.TreeConverter.compiler_string_consts.product_string,
PascalABCCompiler.TreeConverter.compiler_string_consts.version_string, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_apptype,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_reference, PascalABCCompiler.TreeConverter.compiler_string_consts.include_namespace_directive,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_savepcu, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_zerobasedstrings,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_zerobasedstrings_ON, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_zerobasedstrings_OFF,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_nullbasedstrings_ON, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_nullbasedstrings_OFF,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_initstring_as_empty_ON, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_initstring_as_empty_OFF,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_resource, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_platformtarget,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_targetframework, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_faststrings,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_gendoc, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_region,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_endregion, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_ifdef,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_endif, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_ifndef,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_define, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_else,
PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_undef, PascalABCCompiler.TreeConverter.compiler_string_consts.compiler_directive_include});

private Dictionary<string, List<compiler_directive>> GetCompilerDirectives(List<CompilationUnit> Units)
{
Dictionary<string, List<compiler_directive>> directives = new Dictionary<string, List<compiler_directive>>(StringComparer.CurrentCultureIgnoreCase);
Expand All @@ -1170,6 +1187,8 @@ private Dictionary<string, List<compiler_directive>> GetCompilerDirectives(List<
else if (cd.name.Equals("mainresource", StringComparison.CurrentCultureIgnoreCase))
throw new DuplicateDirective(cd.location.doc.file_name, "mainresource", cd.location);
directives[cd.name].Insert(0, cd);
if (!knownDirectives.Contains(cd.name.ToLower()))
warnings.Add(new Errors.CommonWarning(string.Format(StringResources.Get("WARNING_UNKNOWN_DIRECTIVE"), cd.name), cd.location.doc.file_name, cd.location.begin_line_num, cd.location.begin_column_num));
}
}
}
Expand Down Expand Up @@ -4162,7 +4181,7 @@ private bool UnitHasPCU(unit_node_list unitsFromUsesSection, Dictionary<unit_nod
return true;
}
}
catch (InvalidPCUFule)
catch (InvalidPCUFile)
{
//Перекомпилируем....
}
Expand Down
2 changes: 1 addition & 1 deletion Compiler/PCU/PCUFileFormatVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace PascalABCCompiler.PCU
{
public static class PCUFileFormatVersion
{
public static System.Int16 Version = 118;
public static System.Int16 Version = 120;
}
}
23 changes: 16 additions & 7 deletions Compiler/PCU/PCUReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public enum PCUReaderWriterState
BeginReadTree, EndReadTree, BeginSaveTree, EndSaveTree, ErrorSaveTree
}

public class InvalidPCUFule: PascalABCCompiler.Errors.LocatedError
public class InvalidPCUFile: PascalABCCompiler.Errors.LocatedError
{
internal string UnitName;
public InvalidPCUFule(string UnitName)
public InvalidPCUFile(string UnitName)
{
this.UnitName = UnitName;
}
Expand Down Expand Up @@ -263,6 +263,7 @@ public CompilationUnit GetCompilationUnit(string FileName, bool readDebugInfo)
ms = new MemoryStream(File.ReadAllBytes(FileName));
br = new BinaryReader(ms);
ReadPCUHeader();

units[FileName] = this;
unit = new CompilationUnit();
unit.UnitFileName = FileName;
Expand Down Expand Up @@ -313,7 +314,13 @@ public CompilationUnit GetCompilationUnit(string FileName, bool readDebugInfo)
AddTypeSynonyms(pcu_file.interface_synonyms_offset, cun.scope);
AddTypeSynonyms(pcu_file.implementation_synonyms_offset, cun.implementation_scope);
//\ssyy

for (int i = 0; i < pcu_file.names.Length; i++)
{
if (pcu_file.names[i].always_restore)
{
cun.scope.Find(pcu_file.names[i].name);
}
}

ChangeState(this, PCUReaderWriterState.EndReadTree, unit);
return unit;
Expand Down Expand Up @@ -537,9 +544,8 @@ private void AddNames(NameRef[] names, SymbolTable.Scope Scope)

private void InvalidUnitDetected()
{
//(ssyy) DarkStar - Почему бы в этом случае просто не перекомпилировать модуль?
CloseUnit();
throw new InvalidPCUFule(unit_name);
throw new InvalidPCUFile(unit_name);
}

private static bool ReadPCUHead(PCUFile pcu_file, BinaryReader br)
Expand All @@ -549,6 +555,7 @@ private static bool ReadPCUHead(PCUFile pcu_file, BinaryReader br)
if (Header[i] != PCUFile.Header[i])
return false;
pcu_file.Version = br.ReadInt16();
pcu_file.Revision = br.ReadInt32();
pcu_file.CRC = br.ReadInt64();
pcu_file.UseRtlDll = br.ReadBoolean();
pcu_file.IncludeDebugInfo = br.ReadBoolean();
Expand All @@ -558,7 +565,7 @@ private static bool ReadPCUHead(PCUFile pcu_file, BinaryReader br)
//чтение заголовка PCU
private void ReadPCUHeader()
{
if (!ReadPCUHead(pcu_file, br) || PCUFile.SupportedVersion != pcu_file.Version)
if (!ReadPCUHead(pcu_file, br) || PCUFile.SupportedVersion != pcu_file.Version || PCUFile.SupportedRevision != pcu_file.Revision)
InvalidUnitDetected();

if(pcu_file.IncludeDebugInfo)
Expand All @@ -578,6 +585,7 @@ private void ReadPCUHeader()
pcu_file.names[i].offset = br.ReadInt32();
pcu_file.names[i].symbol_kind = (symbol_kind)br.ReadByte();
pcu_file.names[i].special_scope = br.ReadByte();
pcu_file.names[i].always_restore = br.ReadBoolean();
}
//ssyy
num_names = br.ReadInt32();
Expand All @@ -588,6 +596,7 @@ private void ReadPCUHeader()
pcu_file.implementation_names[i].offset = br.ReadInt32();
pcu_file.implementation_names[i].symbol_kind = (symbol_kind)br.ReadByte();
pcu_file.implementation_names[i].special_scope = br.ReadByte();
pcu_file.implementation_names[i].always_restore = br.ReadBoolean();
}
//\ssyy
int num_incl = br.ReadInt32();
Expand Down Expand Up @@ -2567,7 +2576,7 @@ private string[] AddClassMemberNames(WrappedClassScope scope)

si.symbol_kind = (symbol_kind)br.ReadByte();
si.semantic_node_type = (semantic_node_type)br.ReadByte();
si.virtual_slot = br.ReadBoolean();
si.always_restore = br.ReadBoolean();
si.is_static = br.ReadBoolean();
//Вроде это ненужно
//SymbolInfo si2 = scope.FindWithoutCreation(name);
Expand Down
4 changes: 3 additions & 1 deletion Compiler/PCU/PCUWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ private bool needRestore(PCUSymbolInfo pcu_tsi, string name)
{
if (pcu_tsi == null)
return true;
if (pcu_tsi.semantic_node_type == semantic_node_type.common_method_node && pcu_tsi.virtual_slot)
//if (pcu_tsi.semantic_node_type == semantic_node_type.common_method_node && pcu_tsi.virtual_slot)
// return true;
if (pcu_tsi.always_restore)
return true;
if (hasNotRestoreAttribute())
return false;
Expand Down
Loading

0 comments on commit 721bcb8

Please sign in to comment.