@@ -26,7 +26,7 @@ public AstBuilder( DynamicRuntimeState globalState )
2626
2727 public override IAstNode VisitErrorNode ( IErrorNode node )
2828 {
29- return new ErrorNode ( node . GetSourceLocation ( ) , $ "Syntax Error: { node } " ) ;
29+ return new ErrorNode ( node . GetSourceRange ( ) , $ "Syntax Error: { node } " ) ;
3030 }
3131
3232 public override IAstNode VisitParenExpression ( ParenExpressionContext context )
@@ -36,23 +36,23 @@ public override IAstNode VisitParenExpression( ParenExpressionContext context )
3636
3737 public override IAstNode VisitConstExpression ( ConstExpressionContext context )
3838 {
39- return new ConstantExpression ( context . GetSourceLocation ( ) , context . Value ) ;
39+ return new ConstantExpression ( context . GetSourceRange ( ) , context . Value ) ;
4040 }
4141
4242 public override IAstNode VisitVariableExpression ( VariableExpressionContext context )
4343 {
4444 string varName = context . Name ;
4545 return NamedValues . TryGetValue ( varName , out IVariableDeclaration ? declaration )
46- ? new VariableReferenceExpression ( context . GetSourceLocation ( ) , declaration )
47- : new ErrorNode ( context . GetSourceLocation ( ) , $ "Unknown variable name: { varName } " ) ;
46+ ? new VariableReferenceExpression ( context . GetSourceRange ( ) , declaration )
47+ : new ErrorNode ( context . GetSourceRange ( ) , $ "Unknown variable name: { varName } " ) ;
4848 }
4949
5050 public override IAstNode VisitFunctionCallExpression ( FunctionCallExpressionContext context )
5151 {
5252 Prototype ? function = FindCallTarget ( context . CaleeName ) ;
5353 if ( function is null )
5454 {
55- return new ErrorNode ( context . GetSourceLocation ( ) , $ "Call to unknown function '{ context . CaleeName } '" ) ;
55+ return new ErrorNode ( context . GetSourceRange ( ) , $ "Call to unknown function '{ context . CaleeName } '" ) ;
5656 }
5757
5858 var argNodes = ( from expCtx in context . expression ( )
@@ -67,7 +67,7 @@ select expCtx.Accept( this )
6767 }
6868 }
6969
70- return new FunctionCallExpression ( context . GetSourceLocation ( ) , function , argNodes . Cast < IExpression > ( ) ) ;
70+ return new FunctionCallExpression ( context . GetSourceRange ( ) , function , argNodes . Cast < IExpression > ( ) ) ;
7171 }
7272
7373 public override IAstNode VisitExpression ( ExpressionContext context )
@@ -126,7 +126,7 @@ public override IAstNode VisitFunctionDefinition( FunctionDefinitionContext cont
126126 return body ;
127127 }
128128
129- var retVal = new FunctionDefinition ( context . GetSourceLocation ( )
129+ var retVal = new FunctionDefinition ( context . GetSourceRange ( )
130130 , sig
131131 , exp
132132 , LocalVariables . ToImmutableArray ( )
@@ -150,7 +150,7 @@ public override IAstNode VisitFunctionDefinition( FunctionDefinitionContext cont
150150 public override IAstNode VisitTopLevelExpression ( TopLevelExpressionContext context )
151151 {
152152 BeginFunctionDefinition ( ) ;
153- var sig = new Prototype ( context . GetSourceLocation ( ) , RuntimeState . GenerateAnonymousName ( ) , true ) ;
153+ var sig = new Prototype ( context . GetSourceRange ( ) , RuntimeState . GenerateAnonymousName ( ) , true ) ;
154154 var bodyNode = context . expression ( ) . Accept ( this ) ;
155155 var errors = bodyNode . CollectErrors ( ) ;
156156
@@ -160,7 +160,7 @@ public override IAstNode VisitTopLevelExpression( TopLevelExpressionContext cont
160160 return bodyNode ;
161161 }
162162
163- var retVal = new FunctionDefinition ( context . GetSourceLocation ( ) , sig , bodyExp , true ) ;
163+ var retVal = new FunctionDefinition ( context . GetSourceRange ( ) , sig , bodyExp , true ) ;
164164 RuntimeState . FunctionDefinitions . AddOrReplaceItem ( retVal ) ;
165165 return retVal ;
166166 }
@@ -172,18 +172,18 @@ public override IAstNode VisitUnaryOpExpression( UnaryOpExpressionContext contex
172172 var opKind = RuntimeState . GetUnaryOperatorInfo ( context . Op ) . Kind ;
173173 if ( opKind == OperatorKind . None )
174174 {
175- return new ErrorNode ( context . GetSourceLocation ( ) , $ "invalid unary operator { context . Op } " ) ;
175+ return new ErrorNode ( context . GetSourceRange ( ) , $ "invalid unary operator { context . Op } " ) ;
176176 }
177177
178178 string calleeName = CreateUnaryFunctionName ( context . OpToken ) ;
179179 var function = FindCallTarget ( calleeName ) ;
180180 if ( function == null )
181181 {
182- return new ErrorNode ( context . GetSourceLocation ( ) , $ "reference to unknown unary operator function { calleeName } " ) ;
182+ return new ErrorNode ( context . GetSourceRange ( ) , $ "reference to unknown unary operator function { calleeName } " ) ;
183183 }
184184
185185 var arg = context . Rhs . Accept ( this ) ;
186- return arg is not IExpression exp ? arg : new FunctionCallExpression ( context . GetSourceLocation ( ) , function , exp ) ;
186+ return arg is not IExpression exp ? arg : new FunctionCallExpression ( context . GetSourceRange ( ) , function , exp ) ;
187187 }
188188 #endregion
189189
@@ -193,12 +193,12 @@ public override IAstNode VisitFullsrc( FullsrcContext context )
193193 where child is not TopLevelSemicolonContext
194194 select child . Accept ( this ) ;
195195
196- return new RootNode ( context . GetSourceLocation ( ) , children ) ;
196+ return new RootNode ( context . GetSourceRange ( ) , children ) ;
197197 }
198198
199199 public override IAstNode VisitConditionalExpression ( ConditionalExpressionContext context )
200200 {
201- var expressionSpan = context . GetSourceLocation ( ) ;
201+ var expressionSpan = context . GetSourceRange ( ) ;
202202 var condition = context . Condition . Accept ( this ) ;
203203 if ( condition is not IExpression conditionExp )
204204 {
@@ -258,7 +258,7 @@ public override IAstNode VisitForExpression( ForExpressionContext context )
258258 return bodyNode ;
259259 }
260260
261- retVal = new ForInExpression ( context . GetSourceLocation ( ) , initializer , conditionExp , stepExp , bodyExp ) ;
261+ retVal = new ForInExpression ( context . GetSourceRange ( ) , initializer , conditionExp , stepExp , bodyExp ) ;
262262 }
263263
264264 return retVal ;
@@ -277,7 +277,7 @@ public override IAstNode VisitVarInExpression( VarInExpressionContext context )
277277 }
278278
279279 var bodyNode = context . Scope . Accept ( this ) ;
280- return bodyNode is not IExpression bodyExp ? bodyNode : new VarInExpression ( context . GetSourceLocation ( ) , localVariables , bodyExp ) ;
280+ return bodyNode is not IExpression bodyExp ? bodyNode : new VarInExpression ( context . GetSourceRange ( ) , localVariables , bodyExp ) ;
281281 }
282282 }
283283
@@ -288,8 +288,8 @@ public override IAstNode VisitFunctionPrototype( FunctionPrototypeContext contex
288288
289289 public override IAstNode VisitInitializer ( InitializerContext context )
290290 {
291- var value = ( IExpression ) ( context . Value ? . Accept ( this ) ?? new ConstantExpression ( context . GetSourceLocation ( ) , 0.0 ) ) ;
292- return new LocalVariableDeclaration ( context . GetSourceLocation ( )
291+ var value = ( IExpression ) ( context . Value ? . Accept ( this ) ?? new ConstantExpression ( context . GetSourceRange ( ) , 0.0 ) ) ;
292+ return new LocalVariableDeclaration ( context . GetSourceRange ( )
293293 , context . Name
294294 , value
295295 ) ;
@@ -328,25 +328,25 @@ private IAstNode CreateBinaryOperatorNode( IExpression lhs, BinaryopContext op,
328328 switch ( op . OpToken . Type )
329329 {
330330 case LEFTANGLE :
331- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Less , rhs ) ;
331+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Less , rhs ) ;
332332
333333 case CARET :
334- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Pow , rhs ) ;
334+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Pow , rhs ) ;
335335
336336 case PLUS :
337- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Add , rhs ) ;
337+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Add , rhs ) ;
338338
339339 case MINUS :
340- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Subtract , rhs ) ;
340+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Subtract , rhs ) ;
341341
342342 case ASTERISK :
343- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Multiply , rhs ) ;
343+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Multiply , rhs ) ;
344344
345345 case SLASH :
346- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Divide , rhs ) ;
346+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Divide , rhs ) ;
347347
348348 case ASSIGN :
349- return new BinaryOperatorExpression ( op . GetSourceLocation ( ) , lhs , BuiltInOperatorKind . Assign , rhs ) ;
349+ return new BinaryOperatorExpression ( op . GetSourceRange ( ) , lhs , BuiltInOperatorKind . Assign , rhs ) ;
350350
351351 #region UserBinaryOpExpression
352352 default :
@@ -355,14 +355,14 @@ private IAstNode CreateBinaryOperatorNode( IExpression lhs, BinaryopContext op,
355355 var opKind = RuntimeState . GetBinOperatorInfo ( op . OpToken . Type ) . Kind ;
356356 if ( opKind != OperatorKind . InfixLeftAssociative && opKind != OperatorKind . InfixRightAssociative )
357357 {
358- return new ErrorNode ( op . GetSourceLocation ( ) , $ "Invalid binary operator '{ op . OpToken . Text } '" ) ;
358+ return new ErrorNode ( op . GetSourceRange ( ) , $ "Invalid binary operator '{ op . OpToken . Text } '" ) ;
359359 }
360360
361361 string calleeName = CreateBinaryFunctionName ( op . OpToken ) ;
362362 Prototype ? callTarget = FindCallTarget ( calleeName ) ;
363363 return callTarget is null
364- ? new ErrorNode ( op . GetSourceLocation ( ) , $ "Unary operator function '{ calleeName } ' not found" )
365- : new FunctionCallExpression ( op . GetSourceLocation ( ) , callTarget , lhs , rhs ) ;
364+ ? new ErrorNode ( op . GetSourceRange ( ) , $ "Unary operator function '{ calleeName } ' not found" )
365+ : new FunctionCallExpression ( op . GetSourceRange ( ) , callTarget , lhs , rhs ) ;
366366 }
367367 #endregion
368368 }
@@ -385,7 +385,7 @@ private IAstNode BuildPrototype( PrototypeContext context, string name )
385385 name = context . Name ;
386386 }
387387
388- var retVal = new Prototype ( context . GetSourceLocation ( )
388+ var retVal = new Prototype ( context . GetSourceRange ( )
389389 , name
390390 , false
391391 , context . Parent is ExternalDeclarationContext
@@ -397,7 +397,7 @@ private IAstNode BuildPrototype( PrototypeContext context, string name )
397397 {
398398 if ( existingPrototype . Parameters . Count != retVal . Parameters . Count )
399399 {
400- return new ErrorNode ( context . GetSourceLocation ( ) , "Declaration incompatible with previous declaration" ) ;
400+ return new ErrorNode ( context . GetSourceRange ( ) , "Declaration incompatible with previous declaration" ) ;
401401 }
402402 }
403403
0 commit comments