private void AppendLevelContent(FunctionGroup level, bool isNamespaceLevel) { level.MakeConcrete(); foreach (FunctionGroupName gname in level.functions) { // Check if the object belongs to the included namespace level bool isNamespace = gname.IsNamespaceLevel || isNamespaceLevel; // Read the name data. FunctionType type = gname.GetFunctionType(); bool isStatic = gname.IsStatic(); // Find a similar group. FunctionGroupName old = Find(gname); if (old == null) { FunctionGroupName newName = new FunctionGroupName(type, isStatic); newName.IsNamespaceLevel = isNamespace; newName.SetFunction(gname.GetFunction()); functions.Add(newName); continue; } // Ignore names of lower scopes. if (!isNamespace || !old.IsNamespaceLevel) { continue; } // Now the old name is a namespace level, and we are adding another // namespace level function, in other words, we have detected an ambiguity. Function oldFunction = old.GetFunction(); FunctionAmbiguity amb; if (!oldFunction.IsAmbiguity()) { amb = new FunctionAmbiguity(oldFunction.GetName(), oldFunction.GetFlags(), oldFunction.GetParentScope()); amb.AddCandidate(oldFunction); old.SetFunction(amb); } else { amb = (FunctionAmbiguity)oldFunction; } // Add the new function into the ambiguity list. amb.AddCandidate(gname.GetFunction()); } }
private void DefineFunctionBody(FunctionDefinition node, Function function, LexicalScope topScope) { // Create the top basic block. BasicBlock topBlock = CreateBasicBlock(); topBlock.SetName("top"); builder.SetBlock(topBlock); // Prepare returning. PrepareReturning(node, function, topScope); // Store the arguments into local variables. FunctionPrototype prototype = node.GetPrototype(); AstNode argument = prototype.GetArguments(); byte index = 0; while(argument != null) { FunctionArgument argNode = (FunctionArgument) argument; LocalVariable argVar = argNode.GetVariable(); if(argVar != null && !argVar.IsPseudoScope()) { // Load the argument. builder.CreateLoadArg(index); // Store it into the local. builder.CreateStoreLocal(argVar); } // Process the next argument. argument = argument.GetNext(); index++; } // Generate constructor initialization. if(function.IsConstructor()) { Method ctor = (Method)function; ConstructorInitializer ctorInit = prototype.GetConstructorInitializer(); if(ctorInit != null) ctorInit.Accept(this); else CreateImplicitBaseConstructor(node, ctor); // Initialize some field. if(ctor.IsCtorLeaf()) { Structure building = (Structure)ctor.GetParentScope(); GenerateFieldInitializations(node, building); } } else if(function.IsStaticConstructor()) { // Generate static field initialization. Scope parent = function.GetParentScope(); Structure pbuilding = parent as Structure; if(pbuilding != null) GenerateStaticFieldInitializations(node, function, pbuilding); } // Visit his children. VisitList(node.GetChildren()); // Finish return. FinishReturn(node, function); }