public static IEnumerable <MemberDeclarationSyntax> Transpile(this Syntax.TypeDefinitionSyntax typeDefinitionNode)
        {
            _ = typeDefinitionNode ?? throw new ArgumentNullException(nameof(typeDefinitionNode));

            var identifier = SyntaxFactory.Identifier(
                SyntaxTriviaList.Empty,
                SyntaxKind.IdentifierToken,
                typeDefinitionNode.NewTypeNameNode.TranspileIdentifier(),
                typeDefinitionNode.NewTypeNameNode.ValueText,
                SyntaxTriviaList.Empty); // todo: comment?

            if (TranspileToEnumHandler.IsTypeEnum(typeDefinitionNode.NewTypeNameNode.ValueText, out _))
            {
                var enumDeclr = SyntaxFactory.EnumDeclaration(
                    new SyntaxList <AttributeListSyntax>(SyntaxFactory.AttributeList()),
                    new SyntaxTokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)),
                    identifier,
                    null,
                    default);

                TranspileToEnumHandler.AddEnum(enumDeclr);
                yield break;
            }

            var declr = SyntaxFactory.ClassDeclaration(
                default(SyntaxList <AttributeListSyntax>),
                new SyntaxTokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)),
                identifier,
                null,
                null,
                default(SyntaxList <TypeParameterConstraintClauseSyntax>),
                default(SyntaxList <MemberDeclarationSyntax>))
                        .AddMembers(SyntaxFactory.ConstructorDeclaration(
Пример #2
0
        public void EmitDefinition(Syntax.TypeDefinitionSyntax pNode)
        {
            //Get field types
            var name   = CurrentStruct.GetFullName();
            var fields = CurrentStruct.GetFields();

            LLVMTypeRef[] types = new LLVMTypeRef[fields.Length];
            for (int i = 0; i < types.Length; i++)
            {
                types[i] = SmallTypeCache.GetLLVMType(fields[i].Type, this);
            }

            //Emit struct
            var t = LLVM.StructCreateNamed(_context, name);

            t.StructSetBody(types, false);
            Cache.SetLLVMType(name, t);
        }
Пример #3
0
 public static void ImplementationMissingMethod(string pMethod, Syntax.TypeDefinitionSyntax pType, TextSpan pSpan)
 {
     _error.WriteError($"Implementation of trait {pType.Name} is missing method {pMethod}", pSpan);
 }
Пример #4
0
 public static void CircularReference(Syntax.TypeDefinitionSyntax pType, TextSpan pSpan)
 {
     _error.WriteError($"Found circular reference in struct {pType.Name}", pSpan);
 }
Пример #5
0
 public static void DuplicateField(string pField, Syntax.TypeDefinitionSyntax pType, TextSpan pSpan)
 {
     _error.WriteError($"Duplicate field definition '{pField}' within struct {pType.Name}", pSpan);
 }