Skip to content

Commit

Permalink
compiler crash outputs code location
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed May 3, 2024
1 parent 3253e5a commit 58e3ac5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Peachpie.CodeAnalysis/FlowAnalysis/Worklist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,29 @@ public void PingReturnUpdate(ExitBlock updatedExit, T callingBlock)

void Process(T block)
{
var list = _analyzers;
for (int i = 0; i < list.Count; i++)
try
{
list[i](block);
var list = _analyzers;
for (int i = 0; i < list.Count; i++)
{
list[i](block);
}
}
catch (Exception e)
{
if (block.TryGetPath(out var path, out var line))
{
// write more information to the output:
Console.WriteLine(
$"{e.Message} caused by block at at {path}:{line}"
);
}
// block.FlowState.Routine.

// block.FlowState.Routine.
//CompilerLogSource.Log.Count("BoundBlockProcessings");

//CompilerLogSource.Log.Count("BoundBlockProcessings");
throw;
}
}

/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions src/Peachpie.CodeAnalysis/Utilities/AstUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Pchp.CodeAnalysis.Semantics;
using System.Runtime.InteropServices;
using Pchp.CodeAnalysis.FlowAnalysis;
using Pchp.CodeAnalysis.Semantics.Graph;

namespace Pchp.CodeAnalysis
{
Expand Down Expand Up @@ -357,6 +358,37 @@ public static Microsoft.CodeAnalysis.Text.TextSpan GetMoveNextSpan(this ForeachS
return default;
}

public static bool TryGetPath(this BoundBlock block, out string path, out int line)
{
path = null;
line = -1;

if (block != null)
{
if (block.PhpSyntax != null)
{
var unit = block.PhpSyntax.ContainingSourceUnit;
if (unit != null)
{
path = unit.FilePath;

if (block.PhpSyntax.Span.IsValid)
{
line = unit.GetLineFromPosition(block.PhpSyntax.Span.Start);
}
}

//if (path == null && block.FlowState?.Routine != null)
//{
// path = block.FlowState.Routine...
//}
}
}

//
return path != null;
}

sealed class ElementVisitor<TElement> : TreeVisitor
where TElement : LangElement
{
Expand Down

0 comments on commit 58e3ac5

Please sign in to comment.