-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 18 additions & 8 deletions
26
NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Declarations/EnumDeclaration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; | ||
using Socordia.CodeAnalysis.AST; | ||
using Socordia.CodeAnalysis.AST.Declarations; | ||
using Socordia.CodeAnalysis.AST.TypeNames; | ||
|
||
/* | ||
public sealed class EnumDeclaration : IParsePoint | ||
namespace Socordia.CodeAnalysis.Parsing.ParsePoints.Declarations; | ||
|
||
public sealed class EnumDeclarationParser : IParsePoint | ||
{ | ||
public static LNode Parse(TokenIterator iterator, Parser parser) | ||
public static AstNode Parse(TokenIterator iterator, Parser parser) | ||
{ | ||
var keywordToken = iterator.Prev; | ||
|
||
var nameToken = iterator.Match(TokenType.Identifier); | ||
TypeName baseType = new SimpleTypeName("i32"); | ||
if (iterator.ConsumeIfMatch(TokenType.Colon)) | ||
{ | ||
baseType = TypeNameParser.Parse(parser); | ||
} | ||
|
||
iterator.Match(TokenType.OpenCurly); | ||
|
||
var members = ParsingHelpers.ParseSeperated<EnumMemberDeclaration>(parser, TokenType.CloseCurly); | ||
List<AstNode> members = []; //ParsingHelpers.ParseUntil<TypeMemberDeclaration>(parser, TokenType.CloseCurly); | ||
|
||
iterator.Match(TokenType.CloseCurly); //remove if member parsing works | ||
|
||
return SyntaxTree.Enum(LNode.Id(nameToken.Text), members).WithRange(keywordToken, iterator.Prev); | ||
return new EnumDeclaration(nameToken.Text, baseType, members); | ||
} | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Reflection; | ||
using DistIL.AsmIO; | ||
using MrKWatkins.Ast.Listening; | ||
using Socordia.CodeAnalysis.AST; | ||
using Socordia.CodeAnalysis.AST.Declarations; | ||
|
||
namespace SocordiaC.Compilation; | ||
|
||
public class CollectEnumListener : Listener<Driver, AstNode, EnumDeclaration> | ||
{ | ||
protected override void ListenToNode(Driver context, EnumDeclaration node) | ||
{ | ||
var type = context.Compilation.Module.CreateType(context.Settings.RootNamespace, node.Name, | ||
GetModifiers(node), context.Compilation.Module.Resolver.Import(typeof(Enum))); | ||
|
||
type.CreateField("value__", new TypeSig(Utils.GetTypeFromNode(node.BaseType, type)), FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName); | ||
|
||
// .field public static literal valuetype Color R = int32(0) | ||
//type.CreateField("R", new TypeSig(type), FieldAttributes.Public | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.HasDefault, 42); | ||
} | ||
|
||
private TypeAttributes GetModifiers(Declaration node) | ||
{ | ||
var attrs = TypeAttributes.Public; | ||
|
||
foreach (var modifier in node.Modifiers) | ||
{ | ||
attrs |= modifier switch | ||
{ | ||
Modifier.Static => TypeAttributes.Sealed | TypeAttributes.Abstract, | ||
Modifier.Internal => TypeAttributes.NotPublic, | ||
Modifier.Public => TypeAttributes.Public, | ||
_ => throw new NotImplementedException() | ||
}; | ||
} | ||
|
||
if (node.Modifiers.Contains(Modifier.Private) || node.Modifiers.Contains(Modifier.Internal)) | ||
{ | ||
attrs &= ~TypeAttributes.Public; | ||
} | ||
|
||
return attrs | TypeAttributes.Sealed; | ||
} | ||
|
||
protected override bool ShouldListenToChildren(Driver context, AstNode node) => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,14 @@ internal class Hello : System.Text.StringBuilder | |
static class Blub | ||
{ | ||
|
||
} | ||
|
||
enum Color | ||
{ | ||
|
||
} | ||
|
||
enum ShortColor : i8 | ||
{ | ||
|
||
} |