public override AstNode Visit(EnumDefinition node) { // Prevent redefinition. ScopeMember old = currentContainer.FindType(node.GetName(), GenericPrototype.Empty); if (old != null) { Error(node, "trying to redefine a enum."); } // Create the structure Structure building = new Structure(node.GetName(), node.GetFlags(), currentContainer); building.Position = node.GetPosition(); node.SetStructure(building); // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddType(building); } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddType(building); } else { Error(node, "unexpected place for a structure."); } return(node); }
internal PropertyInstance(ScopeMember factory, GenericInstance instance, PropertyVariable template) : base(factory.GetModule()) { this.type = template.GetVariableType().InstanceGeneric(instance, GetModule()); this.flags = template.flags; this.SetName(template.GetName()); this.parentScope = (Scope)factory; if (template.getAccessor != null) { this.getAccessor = (Function)template.getAccessor.InstanceMember(factory, instance); } if (template.setAccessor != null) { this.setAccessor = (Function)template.setAccessor.InstanceMember(factory, instance); } // Instance the indexers. if (template.indices != null) { int numindices = template.indices.Length; this.indices = new IChelaType[numindices]; for (int i = 0; i < numindices; ++i) { this.indices[i] = template.indices[i].InstanceGeneric(instance, GetModule()); } } }
public override AstNode Visit(TypedefDefinition node) { // Prevent redefinition. ScopeMember old = currentContainer.FindMember(node.GetName()); if (old != null) { Error(node, "trying to redefine a typedef."); } // Create the type name. TypeNameMember typeName = new TypeNameMember(node.GetFlags(), node.GetName(), currentContainer); typeName.SetTypedefNode(node); node.SetTypeName(typeName); // Register the type name. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddMember(typeName); } else if (currentContainer.IsStructure() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddTypeName(typeName); } else { Error(node, "unexpected place for a typedef."); } return(node); }
public FunctionInstance(Function template, GenericInstance genericInstance, ScopeMember factory) : base(factory.GetModule()) { this.factory = factory; Initialize(template, genericInstance); // Use the factory as a scope. this.UpdateParent((Scope)factory); }
public FunctionInstance(Function template, GenericInstance genericInstance, ScopeMember factory) : base(factory.GetModule()) { this.factory = factory; Initialize(template, genericInstance); // Use the factory as a scope. this.UpdateParent((Scope)factory); }
public override AstNode Visit(UsingStatement node) { // Visit the using member. Expression member = node.GetMember(); member.Accept(this); // Cast the pseudo-scope. PseudoScope scope = (PseudoScope)node.GetScope(); // Get the member type. IChelaType memberType = member.GetNodeType(); if (memberType.IsMetaType()) { // Get the actual type. MetaType meta = (MetaType)memberType; memberType = meta.GetActualType(); // Only structure relatives. if (memberType.IsStructure() || memberType.IsClass() || memberType.IsInterface()) { scope.AddAlias(memberType.GetName(), (ScopeMember)memberType); } else { Error(node, "unexpected type."); } } else if (memberType.IsReference()) { // Only static members supported. ScopeMember theMember = (ScopeMember)member.GetNodeValue(); MemberFlags instanceFlags = MemberFlags.InstanceMask & theMember.GetFlags(); if (instanceFlags != MemberFlags.Static) { Error(node, "unexpected member type."); } // Store the member. scope.AddAlias(theMember.GetName(), theMember); } else if (memberType.IsNamespace()) { // Set the namespace chain. Namespace space = (Namespace)member.GetNodeValue(); scope.SetChainNamespace(space); } else { Error(node, "unsupported object to use."); } base.Visit(node); return(node); }
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); } }
internal PropertyInstance(ScopeMember factory, GenericInstance instance, PropertyVariable template) : base(factory.GetModule()) { this.type = template.GetVariableType().InstanceGeneric(instance, GetModule()); this.flags = template.flags; this.SetName(template.GetName()); this.parentScope = (Scope)factory; if(template.getAccessor != null) this.getAccessor = (Function)template.getAccessor.InstanceMember(factory, instance); if(template.setAccessor != null) this.setAccessor = (Function)template.setAccessor.InstanceMember(factory, instance); // Instance the indexers. if(template.indices != null) { int numindices = template.indices.Length; this.indices = new IChelaType[numindices]; for(int i = 0; i < numindices; ++i) this.indices[i] = template.indices[i].InstanceGeneric(instance, GetModule()); } }
internal FieldInstance(ScopeMember factory, GenericInstance instance, FieldVariable template) : base(factory.GetModule()) { // Store the factory and the template. this.factory = factory; this.template = template; // Use the factory as the parent scope. this.parentScope = (Scope)factory; // Copy the name and the flags. this.SetName(template.GetName()); this.flags = template.flags; // Copy the slot. this.slot = template.slot; // Instance the type. this.type = template.GetVariableType().InstanceGeneric(instance, GetModule()); // Use the factory as parent scope. this.parentScope = (Scope)factory; }
internal FieldInstance(ScopeMember factory, GenericInstance instance, FieldVariable template) : base(factory.GetModule()) { // Store the factory and the template. this.factory = factory; this.template = template; // Use the factory as the parent scope. this.parentScope = (Scope)factory; // Copy the name and the flags. this.SetName(template.GetName()); this.flags = template.flags; // Copy the slot. this.slot = template.slot; // Instance the type. this.type = template.GetVariableType().InstanceGeneric(instance, GetModule()); // Use the factory as parent scope. this.parentScope = (Scope)factory; }
/// <summary> /// Añade una funcion al programa /// </summary> /// <param name="member"></param> internal void AddFunction(ParseTreeNode member) { if (member.ChildNodes.Count == 4) { String type = member.ChildNodes[0].FindTokenAndGetText(); String name = member.ChildNodes[1].FindTokenAndGetText(); ParseTreeNode pars = member.ChildNodes[2]; ParseTreeNode body = member.ChildNodes[3]; ScopeMember funct = new ScopeMember(type, name, member) { Uncertainty = Uncertainty, ImagePath = ImagePath }; if (funct.IsMain) { Main = funct; } Global.AddFunct(funct); } }
public override AstNode Visit(NamespaceDefinition node) { // Handle nested names. string fullname = node.GetName(); StringBuilder nameBuilder = new StringBuilder(); int numscopes = 0; for (int i = 0; i < fullname.Length; i++) { char c = fullname[i]; if (c != '.') { nameBuilder.Append(c); if (i + 1 < fullname.Length) { continue; } } // Expect full name. if (c == '.' && i + 1 == fullname.Length) { Error(node, "expected complete namespace name."); } // Find an already declared namespace. string name = nameBuilder.ToString(); nameBuilder.Length = 0; ScopeMember old = currentContainer.FindMember(name); if (old != null) { if (!old.IsNamespace()) { Error(node, "defining namespace collides with another thing."); } // Store a reference in the node. node.SetNamespace((Namespace)old); } else { // Cast the current scope. Namespace space = (Namespace)currentContainer; // Create, name and add the new namespace. Namespace newNamespace = new Namespace(space); newNamespace.SetName(name); space.AddMember(newNamespace); // Store a reference in the node. node.SetNamespace(newNamespace); } // Update the scope. PushScope(node.GetNamespace()); // Increase the number of scopes. numscopes++; } // Visit the children. VisitList(node.GetChildren()); // Restore the scopes. for (int i = 0; i < numscopes; i++) { PopScope(); } return(node); }
public override AstNode Visit(DelegateDefinition 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(), GenericPrototype.Empty); if (old != null) { Error(node, "trying to redefine a delegate."); } // Create the structure MemberFlags flags = node.GetFlags(); // TODO: Check the flags. Class building = new Class(node.GetName(), flags, currentContainer); building.SetGenericPrototype(genProto); building.Position = node.GetPosition(); node.SetStructure(building); // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddType(building); } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddType(building); } else { Error(node, "unexpected place for a delegate."); } // Register the compute binding delegate. if (building.GetFullName() == "Chela.Compute.ComputeBinding") { currentModule.RegisterComputeBindingDelegate(building); } return(node); }
public override AstNode Visit(StructDefinition 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 struct."); } // Create the structure Structure building = new Structure(node.GetName(), node.GetFlags(), currentContainer); building.SetGenericPrototype(genProto); node.SetStructure(building); building.Position = node.GetPosition(); // Use the prototype scope. if (protoScope != null) { PushScope(protoScope); } // Register type association. string fullName = building.GetFullName(); IChelaType assoc; if (assocClasses.TryGetValue(fullName, out assoc)) { currentModule.RegisterAssociatedClass(assoc, building); } // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; space.AddType(building); } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; parent.AddType(building); } else { Error(node, "unexpected place for a structure."); } // Push the building unsafe. if (building.IsUnsafe()) { PushUnsafe(); } // Update the scope. PushScope(building); // Visit the building children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); // Pop the building unsafe. if (building.IsUnsafe()) { PopUnsafe(); } // Restore the prototype scope. if (protoScope != null) { PopScope(); } return(node); }
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(ClassDefinition node) { // Check the partial flag. bool isPartial = (node.GetFlags() & MemberFlags.ImplFlagMask) == MemberFlags.Partial; // Add the parent static flag. if (currentContainer.IsStatic()) { MemberFlags oldInstance = node.GetFlags() & MemberFlags.InstanceMask; if (oldInstance == MemberFlags.Static || oldInstance == MemberFlags.Instanced) { MemberFlags flags = node.GetFlags() & ~MemberFlags.InstanceMask; node.SetFlags(flags | MemberFlags.Static); } else { Error(node, "static class member cannot be {0}.", oldInstance.ToString().ToLower()); } } // Static classes are automatically sealed. if ((node.GetFlags() & MemberFlags.InstanceMask) == MemberFlags.Static) { MemberFlags flags = node.GetFlags() & ~MemberFlags.InheritanceMask; node.SetFlags(flags | MemberFlags.Sealed); } // 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 && (!isPartial || !old.IsClass())) { Error(node, "trying to redefine a class."); } // Create the structure Class clazz = (Class)old; if (clazz != null) { if (!clazz.IsPartial()) { Error(node, "incompatible partial class definitions."); } } else { clazz = new Class(node.GetName(), node.GetFlags(), currentContainer); clazz.Position = node.GetPosition(); clazz.SetGenericPrototype(genProto); } node.SetStructure(clazz); // Use the prototype scope. if (protoScope != null) { PushScope(protoScope); } // Register type maps. string fullName = clazz.GetFullName(); IChelaType alias; if (typeMaps.TryGetValue(fullName, out alias)) { currentModule.RegisterTypeMap(alias, clazz); } // Register type association. IChelaType assoc; if (assocClasses.TryGetValue(fullName, out assoc)) { currentModule.RegisterAssociatedClass(assoc, clazz); } // Array base class is special. if (fullName == "Chela.Lang.Array") { currentModule.RegisterArrayClass(clazz); } else if (fullName == "Chela.Lang.Attribute") { currentModule.RegisterAttributeClass(clazz); } else if (fullName == "Chela.Lang.ValueType") { currentModule.RegisterValueTypeClass(clazz); } else if (fullName == "Chela.Lang.Enum") { currentModule.RegisterEnumClass(clazz); } else if (fullName == "Chela.Lang.Type") { currentModule.RegisterTypeClass(clazz); } else if (fullName == "Chela.Lang.Delegate") { currentModule.RegisterDelegateClass(clazz); } else if (fullName == "Chela.Compute.StreamHolder") { currentModule.RegisterStreamHolderClass(clazz); } else if (fullName == "Chela.Compute.StreamHolder1D") { currentModule.RegisterStreamHolder1DClass(clazz); } else if (fullName == "Chela.Compute.StreamHolder2D") { currentModule.RegisterStreamHolder2DClass(clazz); } else if (fullName == "Chela.Compute.StreamHolder3D") { currentModule.RegisterStreamHolder3DClass(clazz); } else if (fullName == "Chela.Compute.UniformHolder") { currentModule.RegisterUniformHolderClass(clazz); } // Add into the current scope. if (currentContainer.IsNamespace()) { Namespace space = (Namespace)currentContainer; if (old == null) { space.AddType(clazz); } } else if (currentContainer.IsStructure() || currentContainer.IsInterface() || currentContainer.IsClass()) { Structure parent = (Structure)currentContainer; if (old == null) { parent.AddType(clazz); } } else { Error(node, "unexpected place for a class."); } // Push the class unsafe. if (clazz.IsUnsafe()) { PushUnsafe(); } // Update the scope. PushScope(clazz); // Visit the building children. VisitList(node.GetChildren()); // Restore the scope. PopScope(); // Restore the scope. if (protoScope != null) { PopScope(); } // Pop the class unsafe. if (clazz.IsUnsafe()) { PopUnsafe(); } return(node); }
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 override ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance) { return new FieldInstance(factory, instance, this); }
public override ScopeMember InstanceMember(ScopeMember factory, GenericInstance instance) { return(new FieldInstance(factory, instance, this)); }