Example #1
0
    private void CreateTypes(ref TranslationUnitData transUnit)
    {
        var idPool = Environment !.IdPool;

        foreach (ref var astUnit in transUnit.AstUnits.Span)
        {
            foreach (var nm in astUnit.Ast.Namespaces)
            {
                ArrayPointer <byte> namespaceName;
                using (var nameArr = nm.NamespaceName.ToPooledChars())
                    namespaceName = idPool.GetIdentifier(nameArr);

                var namespaceBuilder = EnvironmentBuilder !.GetOrCreateNamespace(namespaceName);

                foreach (var type in nm.Contents)
                {
                    switch (type)
                    {
                    case ES_AstClassDefinition classDef:
                        CreateTypes_Aggregate(ref transUnit, namespaceBuilder, ES_TypeTag.Class, classDef);
                        break;

                    case ES_AstStructDefinition structDef:
                        CreateTypes_Aggregate(ref transUnit, namespaceBuilder, ES_TypeTag.Struct, structDef);
                        break;

                    case ES_AstEnumDefinition enumDef: {
                        var typeName = Environment !.IdPool.GetIdentifier(enumDef.Name.Text.Span);

                        if (namespaceBuilder.CheckTypeExists(typeName, null) != null)
                        {
                            errorList.Add(ES_FrontendErrors.GenTypeAlreadyDefined(
                                              namespaceBuilder.NamespaceData.NamespaceNameString,
                                              enumDef.Name.Text.Span.GetPooledString(),
                                              enumDef.Name
                                              ));
                            break;
                        }

                        var builder = namespaceBuilder.GetOrCreateEnum(enumDef.AccessModifier, typeName, transUnit.Name);
                        EnvironmentBuilder !.PointerAstMap.Add((IntPtr)builder.EnumData, enumDef);

                        break;
                    }

                    case ES_AstFunctionDefinition:
                        // Functions are handled in a pass of their own.
                        break;

                    default:
                        throw new NotImplementedException("Node type not implemented yet.");
                    }
                }
            }
        }
    }
Example #2
0
    private Pointer <ES_TypeInfo> GenerateBuiltinTypes_Float(ES_FloatSize size)
    {
        var floatDataPtr = EnvironmentBuilder !.MemoryManager.GetMemory <ES_FloatTypeData> ();
        var namePtr      = Environment !.IdPool.GetIdentifier(ES_PrimitiveTypes.GetFloatName(size));
        var fqn          = new ES_FullyQualifiedName(Environment.GlobalTypesNamespace, namePtr);

        *floatDataPtr = new ES_FloatTypeData(ES_AccessModifier.Public, ArrayPointer <byte> .Null, fqn, size);

        return(new Pointer <ES_TypeInfo> (&floatDataPtr->TypeInfo));
    }
Example #3
0
    private Pointer <ES_TypeInfo> GenerateBuiltinTypes_Simple(ReadOnlySpan <char> name, ES_TypeTag tag, int runtimeSize)
    {
        var voidDataPtr = EnvironmentBuilder !.MemoryManager.GetMemory <ES_TypeInfo> ();
        var namePtr     = Environment !.IdPool.GetIdentifier(name);
        var fqn         = new ES_FullyQualifiedName(Environment.GlobalTypesNamespace, namePtr);

        *voidDataPtr = new ES_TypeInfo(tag, ES_AccessModifier.Public, ES_TypeFlag.NoRefs | ES_TypeFlag.NoNew, ArrayPointer <byte> .Null, fqn);
        voidDataPtr->RuntimeSize = runtimeSize;

        return(new Pointer <ES_TypeInfo> (voidDataPtr));
    }
Example #4
0
    private ES_NamespaceData?GetNamespace(SourceData src, ES_AstNodeBounds nodeBounds, ReadOnlySpan <char> namespaceStr)
    {
        var namespaceName = Environment !.IdPool.GetIdentifier(namespaceStr);

        if (!Environment !.Namespaces.TryGetValue(namespaceName, out var namespaceData))
        {
            var err = ES_FrontendErrors.GenNamespaceDoesntExist(
                namespaceStr.GetPooledString(),
                src,
                nodeBounds
                );
            errorList.Add(err);
            return(null);
        }

        return(namespaceData);
    }
Example #5
0
    private void CreateTypes_Aggregate(
        ref TranslationUnitData transUnit, ES_NamespaceData.Builder namespaceBuilder,
        ES_TypeTag type, ES_AstAggregateDefinition typeDef
        )
    {
        var namespaceName = namespaceBuilder.NamespaceData.NamespaceName;
        var typeName      = Environment !.IdPool.GetIdentifier(typeDef.Name.Text.Span);

        if (namespaceBuilder.CheckTypeExists(typeName, null) != null)
        {
            errorList.Add(ES_FrontendErrors.GenTypeAlreadyDefined(
                              namespaceBuilder.NamespaceData.NamespaceNameString,
                              typeDef.Name.Text.Span.GetPooledString(),
                              typeDef.Name
                              ));
            return;
        }

        ES_TypeInfo *typeData = null;

        if (type == ES_TypeTag.Class)
        {
            var classBuilder = namespaceBuilder.GetOrCreateClass(typeDef.AccessModifier, typeName, transUnit.Name);
            typeData = &classBuilder.ClassData->TypeInfo;
        }
        else if (type == ES_TypeTag.Struct)
        {
            var structBuilder = namespaceBuilder.GetOrCreateStruct(typeDef.AccessModifier, typeName, transUnit.Name);
            typeData = &structBuilder.StructData->TypeInfo;
        }
        else
        {
            Debug.Fail("Not implemented/supported.");
        }

        EnvironmentBuilder !.PointerAstMap.Add((IntPtr)typeData, typeDef);
    }