/// <summary> /// According to current <see cref="ILBuilder.SeqPointsOpt"/>, gets file name and position in the source code currently being emitted. /// </summary> public static string GuessSourceLocation(ILBuilder il, IPhpOperation op = null, SourceRoutineSymbol routine = null, MethodSymbol debugroutine = null) { var syntax = op?.PhpSyntax; if (syntax != null) { // get location from AST var unit = syntax.ContainingSourceUnit; unit.GetLineColumnFromPosition(syntax.Span.Start, out int line, out int col); return($"{unit.FilePath}({line + 1}, {col + 1})"); } else if (il.SeqPointsOpt != null && il.SeqPointsOpt.Count != 0) { // get location from last sequence point var pt = il.SeqPointsOpt.Last(); ((PhpSyntaxTree)pt.SyntaxTree).Source.GetLineColumnFromPosition(pt.Span.Start, out int line, out int col); return($"{pt.SyntaxTree.FilePath}({line + 1}, {col + 1})"); } else if (routine != null) { return($"{routine.ContainingFile.SyntaxTree.FilePath} in '{routine.RoutineName}'"); } else if (debugroutine != null) { var method = $"{debugroutine.ContainingType.GetFullName()}::{debugroutine.RoutineName}"; if (debugroutine.ContainingType is SourceTypeSymbol srctype) { return($"{srctype.ContainingFile.SyntaxTree.FilePath} in {method}"); } return(method); } else { return(null); } }
void CannotInstantiate(IPhpOperation op, string kind, BoundTypeRef t) { _diagnostics.Add(_routine, op.PhpSyntax, ErrorCode.ERR_CannotInstantiateType, kind, t.ResolvedType); }
/// <summary>Visits given operation.</summary> protected virtual void Accept(IPhpOperation x) => x?.Accept(this);
/// <summary>Visits given operation.</summary> protected TResult Accept(IPhpOperation x) => (x != null) ? x.Accept(this) : default;
/// <summary> /// Gets <see cref="System.NotImplementedException"/> with aproximate location of the error. /// </summary> public static Exception NotImplementedException(ILBuilder il, string message = null, IPhpOperation op = null, SourceRoutineSymbol routine = null, MethodSymbol debugroutine = null) { string location = null; var syntax = op?.PhpSyntax; if (syntax != null) { // get location from AST var unit = syntax.ContainingSourceUnit; unit.GetLineColumnFromPosition(syntax.Span.Start, out int line, out int col); location = $"{unit.FilePath}({line}, {col})"; } else if (il.SeqPointsOpt != null && il.SeqPointsOpt.Count != 0) { // get location from last sequence point var pt = il.SeqPointsOpt.Last(); ((PhpSyntaxTree)pt.SyntaxTree).Source.GetLineColumnFromPosition(pt.Span.Start, out int line, out int col); location = $"{pt.SyntaxTree.FilePath}({line}, {col})"; } else if (routine != null) { location = $"{routine.ContainingFile.SyntaxTree.FilePath} in '{routine.RoutineName}'"; } else if (debugroutine != null) { location = $"{debugroutine.ContainingType.GetFullName()}::{debugroutine.RoutineName}"; if (debugroutine.ContainingType is SourceTypeSymbol srctype) { location = $"{srctype.ContainingFile.SyntaxTree.FilePath} in {location}"; } } else { location = "<unknown>"; } // return(new NotImplementedException($"{message} not implemented at {location}")); }
/// <summary> /// Gets <see cref="System.NotImplementedException"/> with aproximate location of the error. /// </summary> public static Exception NotImplementedException(this CodeGenerator cg, string message = null, IPhpOperation op = null) { return(NotImplementedException(cg.Builder, message, op: op, routine: cg.Routine, debugroutine: cg.DebugRoutine)); }
/// <summary> /// Gets <see cref="System.NotImplementedException"/> with aproximate location of the error. /// </summary> public static NotImplementedException NotImplementedException(ILBuilder il, string message = null, IPhpOperation op = null, SourceRoutineSymbol routine = null, MethodSymbol debugroutine = null) { var location = GuessSourceLocation(il, op, routine, debugroutine) ?? "<unknown>"; // return(new NotImplementedException($"{message} not implemented at {location}")); }
public static string GuessSourceLocation(CodeGenerator cg, IPhpOperation op = null) => GuessSourceLocation(cg.Builder, op, cg.Routine, cg.DebugRoutine);