public void Instantiate(AstTypeReferenceType type)
        {
            Ast.Guard(type.TemplateArguments.Count() == TemplateDefinition.TemplateParameters.Count(),
                      $"The number of template parameters do not match the TemplateDefinition {TemplateDefinition.Identifier.NativeFullName}");

            Context = type.Context;
            this.SetIdentifier(type.Identifier.MakeCopy());

            _templateArguments = new AstTemplateArgumentMap(
                TemplateDefinition.TemplateParameters, type.TemplateArguments);

            foreach (var field in TemplateDefinition.Fields)
            {
                var fieldDef = new AstTypeDefinitionStructField();
                fieldDef.SetIdentifier(field.Identifier.MakeCopy());
                if (field.IsTemplate)
                {
                    var templateArgument = _templateArguments.LookupArgument(field.TypeReference.Identifier);
                    Ast.Guard(templateArgument, $"No Template Argument was found for {field.TypeReference.Identifier.CanonicalFullName}");
                    fieldDef.SetTypeReference(templateArgument !.TypeReference.MakeCopy());
                }
                else
                {
                    fieldDef.SetTypeReference(field.TypeReference.MakeCopy());
                }

                this.AddField(fieldDef);
                type.Symbol.SymbolTable.Add(fieldDef);
            }
        }
Beispiel #2
0
        public void Clone(AstFunctionReference functionRef,
                          AstFunctionDefinition templateFunctionDef, AstTemplateInstanceFunction instanceFunction,
                          AstTemplateArgumentMap argumentMap)
        {
            if (templateFunctionDef is AstFunctionDefinition functionDef)
            {
                _argumentMap = argumentMap;
                _current.SetCurrent(instanceFunction.FunctionType);
                _current.SetCurrent(instanceFunction);
                functionDef.VisitChildren(this);
                _current.RevertCurrent();
                _current.RevertCurrent();

                instanceFunction.SetIdentifier(functionRef.Identifier);

                AstSymbolTable symbols;
                if (templateFunctionDef is IAstSymbolTableSite symbolSite)
                {
                    // registered in impl function defs symbol table
                    symbols = symbolSite.SymbolTable;
                }
                else
                {
                    // intrinsics are registered in root symbol table
                    symbols = functionRef.Symbol.SymbolTable.GetRootTable();
                }

                instanceFunction.CreateSymbols(symbols);
            }
            else
            {
                throw new NotImplementedException(
                          "[Interop] .NET Generics not implemented yet.");
            }
        }
        public void Instantiate(CompilerContext context, AstFunctionReference function)
        {
            Context            = function.Context;
            _templateArguments = new AstTemplateArgumentMap(
                TemplateDefinition.TemplateParameters, function.TemplateArguments);

            var cloner = new AstNodeCloner(context, TemplateDefinition.Indent);

            cloner.Clone(function, TemplateDefinition, this, _templateArguments);
        }