diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 55c9632ff..139e78a53 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "9"; public const string Build = "0"; - public const string Revision = "3288"; + public const string Revision = "3293"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 1409b7842..0a81589bb 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=0 -%REVISION%=3288 %MINOR%=9 +%REVISION%=3293 +%COREVERSION%=0 %MAJOR%=3 diff --git a/ParserTools/ParserTools/DefaultLanguageInformation.cs b/ParserTools/ParserTools/DefaultLanguageInformation.cs index c45799a56..dd4d02c6c 100644 --- a/ParserTools/ParserTools/DefaultLanguageInformation.cs +++ b/ParserTools/ParserTools/DefaultLanguageInformation.cs @@ -542,17 +542,38 @@ namespace PascalABCCompiler.Parsers if (fields[i].Name != "value__") { object o = fields[i].GetRawConstantValue(); //ошибка была здесь, так как я не знал, что у констант enum'а может быть другой тип помимо int - switch (o) - { - case byte b: if (b != i - 1) return true; break; - case sbyte b: if (b != i - 1) return true; break; - case short b: if (b != i - 1) return true; break; - case ushort b: if (b != i - 1) return true; break; - case int b: if (b != i - 1) return true; break; - case uint b: return true; break; - case long b: return true; break; - case ulong b: return true; break; - } + if (o is byte b1) + { + if (b1 != i - 1) return true; + } + else if (o is sbyte b2) + { + if (b2 != i - 1) return true; + } + else if (o is short b3) + { + if (b3 != i - 1) return true; + } + else if (o is ushort b4) + { + if (b4 != i - 1) return true; + } + else if (o is int b5) + { + if (b5 != i - 1) return true; + } + else if (o is uint b6) + { + return true; + } + else if (o is long b7) + { + return true; + } + else if (o is ulong b8) + { + return true; + } } } return false; diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 4ce93c093..730059d32 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.9.0.3288 +3.9.0.3293 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 9a52e2725..df3313a3a 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.9.0.3288' +!define VERSION '3.9.0.3293' diff --git a/SyntaxVisitors/LightSymInfoVisitors/SymInfoCollect1.cs b/SyntaxVisitors/LightSymInfoVisitors/SymInfoCollect1.cs index ce89718e2..6301055a4 100644 --- a/SyntaxVisitors/LightSymInfoVisitors/SymInfoCollect1.cs +++ b/SyntaxVisitors/LightSymInfoVisitors/SymInfoCollect1.cs @@ -32,7 +32,7 @@ namespace PascalABCCompiler.SyntaxTree public override void Enter(syntax_tree_node st) { ScopeSyntax t = null; - switch (st) + /*switch (st) { case program_module p: case unit_module u: @@ -62,9 +62,9 @@ namespace PascalABCCompiler.SyntaxTree case foreach_stmt p: t = new ForeachScopeSyntax(); break; - /*case repeat_node p: // не надо т.к. это StatListScope - t = new RepeatScopeSyntax(); - break;*/ + //case repeat_node p: // не надо т.к. это StatListScope + // t = new RepeatScopeSyntax(); + // break; case case_node p: t = new CaseScopeSyntax(); break; @@ -90,7 +90,65 @@ namespace PascalABCCompiler.SyntaxTree case function_lambda_definition p: t = new LambdaScopeSyntax(); break; + }*/ + if (st is program_module p1 || st is unit_module u) + { + t = new GlobalScopeSyntax(); + Root = t; } + else if (st is procedure_definition p2) + { + var name = p2.proc_header?.name?.meth_name; + if (name == null) + name = "create"; + var attr = p2.proc_header.class_keyword ? Attributes.class_attr : 0; + if (name != null) + if (p2.proc_header is function_header) + AddSymbol(name, SymKind.funcname, null, attr); + else AddSymbol(name, SymKind.procname, null, attr); + t = new ProcScopeSyntax(name); + } + else if (st is statement_list p3) + { + t = new StatListScopeSyntax(); + } + else if (st is for_node p4) + { + t = new ForScopeSyntax(); + } + else if (st is foreach_stmt p5) + { + t = new ForeachScopeSyntax(); + } + else if (st is case_node p6) + { + t = new CaseScopeSyntax(); + } + else if (st is class_definition p7) + { + var td = p7.Parent as type_declaration; + var tname = td == null ? "NONAME" : td.type_name; + if (p7.keyword == class_keyword.Class) + { + AddSymbol(tname, SymKind.classname); + t = new ClassScopeSyntax(tname); + } + else if (p7.keyword == class_keyword.Record) + { + AddSymbol(tname, SymKind.recordname); + t = new RecordScopeSyntax(tname); + } + else if (p7.keyword == class_keyword.Interface) + { + AddSymbol(tname, SymKind.interfacename); + t = new InterfaceScopeSyntax(tname); + } + } + else if (st is function_lambda_definition p8) + { + t = new LambdaScopeSyntax(); + } + if (t != null) { t.Parent = Current; @@ -112,7 +170,7 @@ namespace PascalABCCompiler.SyntaxTree } public override void Exit(syntax_tree_node st) { - switch (st) + /*switch (st) { case program_module p: case procedure_definition pd: @@ -129,6 +187,14 @@ namespace PascalABCCompiler.SyntaxTree if (Current != null) Current = Current.Parent; break; + }*/ + if (st is program_module p || st is procedure_definition pd || st is statement_list stl || + st is for_node f || st is foreach_stmt fe || st is class_definition cd || st is record_type rt || + st is function_lambda_definition fld || st is case_node cas) + { + PreExitScope(st); + if (Current != null) + Current = Current.Parent; } } public override void visit(var_def_statement vd) diff --git a/SyntaxVisitors/PatternsVisitors/PatternsDesugaringVisitor.cs b/SyntaxVisitors/PatternsVisitors/PatternsDesugaringVisitor.cs index df3e91ec0..38c7d3be4 100644 --- a/SyntaxVisitors/PatternsVisitors/PatternsDesugaringVisitor.cs +++ b/SyntaxVisitors/PatternsVisitors/PatternsDesugaringVisitor.cs @@ -354,7 +354,7 @@ namespace SyntaxVisitors.PatternsVisitors private type_definition GetTypeDefinitionForConstParam(expression constParamExpr) { - switch (constParamExpr) + /*switch (constParamExpr) { case string_const type: return new named_type_reference("string"); @@ -366,7 +366,17 @@ namespace SyntaxVisitors.PatternsVisitors return new named_type_reference("integer"); case double_const type: return new named_type_reference("double"); - } + }*/ + if (constParamExpr is string_const) + return new named_type_reference("string"); + if (constParamExpr is char_const) + return new named_type_reference("char"); + if (constParamExpr is int32_const) + return new named_type_reference("integer"); + if (constParamExpr is int64_const) + return new named_type_reference("integer"); + if (constParamExpr is double_const) + return new named_type_reference("double"); return null; } @@ -821,13 +831,14 @@ namespace SyntaxVisitors.PatternsVisitors { List statementsToAdd = null; - switch (isExpression.right) + /*switch (isExpression.right) { case deconstructor_pattern dp: if (dp.const_params_check != null) { var ifToAddConstParamsCheckTo = GetAscendant(isExpression); - ifToAddConstParamsCheckTo.condition = bin_expr.LogicalAnd(ifToAddConstParamsCheckTo.condition, dp.const_params_check); + ifToAddConstParamsCheckTo.condition = + bin_expr.LogicalAnd(ifToAddConstParamsCheckTo.condition, dp.const_params_check); } statementsToAdd = ProcessDesugaringForDeconstructorPattern(isExpression); break; @@ -840,7 +851,30 @@ namespace SyntaxVisitors.PatternsVisitors case const_pattern cp: statementsToAdd = ProcessDesugaringForConstPattern(isExpression); break; + }*/ + if (isExpression.right is deconstructor_pattern dp) + { + if (dp.const_params_check != null) + { + var ifToAddConstParamsCheckTo = GetAscendant(isExpression); + ifToAddConstParamsCheckTo.condition = + bin_expr.LogicalAnd(ifToAddConstParamsCheckTo.condition, dp.const_params_check); + } + statementsToAdd = ProcessDesugaringForDeconstructorPattern(isExpression); } + else if (isExpression.right is collection_pattern) + { + statementsToAdd = ProcessDesugaringForCollectionPattern(isExpression); + } + else if (isExpression.right is tuple_pattern) + { + statementsToAdd = ProcessDesugaringForTuplePattern(isExpression); + } + else if (isExpression.right is const_pattern) + { + statementsToAdd = ProcessDesugaringForConstPattern(isExpression); + } + var enclosingIf = GetAscendant(isExpression); // Если уже обрабатывался ранее (второй встретившийся в том же условии is), то не изменяем if @@ -1113,13 +1147,20 @@ namespace SyntaxVisitors.PatternsVisitors { var firstStatement = GetAscendant(node); - switch (firstStatement) + /*switch (firstStatement) { case if_node _: return PatternLocation.IfCondition; case var_statement _: return PatternLocation.Assign; case assign _: return PatternLocation.Assign; default: return PatternLocation.Unknown; - } + }*/ + if (firstStatement is if_node) + return PatternLocation.IfCondition; + if (firstStatement is var_statement) + return PatternLocation.Assign; + if (firstStatement is assign) + return PatternLocation.Assign; + return PatternLocation.Unknown; } private T GetAscendant(syntax_tree_node node) diff --git a/TreeConverter/TreeConversion/SyntaxTreeVisitorNodes/Patterns.cs b/TreeConverter/TreeConversion/SyntaxTreeVisitorNodes/Patterns.cs index f9795205f..b9741cb4b 100644 --- a/TreeConverter/TreeConversion/SyntaxTreeVisitorNodes/Patterns.cs +++ b/TreeConverter/TreeConversion/SyntaxTreeVisitorNodes/Patterns.cs @@ -140,12 +140,17 @@ namespace PascalABCCompiler.TreeConverter private type_node GetDeconstructorOwner(function_node deconstructor) { - switch (deconstructor) + /*switch (deconstructor) { case common_method_node commonMethod: return commonMethod.cont_type; case common_namespace_function_node commonNamespaseFunction: return GetSelfParameter(commonNamespaseFunction).type; default: return null; - } + }*/ + if (deconstructor is common_method_node commonMethod) + return commonMethod.cont_type; + if (deconstructor is common_namespace_function_node commonNamespaseFunction) + return GetSelfParameter(commonNamespaseFunction).type; + return null; } private bool AreTheSameType(type_node type1, type_node type2) => diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 74e4576b7..d61593d57 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -21364,24 +21364,25 @@ namespace PascalABCCompiler.TreeConverter semantic_check_for_indices(expr); }*/ // Patterns - else if (st.typ is SemanticCheckType.MatchedExpression) // Это безобразие - SemanticCheckType в TreeHelper.cs помещать!!! + else if (st.typ is SemanticCheckType && (SemanticCheckType)st.typ == SemanticCheckType.MatchedExpression) + // Это безобразие - SemanticCheckType в TreeHelper.cs помещать!!! { var expr = st.lst[0] as expression; CheckMatchedExpression(expr); } - else if (st.typ is SemanticCheckType.MatchedExpressionAndType) + else if (st.typ is SemanticCheckType && (SemanticCheckType)st.typ == SemanticCheckType.MatchedExpressionAndType) { var expr = st.lst[0] as expression; var type = st.lst[1] as type_definition; CheckIfCanBeMatched(expr, type); } - else if (st.typ is SemanticCheckType.MatchedExpressionAndExpression) + else if (st.typ is SemanticCheckType && (SemanticCheckType)st.typ == SemanticCheckType.MatchedExpressionAndExpression) { var matchedExpr = st.lst[0] as expression; var patternExpr = st.lst[1] as expression; CheckIfCanBeMatched(matchedExpr, patternExpr); } - else if (st.typ is SemanticCheckType.MatchedTuple) + else if (st.typ is SemanticCheckType && (SemanticCheckType)st.typ == SemanticCheckType.MatchedTuple) { var tuple = st.lst[0] as expression; var length = st.lst[1] as int32_const; @@ -21389,7 +21390,7 @@ namespace PascalABCCompiler.TreeConverter } // !Patterns // Slices - else if (st.typ is SemanticCheckType.SliceAssignmentTypeCompatibility) + else if (st.typ is SemanticCheckType && (SemanticCheckType)st.typ == SemanticCheckType.SliceAssignmentTypeCompatibility) { var to = st.lst[0] as expression; var from = st.lst[1] as expression;