Skip to content

Commit

Permalink
updated parser, 8.2 language level added, 8.2 default language level
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed May 22, 2023
1 parent f629a42 commit 531bcf0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<PeachpieLibraryRegularExpressionsVersion>1.6.0</PeachpieLibraryRegularExpressionsVersion>
<MySqlConnectorVersion>2.0.0</MySqlConnectorVersion>
<ParserVersion>8.2.12198</ParserVersion>
<ParserVersion>8.2.13126</ParserVersion>
<PeachpieMicrosoftCodeAnalysisVersion>3.7.1</PeachpieMicrosoftCodeAnalysisVersion>

</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,14 @@ public override void VisitIfStmt(IfStmt x)
var end = NewBlock();

var conditions = x.Conditions;
Debug.Assert(conditions.Count != 0);
Debug.Assert(conditions.Length != 0);
BoundBlock elseBlock = null;
for (int i = 0; i < conditions.Count; i++)
for (int i = 0; i < conditions.Length; i++)
{
var cond = conditions[i];
if (cond.Condition != null) // if (Condition) ...
{
elseBlock = (i == conditions.Count - 1) ? end : NewBlock();
elseBlock = (i == conditions.Length - 1) ? end : NewBlock();
_current = Connect(_current, NewBlock(), elseBlock, cond.Condition);
}
else // else ...
Expand Down
2 changes: 2 additions & 0 deletions src/Peachpie.CodeAnalysis/Syntax/AdditionalSyntaxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public TValue TokenValue

public string TokenText => _provider.TokenText;

public ReadOnlySpan<char> TokenTextSpan => _provider.TokenTextSpan;

public IDocBlock DocComment { get => _provider.DocComment; set => _provider.DocComment = value; }

public int GetNextToken()
Expand Down
16 changes: 11 additions & 5 deletions src/Peachpie.CodeAnalysis/Syntax/NodesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ FunctionCall WithGenericTypes(FunctionCall call, Span nameSpan)
return call;
}

public override LangElement GlobalCode(Span span, IEnumerable<LangElement> statements, NamingContext context)
public override LangElement GlobalCode(Span span, Statement[] statements, NamingContext context)
{
Debug.Assert(_annotations == null || _annotations.Count == 0, $"file {this.SourceUnit.FilePath} contains CLR annotations we did not consume! Probably a bogus in AdditionalSyntaxProvider."); // all parsed custom annotations have to be consumed

Expand Down Expand Up @@ -189,13 +189,19 @@ public override LangElement YieldFrom(Span span, LangElement fromExpr)
return AddAndReturn(ref _yieldNodes, base.YieldFrom(span, fromExpr));
}

public Literal Literal(Span span, long lvalue) => new LongIntLiteral(span, lvalue); // overload to avoid boxing
public override LangElement Literal(Span span, double value, ReadOnlySpan<char> originalValue)
{
return base.Literal(span, value, originalValue: null);
}

public Literal Literal(Span span, double dvalue) => new DoubleLiteral(span, dvalue); // overload to avoid boxing
public override LangElement Literal(Span span, long value, ReadOnlySpan<char> originalValue)
{
return base.Literal(span, value, originalValue: null);
}

public override LangElement Literal(Span span, object value, string originalValue)
public override LangElement Literal(Span span, object value, ReadOnlySpan<char> originalValue)
{
return base.Literal(span, value, originalValue: null); // discard the original value string, not needed, free some memory
return base.Literal(span, value, originalValue: null);
}

public override LangElement EncapsedExpression(Span span, LangElement expression, Tokens openDelimiter) => expression;
Expand Down
5 changes: 3 additions & 2 deletions src/Peachpie.CodeAnalysis/Syntax/PhpSyntaxTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ public class PhpSyntaxTree : SyntaxTree

{ new Version(8, 0), LanguageFeatures.Php80Set },
{ new Version(8, 1), LanguageFeatures.Php81Set },
{ new Version(8, 2), LanguageFeatures.Php82Set },
};

public static Version LatestLanguageVersion => SupportedLanguageVersions.Max();

public static Version DefaultLanguageVersion => new Version(8, 0);
public static Version DefaultLanguageVersion => new Version(8, 2);

public static IReadOnlyCollection<Version> SupportedLanguageVersions => s_langversions.Keys;

Expand Down Expand Up @@ -178,7 +179,7 @@ static LanguageFeatures GetLanguageFeatures(PhpParseOptions options)
{
// Parser leaves factory.Root to null in the case of syntax errors -> create a proxy syntax node
var fullSpan = new Devsense.PHP.Text.Span(0, sourceText.Length);
result.Root = new GlobalCode(fullSpan, ImmutableArray<Statement>.Empty, unit);
result.Root = new GlobalCode(fullSpan, Array.Empty<Statement>(), unit);
}

//
Expand Down
2 changes: 2 additions & 0 deletions src/Peachpie.CodeAnalysis/Syntax/PhpTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public string TokenText
}
}

public ReadOnlySpan<char> TokenTextSpan => TokenText.AsSpan();

public IDocBlock DocComment
{
get => _docblock;
Expand Down

0 comments on commit 531bcf0

Please sign in to comment.