Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Commit ff359c6

Browse files
use AST for most of semantic analysis
1 parent 74e37c0 commit ff359c6

File tree

100 files changed

+1008
-435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1008
-435
lines changed

AST/AbstractSyntaxTree.tree

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
◊using System.Numerics;
66
◊using Adamant.Tools.Compiler.Bootstrap.Core;
77
◊using Adamant.Tools.Compiler.Bootstrap.Core.Operators;
8+
◊using Adamant.Tools.Compiler.Bootstrap.Core.Promises;
89
◊using Adamant.Tools.Compiler.Bootstrap.Framework;
910
◊using Adamant.Tools.Compiler.Bootstrap.Symbols;
1011
◊using Adamant.Tools.Compiler.Bootstrap.Types;
@@ -25,16 +26,16 @@ LocalBinding: Binding = Symbol:'NamedBindingSymbol';
2526
Declaration = File:'CodeFile' Symbol:'Symbol';
2627
/// A declaration that could contain executable code (i.e. invocable declaration or field declaration)
2728
ExecutableDeclaration: Declaration;
28-
InvocableDeclaration: ExecutableDeclaration = Parameters:ConstructorParameter*;
29-
ConcreteInvocableDeclaration: InvocableDeclaration = Body;
29+
InvocableDeclaration: Declaration = Symbol:'InvocableSymbol' Parameters:ConstructorParameter*;
30+
ConcreteInvocableDeclaration: InvocableDeclaration, ExecutableDeclaration = Body;
3031

3132
// ---------- Non-Member Declarations
3233
NonMemberDeclaration: Declaration;
3334
ClassDeclaration: NonMemberDeclaration = Symbol:'ObjectTypeSymbol' Members:MemberDeclaration*;
3435
FunctionDeclaration: NonMemberDeclaration, ConcreteInvocableDeclaration = Symbol:'FunctionSymbol' Parameters:NamedParameter* Body;
3536

3637
// ---------- Member Declarations
37-
MemberDeclaration: Declaration;
38+
MemberDeclaration: Declaration = DeclaringClass:'IClassDeclaration';
3839
MethodDeclaration: MemberDeclaration = Symbol:'MethodSymbol' SelfParameter Parameters:NamedParameter*;
3940
AbstractMethodDeclaration: MethodDeclaration = SelfParameter Parameters:NamedParameter*;
4041
ConcreteMethodDeclaration: MethodDeclaration, ConcreteInvocableDeclaration = SelfParameter Parameters:NamedParameter* Body;
@@ -59,11 +60,11 @@ Body: BodyOrBlock = Statements:BodyStatement*;
5960
Statement;
6061
ResultStatement: Statement, BlockOrResult = Expression;
6162
BodyStatement: Statement;
62-
VariableDeclarationStatement: BodyStatement, LocalBinding = NameSpan:'TextSpan' Symbol:'VariableSymbol' Initializer:Expression?;
63+
VariableDeclarationStatement: BodyStatement, LocalBinding = NameSpan:'TextSpan' Symbol:'VariableSymbol' Initializer:Expression? VariableIsLiveAfter:'Promise<bool>';
6364
ExpressionStatement: BodyStatement = Expression;
6465

6566
// ---------- Expressions
66-
Expression = DataType:'DataType';
67+
Expression = DataType:'DataType' Semantics:'ExpressionSemantics';
6768
AssignableExpression: Expression;
6869
BlockExpression: Expression, BlockOrResult, BodyOrBlock = Statements:Statement*;
6970
NewObjectExpression: Expression = ReferencedSymbol:'ConstructorSymbol' Arguments:Expression*;
@@ -85,7 +86,7 @@ UnaryOperatorExpression: Expression = Fixity:'UnaryOperatorFixity' Operator:'Una
8586
IfExpression: Expression, ElseClause = Condition:Expression ThenBlock:BlockOrResult ElseClause?;
8687
LoopExpression: Expression = Block:BlockExpression;
8788
WhileExpression: Expression = Condition:Expression Block:BlockExpression;
88-
ForeachExpression: Expression, LocalBinding = Symbol:'VariableSymbol' InExpression:Expression Block:BlockExpression;
89+
ForeachExpression: Expression, LocalBinding = Symbol:'VariableSymbol' InExpression:Expression Block:BlockExpression VariableIsLiveAfterAssignment:'Promise<bool>';
8990
BreakExpression: Expression = Value:Expression?;
9091
NextExpression: Expression;
9192
ReturnExpression: Expression = Value:Expression?;
@@ -103,7 +104,7 @@ FunctionInvocationExpression: InvocationExpression = ReferencedSymbol:'FunctionS
103104
MethodInvocationExpression: InvocationExpression = Context:Expression ReferencedSymbol:'MethodSymbol' Arguments:Expression*;
104105

105106
// ---------- Variable Expressions
106-
NameExpression: AssignableExpression = ReferencedSymbol:'NamedBindingSymbol';
107+
NameExpression: AssignableExpression = ReferencedSymbol:'NamedBindingSymbol' VariableIsLiveAfter:'Promise<bool>';
107108
SelfExpression: Expression = ReferencedSymbol:'SelfParameterSymbol' IsImplicit:'bool';
108109
FieldAccessExpression: AssignableExpression = Context:Expression AccessOperator:'AccessOperator' ReferencedSymbol:'FieldSymbol';
109110
BorrowExpression: Expression = ReferencedSymbol:'BindingSymbol' Referent:Expression;

AST/AbstractSyntaxTree.tree.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Numerics;
33
using Adamant.Tools.Compiler.Bootstrap.Core;
44
using Adamant.Tools.Compiler.Bootstrap.Core.Operators;
5+
using Adamant.Tools.Compiler.Bootstrap.Core.Promises;
56
using Adamant.Tools.Compiler.Bootstrap.Framework;
67
using Adamant.Tools.Compiler.Bootstrap.Symbols;
78
using Adamant.Tools.Compiler.Bootstrap.Types;
@@ -64,6 +65,7 @@ public partial interface ILocalBinding : IBinding
6465

6566
[Closed(
6667
typeof(IExecutableDeclaration),
68+
typeof(IInvocableDeclaration),
6769
typeof(INonMemberDeclaration),
6870
typeof(IMemberDeclaration))]
6971
public partial interface IDeclaration : IAbstractSyntax
@@ -73,16 +75,17 @@ public partial interface IDeclaration : IAbstractSyntax
7375
}
7476

7577
[Closed(
76-
typeof(IInvocableDeclaration),
78+
typeof(IConcreteInvocableDeclaration),
7779
typeof(IFieldDeclaration))]
7880
public partial interface IExecutableDeclaration : IDeclaration
7981
{
8082
}
8183

8284
[Closed(
8385
typeof(IConcreteInvocableDeclaration))]
84-
public partial interface IInvocableDeclaration : IExecutableDeclaration
86+
public partial interface IInvocableDeclaration : IDeclaration
8587
{
88+
new InvocableSymbol Symbol { get; }
8689
FixedList<IConstructorParameter> Parameters { get; }
8790
}
8891

@@ -91,7 +94,7 @@ public partial interface IInvocableDeclaration : IExecutableDeclaration
9194
typeof(IConcreteMethodDeclaration),
9295
typeof(IConstructorDeclaration),
9396
typeof(IAssociatedFunctionDeclaration))]
94-
public partial interface IConcreteInvocableDeclaration : IInvocableDeclaration
97+
public partial interface IConcreteInvocableDeclaration : IInvocableDeclaration, IExecutableDeclaration
9598
{
9699
IBody Body { get; }
97100
}
@@ -122,6 +125,7 @@ public partial interface IFunctionDeclaration : INonMemberDeclaration, IConcrete
122125
typeof(IAssociatedFunctionDeclaration))]
123126
public partial interface IMemberDeclaration : IDeclaration
124127
{
128+
IClassDeclaration DeclaringClass { get; }
125129
}
126130

127131
[Closed(
@@ -231,6 +235,7 @@ public partial interface IVariableDeclarationStatement : IBodyStatement, ILocalB
231235
TextSpan NameSpan { get; }
232236
new VariableSymbol Symbol { get; }
233237
IExpression? Initializer { get; }
238+
Promise<bool> VariableIsLiveAfter { get; }
234239
}
235240

236241
public partial interface IExpressionStatement : IBodyStatement
@@ -263,6 +268,7 @@ public partial interface IExpressionStatement : IBodyStatement
263268
public partial interface IExpression : IAbstractSyntax
264269
{
265270
DataType DataType { get; }
271+
ExpressionSemantics Semantics { get; }
266272
}
267273

268274
[Closed(
@@ -359,6 +365,7 @@ public partial interface IForeachExpression : IExpression, ILocalBinding
359365
new VariableSymbol Symbol { get; }
360366
IExpression InExpression { get; }
361367
IBlockExpression Block { get; }
368+
Promise<bool> VariableIsLiveAfterAssignment { get; }
362369
}
363370

364371
public partial interface IBreakExpression : IExpression
@@ -427,6 +434,7 @@ public partial interface IMethodInvocationExpression : IInvocationExpression
427434
public partial interface INameExpression : IAssignableExpression
428435
{
429436
NamedBindingSymbol ReferencedSymbol { get; }
437+
Promise<bool> VariableIsLiveAfter { get; }
430438
}
431439

432440
public partial interface ISelfExpression : IExpression

AST/IAbstractSyntax.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Adamant.Tools.Compiler.Bootstrap.AST
2+
{
3+
public partial interface IAbstractSyntax
4+
{
5+
string ToString();
6+
}
7+
}

AST/IExpression.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Adamant.Tools.Compiler.Bootstrap.Tokens;
2+
3+
namespace Adamant.Tools.Compiler.Bootstrap.AST
4+
{
5+
public partial interface IExpression
6+
{
7+
string ToGroupedString(OperatorPrecedence surroundingPrecedence);
8+
}
9+
}

CST/ExpressionSemanticsExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using Adamant.Tools.Compiler.Bootstrap.Core;
34
using ExhaustiveMatching;
45

56
namespace Adamant.Tools.Compiler.Bootstrap.CST

CST/IExpressionSyntax.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using Adamant.Tools.Compiler.Bootstrap.Core;
23
using Adamant.Tools.Compiler.Bootstrap.Tokens;
34
using Adamant.Tools.Compiler.Bootstrap.Types;
45

CST/IForeachExpressionSyntax.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

CST/INameExpressionSyntax.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ namespace Adamant.Tools.Compiler.Bootstrap.CST
1010
public partial interface INameExpressionSyntax
1111
{
1212
IEnumerable<IPromise<NamedBindingSymbol>> LookupInContainingScope();
13-
bool VariableIsLiveAfter { get; set; }
1413
}
1514
}

CST/IVariableDeclarationStatementSyntax.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

CST/ExpressionSemantics.cs renamed to Core/ExpressionSemantics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Diagnostics.CodeAnalysis;
22

3-
namespace Adamant.Tools.Compiler.Bootstrap.CST
3+
namespace Adamant.Tools.Compiler.Bootstrap.Core
44
{
55
/// <summary>
66
/// The semantics of the value of an expression

0 commit comments

Comments
 (0)