Skip to content

Commit

Permalink
(#72) Parser: support basic struct parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Feb 10, 2022
1 parent e925b44 commit f67002c
Show file tree
Hide file tree
Showing 31 changed files with 223 additions and 61 deletions.
28 changes: 26 additions & 2 deletions Cesium.Ast/Declarations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,35 @@ public record Declaration(
public record InitDeclarator(Declarator Declarator, Initializer? Initializer = null);

public interface IDeclarationSpecifier { }

// 6.7.1 Storage-class specifiers
public record StorageClassSpecifier(string Name) : IDeclarationSpecifier;

// 6.7.2 Type specifiers
public record TypeSpecifier(string TypeName) : IDeclarationSpecifier;
public interface ITypeSpecifier : ISpecifierQualifierListItem, IDeclarationSpecifier { }

public record SimpleTypeSpecifier(string TypeName) : ITypeSpecifier;
public record StructOrUnionSpecifier(
ComplexTypeKind TypeKind,
string? Identifier,
ImmutableArray<StructDeclaration> StructDeclarations) : ITypeSpecifier;

// 6.7.2.1 Structure and union specifiers
public enum ComplexTypeKind
{
Struct
}

public record StructDeclaration(
ImmutableArray<ISpecifierQualifierListItem> SpecifiersQualifiers,
ImmutableArray<StructDeclarator>? Declarators);

public interface ISpecifierQualifierListItem {}

public record StructDeclarator(Declarator Declarator);

// 6.7.3 Type qualifiers
public record TypeQualifier(string Name) : IDeclarationSpecifier;
public record TypeQualifier(string Name) : IDeclarationSpecifier, ISpecifierQualifierListItem;

// 6.7.7 Type names
public record AbstractDeclarator(Pointer? Pointer = null, IDirectAbstractDeclarator? DirectAbstractDeclarator = null);
Expand Down
2 changes: 1 addition & 1 deletion Cesium.CodeGen/Ir/DeclarationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static (IType, string? cliImportMemberName) GetPrimitiveInfo(
{
switch (specifier)
{
case TypeSpecifier ts:
case SimpleTypeSpecifier ts:
if (type != null)
throw new NotSupportedException(
$"Unsupported type definition after already resolved type {type}: {ts}.");
Expand Down
2 changes: 1 addition & 1 deletion Cesium.CodeGen/Ir/ParametersInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ParametersInfo Of(ParameterTypeList parameters)
if (specifiers.Length != 1 || declarator != null || abstractDeclarator != null) isVoid = false;
else
{
isVoid = specifiers.Single() is TypeSpecifier { TypeName: "void" };
isVoid = specifiers.Single() is SimpleTypeSpecifier { TypeName: "void" };
}
}
else isVoid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"MemberName": "System.Runtime.InteropServices.Marshal::AllocHGlobal"
},
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -30,7 +30,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down Expand Up @@ -63,7 +63,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"MemberName": "Foo.Bar::Baz"
},
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down Expand Up @@ -40,7 +40,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -65,7 +65,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down Expand Up @@ -43,7 +43,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -68,7 +68,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -45,7 +45,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -30,7 +30,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "void"
}
],
Expand All @@ -26,7 +26,7 @@
"$type": "Cesium.Ast.ParameterDeclaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "char"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand All @@ -30,7 +30,7 @@
"$type": "Cesium.Ast.Declaration, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"$type": "Cesium.Ast.FunctionDefinition, Cesium.Ast",
"Specifiers": [
{
"$type": "Cesium.Ast.TypeSpecifier, Cesium.Ast",
"$type": "Cesium.Ast.SimpleTypeSpecifier, Cesium.Ast",
"TypeName": "int"
}
],
Expand Down
Loading

0 comments on commit f67002c

Please sign in to comment.