Ejemplo n.º 1
0
    private ES_TypeInfo *GetType(SymbolStack <FrontendSymbol> symbols, SourceData src, ES_AstTypeDeclaration_TypeName typeName)
    {
        var idPool = Environment !.IdPool;

        Debug.Assert(typeName.TypeName.Parts.Length > 0);

        if (typeName.Namespace is not null)
        {
            using var namespaceChars = typeName.Namespace.ToPooledChars();
            using var nameChars      = typeName.TypeName.ToPooledChars();
            var namespaceId = idPool.GetIdentifier(namespaceChars);
            var nameId      = idPool.GetIdentifier(nameChars);

            var type = Environment !.GetFullyQualifiedType(namespaceId, nameId);

            if (type == null)
            {
                var err = ES_FrontendErrors.GenCantFindSymbol(typeName.ToString(), src, typeName.NodeBounds);
                errorList.Add(err);

                return(Environment.TypeUnknownValue);
            }

            return(type);
        }
        else
        {
            var typeParts = typeName.TypeName.Parts;
            var typeId    = idPool.GetIdentifier(typeParts [0].Text.Span);

            var symbol = symbols.GetSymbol(typeId);

            if (symbol.Tag == FrontendSymbolType.None)
            {
                var err = ES_FrontendErrors.GenCantFindSymbol(typeParts [0].Text.Span.GetPooledString(), typeParts [0]);
                errorList.Add(err);

                return(Environment.TypeUnknownValue);
            }
            else if (symbol.Tag == FrontendSymbolType.Variable)
            {
                var err = ES_FrontendErrors.GenVarUsedAsType(typeParts [0].Text.Span.GetPooledString(), typeParts [0]);
                errorList.Add(err);

                return(Environment.TypeUnknownValue);
            }
            else if (symbol.Tag == FrontendSymbolType.Function)
            {
                var err = ES_FrontendErrors.GenFuncUsedAsType(typeParts [0].Text.Span.GetPooledString(), typeParts [0]);
                errorList.Add(err);

                return(Environment.TypeUnknownValue);
            }
            else if (symbol.Tag != FrontendSymbolType.Type)
            {
                throw new NotImplementedException("Not implemented?");
            }

            if (typeParts.Length > 1)
            {
                throw new NotImplementedException("[TODO] Nested types not implemented yet.");
            }

            return(symbol.MatchType());
        }
    }