private void CreateDefaultConstructor(StructDefinition node) { // Get the structure. Structure building = node.GetStructure(); // Check for an user defined constructor. if (building.GetConstructor() != null) { return; } // Instance the building. GenericPrototype contGenProto = building.GetGenericPrototype(); int templateArgs = contGenProto.GetPlaceHolderCount(); Structure buildingInstance = building; if (templateArgs != 0) { IChelaType[] thisArgs = new IChelaType[templateArgs]; for (int i = 0; i < templateArgs; ++i) { thisArgs[i] = contGenProto.GetPlaceHolder(i); } buildingInstance = (Structure)building.InstanceGeneric( new GenericInstance(contGenProto, thisArgs), currentModule); } // Create the default constructor function type. List <IChelaType> arguments = new List <IChelaType> (); arguments.Add(ReferenceType.Create(buildingInstance)); FunctionType ctorType = FunctionType.Create(ChelaType.GetVoidType(), arguments); // Create the constructor method. MemberFlags flags = MemberFlags.Public | MemberFlags.Constructor; Method constructor = new Method(building.GetName(), flags, building); constructor.SetFunctionType(ctorType); // Store it. building.AddFunction("<ctor>", constructor); node.SetDefaultConstructor(constructor); }
public override AstNode Visit(InterfaceDefinition node) { // Parse the generic signature. GenericSignature genericSign = node.GetGenericSignature(); GenericPrototype genProto = GenericPrototype.Empty; PseudoScope protoScope = null; if (genericSign != null) { // Visit the generic signature. genericSign.Accept(this); // Connect the generic prototype. genProto = genericSign.GetPrototype(); // Create the placeholders scope. protoScope = new PseudoScope(currentScope, genProto); node.SetGenericScope(protoScope); } // Prevent redefinition. ScopeMember old = currentContainer.FindType(node.GetName(), genProto); if (old != null) { Error(node, "trying to redefine a class."); } // Create the structure Interface iface = new Interface(node.GetName(), node.GetFlags(), currentContainer); iface.SetGenericPrototype(genProto); node.SetStructure(iface); iface.Position = node.GetPosition(); // Register type maps. string fullName = iface.GetFullName(); IChelaType alias; if (typeMaps.TryGetValue(fullName, out alias)) { currentModule.RegisterTypeMap(alias, ReferenceType.Create(iface)); } // Register some important interfaces. if (fullName == "Chela.Lang.NumberConstraint") { currentModule.RegisterNumberConstraint(iface); } else if (fullName == "Chela.Lang.IntegerConstraint") { currentModule.RegisterIntegerConstraint(iface); } else if (fullName == "Chela.Lang.FloatingPointConstraint") { currentModule.RegisterFloatingPointConstraint(iface); } else if (fullName == "Chela.Collections.IEnumerable") { currentModule.RegisterEnumerableIface(iface); } else if (fullName == "Chela.Collections.IEnumerator") { currentModule.RegisterEnumeratorIface(iface); } else if (fullName.StartsWith("Chela.Collections.Generic.IEnumerable<")) { currentModule.RegisterEnumerableGIface(iface); } else if (fullName.StartsWith("Chela.Collections.Generic.IEnumerator<")) { currentModule.RegisterEnumeratorGIface(iface); } // Use the prototype scope. if (protoScope != null) { PushScope(protoScope); } // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddType(iface); } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddType(iface); } else { Error(node, "unexpected place for a class."); } // Push the interface unsafe. if (iface.IsUnsafe()) { PushUnsafe(); } // Update the scope. PushScope(iface); // Visit the building children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); // Restore the generic scope. if (protoScope != null) { PopScope(); } // Pop the interface unsafe. if (iface.IsUnsafe()) { PopUnsafe(); } return(node); }
public static IChelaType GetNullType() { return(ReferenceType.Create(null)); }
/// <summary> /// Cria um tipo Referencia, no final irá virar um longType, porém com annotations de lookup. /// </summary> /// <param name="reference"></param> /// <returns></returns> private static TypeBase GetTypeFromReference(TypeRef reference) { return(reference.AsString().ToLower() == "long" ? ReferenceType.Create() : ReferenceType.CreateNullable()); }