public FunctionGroupInstance(FunctionGroup template, GenericInstance instance, ScopeMember factory) : base(template.GetName(), (Scope)factory) { // Instance all of the functions. foreach(FunctionGroupName gname in template.GetFunctions()) { // Instance the function. Function tmplFunction = gname.GetFunction(); Function function = (Function)tmplFunction.InstanceMember(factory, instance); // Create the new group name. FunctionGroupName groupName = new FunctionGroupName(function.GetFunctionType(), gname.IsStatic()); groupName.SetFunction(function); // Store the group name. functions.Add(groupName); } }
public FunctionGroupInstance(FunctionGroup template, GenericInstance instance, ScopeMember factory) : base(template.GetName(), (Scope)factory) { // Instance all of the functions. foreach (FunctionGroupName gname in template.GetFunctions()) { // Instance the function. Function tmplFunction = gname.GetFunction(); Function function = (Function)tmplFunction.InstanceMember(factory, instance); // Create the new group name. FunctionGroupName groupName = new FunctionGroupName(function.GetFunctionType(), gname.IsStatic()); groupName.SetFunction(function); // Store the group name. functions.Add(groupName); } }
public override AstNode Visit(FunctionPrototype node) { // Get the name expression. Expression nameExpression = node.GetNameExpression(); if (nameExpression == null) { return(node); } // Visit the name expression. nameExpression.SetHints(Expression.MemberHint); nameExpression.Accept(this); // Get the function and his type. Function function = node.GetFunction(); FunctionType functionType = function.GetFunctionType(); if (!function.IsMethod()) { Error(node, "expected a method prototype."); } Method method = (Method)function; // It must be a function selector. IChelaType nameType = nameExpression.GetNodeType(); if (!nameType.IsFunctionGroup()) { Error(nameExpression, "expected a function group."); } FunctionGroupSelector selector = (FunctionGroupSelector)nameExpression.GetNodeValue(); FunctionGroup group = selector.GetFunctionGroup(); // Find a matching function in the group. Function match = null; foreach (FunctionGroupName gname in group.GetFunctions()) { // Ignore static functions. if (gname.IsStatic()) { continue; } // Check for match. FunctionType candidate = gname.GetFunctionType(); // Found a match?. if (MatchFunction(candidate, functionType, 1)) { match = (Function)gname.GetFunction(); break; } } // Raise an error. if (match == null) { Error(nameExpression, "couldn't find matching interface member for {0}", functionType.GetName()); } // TODO: Rename the method. // Bind the contract. method.SetExplicitContract(match); return(node); }