예제 #1
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.");
            }
        }
예제 #2
0
        public override void VisitFunctionDefinition(AstFunctionDefinition function)
        {
            if (function is AstFunctionDefinitionImpl functionDef)
            {
                var fnDef = new AstFunctionDefinitionImpl((Function_defContext)functionDef.Context !);
                fnDef.SetIdentifier(functionDef.Identifier);

                var codeBlock = _current.GetCurrent <AstCodeBlock>();
                codeBlock.AddLine(fnDef);

                _current.SetCurrent(fnDef.FunctionType);
                _current.SetCurrent(fnDef);
                functionDef.VisitChildren(this);
                _current.RevertCurrent();
                _current.RevertCurrent();

                var symbols = _current.GetCurrent <IAstSymbolTableSite>();
                fnDef.CreateSymbols(symbols.SymbolTable);
            }
        }
예제 #3
0
        public static int Rank(AstFunctionReference functionRef, AstFunctionDefinition functionDef)
        {
            var sources = functionRef.FunctionType.Arguments.Select(p => p.TypeReference).ToList();
            var targets = functionDef.FunctionType.Parameters.Select(p => p.TypeReference).ToList();

            // TODO: check for default values on targets
            if (sources.Count != targets.Count)
            {
                return(0);
            }

            if (functionRef.FunctionType.HasTypeReference &&
                functionDef.FunctionType.HasTypeReference)
            {
                sources.Add(functionRef.FunctionType.TypeReference);
                targets.Add(functionDef.FunctionType.TypeReference);
            }

            return(Rank(sources, targets));
        }
 public AstTemplateInstanceFunction(AstFunctionDefinition templateDefinition)
     : base(new AstTypeDefinitionFunction())
 {
     TemplateDefinition = templateDefinition;
     TrySetParent(templateDefinition.Parent);
 }