Inheritance: Boo.Lang.Compiler.Ast.TypeDefinition
Exemplo n.º 1
0
 public override void OnClassDefinition(ClassDefinition node)
 {
     IAccessibilityChecker saved = _checker;
     _checker = new AccessibilityChecker(node);
     base.OnClassDefinition(node);
     _checker = saved;
 }
Exemplo n.º 2
0
		override public void OnStructDefinition(StructDefinition node)
		{
			ClassDefinition cd = new ClassDefinition(node.LexicalInfo);
			cd.Name = node.Name;
			cd.Attributes = node.Attributes;
			cd.Modifiers = node.Modifiers;
			cd.Members = node.Members;
			cd.GenericParameters = node.GenericParameters;
			cd.BaseTypes = node.BaseTypes;
			cd.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ValueTypeType));
			foreach (TypeMember member in cd.Members)
			{
				if (member.IsVisibilitySet)
					continue;

				switch (member.NodeType)
				{
					case NodeType.Field:
						member.Visibility = Context.Parameters.DefaultFieldVisibility;
						break;
					case NodeType.Property:
						member.Visibility = Context.Parameters.DefaultPropertyVisibility;
						break;
					case NodeType.Method:
						member.Visibility = Context.Parameters.DefaultMethodVisibility;
						break;
				}

				if (member.IsProtected)
					member.Visibility = TypeMemberModifiers.Public;
			}
			OnClassDefinition(cd);
			ReplaceCurrentNode(cd);
		}
        public override void LeaveClassDefinition(ClassDefinition node)
        {
            MarkVisited(node);
            if(!_classDefinitionList.Contains(node.Name))
            {
                _classDefinitionList.Add(node.Name, node);
            }
            foreach (TypeReference baseTypeRef in node.BaseTypes)
            {
                IType baseType = GetType(baseTypeRef);
                EnsureRelatedNodeWasVisited(node, baseType);

                if (baseType.IsInterface)
                {
                    ResolveInterfaceMembers(node, baseTypeRef, baseType);
                }
                else
                {
                    if (IsAbstract(baseType))
                    {
                        ResolveAbstractMembers(node, baseTypeRef, baseType);
                    }
                }
            }
        }
		public override void Run()
		{
			foreach(Module module in CompileUnit.Modules)
			{
				module.Imports.Add(new Import(module.LexicalInfo, "Castle.MonoRail.Views.Brail"));
				module.Imports.Add(new Import(module.LexicalInfo, "Castle.MonoRail.Framework"));

				foreach(string name in options.NamespacesToImport)
				{
					module.Imports.Add(new Import(module.LexicalInfo, name));
				}

				ClassDefinition macro = new ClassDefinition();
				macro.Name = GetViewTypeName(module.FullName);
				macro.BaseTypes.Add(new SimpleTypeReference("Castle.MonoRail.Views.Brail.BrailBase"));

				AddConstructor(macro);
				ScriptDirectoryProperty(macro, module);
				ViewFileNameProperty(macro, module);
				AddRunMethod(macro, module);

				foreach(TypeMember member in module.Members)
				{
					macro.Members.Add(member);
				}

				module.Members.Clear();
				module.Members.Add(macro);
			}
		}
Exemplo n.º 5
0
        void CheckBaseTypes(ClassDefinition node)
        {
            IType baseClass = null;
            foreach (TypeReference baseTypeRef in node.BaseTypes)
            {
                IType baseType = GetType(baseTypeRef);
                if (baseType.IsInterface)
                    continue;

                if (null != baseClass)
                {
                    Error(
                        CompilerErrorFactory.ClassAlreadyHasBaseType(baseTypeRef,
                            node.Name,
                            baseClass.FullName)
                        );
                    continue;
                }

                baseClass = baseType;
                if (baseClass.IsFinal && !TypeSystemServices.IsError(baseClass))
                {
                    Error(
                        CompilerErrorFactory.CannotExtendFinalType(
                            baseTypeRef,
                            baseClass.FullName));
                }
            }

            if (null == baseClass)
                node.BaseTypes.Insert(0, CodeBuilder.CreateTypeReference(TypeSystemServices.ObjectType)	);
        }
Exemplo n.º 6
0
        public override void Run()
        {
            foreach(var module in CompileUnit.Modules)
            {
                foreach(string name in options.NamespacesToImport)
                {
                    module.Imports.Add(new Import(module.LexicalInfo, name));
                }

                var macro = new ClassDefinition {Name = GetViewTypeName(module.FullName)};
                macro.BaseTypes.Add(new SimpleTypeReference(options.BaseType));

                AddConstructor(macro);
                ScriptDirectoryProperty(macro, module);
                AddRunMethod(macro, module);

                foreach(var member in module.Members)
                {
                    macro.Members.Add(member);
                }

                module.Members.Clear();
                module.Members.Add(macro);
            }
        }
Exemplo n.º 7
0
		/// <summary>
		/// Run this compiler step
		/// </summary>
		public override void Run()
		{
			if (Context.References.Contains(baseClass.Assembly) == false)
                Context.Parameters.References.Add(baseClass.Assembly);

			foreach (Module module in CompileUnit.Modules)
			{
				foreach (string ns in namespaces)
				{
					module.Imports.Add(new Import(module.LexicalInfo, ns));
				}

				ClassDefinition definition = new ClassDefinition();
				definition.Name = module.FullName;
				definition.BaseTypes.Add(new SimpleTypeReference(baseClass.FullName));

				GenerateConstructors(definition);

				// This is called before the module.Globals is set to a new block so that derived classes may retrieve the
				// block from the module.
				ExtendBaseClass(module, definition);

				module.Globals = new Block();
				module.Members.Add(definition);
			}
		}
Exemplo n.º 8
0
 protected void CheckPrivateMembersNeverUsed(ClassDefinition node)
 {
     foreach (TypeMember member in node.Members)
     {
         WarnIfPrivateMemberNeverUsed(member);
     }
 }
Exemplo n.º 9
0
        // create a constructor that delegate to the base class
        private void AddConstructor(ClassDefinition macro)
        {
            var ctor = new Constructor(macro.LexicalInfo);

            ctor.Parameters.Add(
                new ParameterDeclaration("viewEngine",
                                         new SimpleTypeReference("MvcContrib.BrailViewEngine.BooViewEngine"))); // TODO: Update Reference

            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("output",
            //				                         new SimpleTypeReference("System.IO.TextWriter")));
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("context",
            //				                         new SimpleTypeReference("Castle.MonoRail.Framework.IEngineContext")));
            //
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("__controller",
            //				                         new SimpleTypeReference("Castle.MonoRail.Framework.IController")));
            //
            //			ctor.Parameters.Add(
            //				new ParameterDeclaration("__controllerContext",
            //										 new SimpleTypeReference("Castle.MonoRail.Framework.IControllerContext")));

            var mie = new MethodInvocationExpression(new SuperLiteralExpression());
            mie.Arguments.Add(AstUtil.CreateReferenceExpression("viewEngine"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("output"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("context"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controller"));
            //			mie.Arguments.Add(AstUtil.CreateReferenceExpression("__controllerContext"));

            ctor.Body.Add(mie);

            macro.Members.Add(ctor);
        }
Exemplo n.º 10
0
			public override void Run()
			{
				var klass = new ClassDefinition { Name = "Foo" };
				var baseType = new SimpleTypeReference("object");
				klass.BaseTypes.Add(baseType);

				var method = new Method { Name = "Bar" };
				method.Body.Add(
					new ReturnStatement(
						new IntegerLiteralExpression(42)));
				klass.Members.Add(method);

				var module = CompileUnit.Modules[0];
				Assert.AreEqual(0, module.Members.Count);

				My<CodeReifier>.Instance.ReifyInto(module, klass);

				Assert.AreEqual(1, module.Members.Count);
				Assert.AreSame(klass, module.Members[0]);

				var klassEntity = (IType) klass.Entity;
				Assert.IsTrue(klassEntity.IsClass);
				Assert.AreSame(TypeSystemServices.ObjectType, klassEntity.BaseType);

				var methodEntity = (IMethod)method.Entity;
				Assert.AreEqual(method.Name, methodEntity.Name);
				Assert.AreSame(TypeSystemServices.IntType, methodEntity.ReturnType);
			}
Exemplo n.º 11
0
 public override bool EnterClassDefinition(ClassDefinition node)
 {
     if (WasVisited(node))
         return false;
     _visited.Add(node);
     return true;
 }
 public override void LeaveClassDefinition(ClassDefinition node)
 {
     LeaveTypeDefinition(node);
     if (!node.HasInstanceConstructor && !node.IsStatic)
     {
         node.Members.Add(AstUtil.CreateDefaultConstructor(node));
     }
 }
Exemplo n.º 13
0
        public override void LeaveClassDefinition(ClassDefinition node)
        {
            CheckModifierCombination(node);
            CantBeMarkedPartialIfNested(node);

            if (node.IsStatic)
                node.Modifiers |= TypeMemberModifiers.Abstract | TypeMemberModifiers.Final;
        }
Exemplo n.º 14
0
 public override void OnClassDefinition(ClassDefinition node)
 {
     if (null == node.Entity)
     {
         node.Entity = new InternalClass(TypeSystemServices, node);
     }
     Visit(node.Members);
 }
Exemplo n.º 15
0
 protected void CheckMembers(ClassDefinition node)
 {
     foreach (TypeMember member in node.Members)
     {
         WarnIfPrivateMemberNeverUsed(member);
         WarnIfProtectedMemberInSealedClass(member);
     }
 }
Exemplo n.º 16
0
 public void Merge(ClassDefinition node)
 {
     if (null == node) throw new ArgumentNullException("node");
     if (ReferenceEquals(this, node)) return;
     this.Attributes.Extend(node.Attributes);
     this.BaseTypes.Extend(node.BaseTypes);
     this.Members.Extend(node.Members);
 }
        public override void OnClassDefinition(ClassDefinition node)
        {
            Visit(node.Members, NodeType.ClassDefinition);

            InternalCallableType type = node.Entity as InternalCallableType;
            if (null != type)
            {
                ImplementICallableCall(type, node);
            }
        }
Exemplo n.º 18
0
		public BooClassBuilder(string name)
		{
			if (name == null)
				throw new ArgumentNullException("name");
			
			_internalTypeSystemProvider = My<InternalTypeSystemProvider>.Instance;
			_codeBuilder = My<BooCodeBuilder>.Instance;
			_cd = new ClassDefinition { Name = name, IsSynthetic = true };
			EnsureEntityFor(_cd);
		}
Exemplo n.º 19
0
		public void ReifyIntoShouldFailWithAlreadyConnectedMember()
		{
			var module = new Module();
			RunCompilerStepAfterExpressionResolutionOn(new CompileUnit(module), new ActionStep(() =>
			{
				var klass = new ClassDefinition { Name = "Foo" };
				module.Members.Add(klass);
				Exceptions.Expecting<ArgumentException>(() => CodeReifier().ReifyInto(module, klass));
			}));
		}
Exemplo n.º 20
0
        public override void LeaveClassDefinition(ClassDefinition node)
        {
            CheckModifierCombination(node);
            CheckMemberName(node);

            if(node.IsStatic)
            {
                node.Modifiers |= TypeMemberModifiers.Abstract | TypeMemberModifiers.Final;
            }
        }
Exemplo n.º 21
0
 public void SimplifyBaseTypeName(ClassDefinition node)
 {
     if (node.BaseTypes.Count != 0)
     {
         var simpleTypeReference = node.BaseTypes[0] as SimpleTypeReference;
         if (simpleTypeReference != null && simpleTypeReference.Name == "UnityEngine.MonoBehaviour")
         {
             simpleTypeReference.Name = "MonoBehaviour";
         }
     }
 }
Exemplo n.º 22
0
		public ClassDefinition CreateEmptyCallableDefinition(string name)
		{
			var cd = new ClassDefinition { IsSynthetic = true, Name = name, Modifiers = TypeMemberModifiers.Final };
			cd.Entity = new InternalCallableType(My<InternalTypeSystemProvider>.Instance, cd);
			cd.BaseTypes.Add(CodeBuilder.CreateTypeReference(TypeSystemServices.MulticastDelegateType));
			cd.BaseTypes.Add(CodeBuilder.CreateTypeReference(TypeSystemServices.ICallableType));
			cd.Attributes.Add(CodeBuilder.CreateAttribute(typeof(CompilerGeneratedAttribute)));
			cd.Members.Add(CreateCallableConstructor());
			cd.Members.Add(CreateCallMethod());
			return cd;
		}
		// get the directory name where this script reside and create a property
		// that return this value.
		// this is used to calculate relative paths when loading subviews.
		private void ScriptDirectoryProperty(ClassDefinition macro, Module module)
		{
			Property p = new Property("ScriptDirectory");
			p.Modifiers = TypeMemberModifiers.Override;
			p.Getter = new Method("getScriptDirectory");
			p.Getter.Body.Add(
				new ReturnStatement(
					new StringLiteralExpression(
						Path.GetDirectoryName(module.LexicalInfo.FileName))));

			macro.Members.Add(p);
		}
Exemplo n.º 24
0
        public override void OnClassDefinition(ClassDefinition node)
        {
            // Visit type definition's members to resolve base types on nested types
            base.OnClassDefinition(node);

            // Resolve and check base types
            ResolveBaseTypes(new Boo.Lang.List(), node);
            CheckBaseTypes(node);

            if (node.IsFinal)
                return;

            if (((IType)node.Entity).IsFinal)
                node.Modifiers |= TypeMemberModifiers.Final;
        }
        /// <summary>
        /// Allow a derived class to perform additional operations on the newly created type definition.
        /// </summary>
        protected override void ExtendBaseClass(Module module, ClassDefinition definition)
        {
            Method method = new Method(methodName);

            if (parameters != null) {
                foreach (ParameterDeclaration parameter in parameters) {
                    method.Parameters.Add(parameter);
                }
            }

            method.Body = module.Globals;
            definition.Members.Add(method);

            ExtendBaseClass(definition);
        }
		/// <summary>
		/// Extends the base class by placing the blocks of macros into methods on the base class
		/// of the same name.
		/// </summary>
		/// <example>
		/// MyMethod:
		///		PerformActions
		/// 
		/// If an overridable method called MyMethod exists on <see cref="BaseClassCompilerStep.BaseClass"/>, then 
		/// it is overridden as follows:
		/// <code>
		/// public override void MyMethod() { PerformActions(); }
		/// </code>
		/// </example>
		protected override void ExtendBaseClass(Module module, ClassDefinition definition)
		{
			List<MethodInfo> methodsThatAreOverridable = new List<MethodInfo>();

			MethodInfo[] baseClassMethods =
				BaseClass.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
									 BindingFlags.InvokeMethod);

			foreach (MethodInfo method in baseClassMethods)
			{
				if(method.DeclaringType==typeof(object))
					continue;
				if (method.IsVirtual || method.IsAbstract)
					methodsThatAreOverridable.Add(method);
			}

			MethodSubstitutionTransformer mst = new MethodSubstitutionTransformer(methodsThatAreOverridable.ToArray(), definition);
			mst.Visit(module);

			foreach (Statement statement in module.Globals.Statements)
			{
				ExpressionStatement es = statement as ExpressionStatement;
				if (es != null)
				{
					BinaryExpression be = es.Expression as BinaryExpression;
					if (be != null)
					{
						if (be.Left.NodeType == NodeType.ReferenceExpression && be.Operator == BinaryOperatorType.Assign)
						{
							ReferenceExpression refExp = be.Left as ReferenceExpression;

							Field field = new Field(refExp.LexicalInfo);
							field.Name = refExp.Name;
							field.Initializer = be.Right;
							definition.Members.Add(field);
						}
					}
				}
			}

			if (transformers != null)
			{
				foreach (DepthFirstTransformer transformer in transformers)
					transformer.Visit(module);
			}
		}
Exemplo n.º 27
0
        public BooClassBuilder(BooCodeBuilder codeBuilder, string name)
        {
            if (null == codeBuilder)
            {
                throw new ArgumentNullException("codeBuilder");
            }
            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            _codeBuilder = codeBuilder;
            _cd = new ClassDefinition();
            _cd.Name = name;
            _cd.Entity = new InternalClass(_codeBuilder.TypeSystemServices, _cd);
            _cd.IsSynthetic = true;
        }
		void ImplementICallableCall(InternalCallableType type, ClassDefinition node)
		{
			Method call = (Method)node.Members["Call"];
			Debug.Assert(null != call);
			Debug.Assert(call.Body.IsEmpty);
						
			CallableSignature signature = type.GetSignature();
			int byRefCount = GetByRefParamCount(signature);
			if (byRefCount > 0)
			{
				ImplementByRefICallableCall(call, type, node, signature, byRefCount);
			}
			else
			{
				ImplementRegularICallableCall(call, type, node, signature);
			}
		}
Exemplo n.º 29
0
		private void tryMethod(Node targetNode) {
			var method = targetNode as Method;
			if (method == null)
			{
				return;
			}
			var processmethod = method.Clone() as Method;
			processmethod.Name = "process";
			processmethod.Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Override;
			processmethod.Parameters.Clear();
			//processmethod.Parameters.Add(new ParameterDeclaration("context", new SimpleTypeReference("Comdiv.Framework.Quick.QWebContext")));
			processmethod.ReturnType = new SimpleTypeReference("System.Object");
			var name = method.Name;
			var cls = new ClassDefinition();
			cls.Name = name;
			cls.Members.Add(processmethod);
			method.ParentNode.Replace(method, cls);
			tryClass(cls);
		}
Exemplo n.º 30
0
        public override bool EnterClassDefinition(ClassDefinition node)
        {
            if (!node.IsPartial)
            {
                return false;
            }

            if (_partials.Contains(node.FullName))
            {
                _current = (ClassDefinition)_partials[node.FullName];
                MergeImports(node, _current);
                RemoveCurrentNode();
                return true;
            }
            else
            {
                _partials[node.FullName] = node;
                return false;
            }
        }
Exemplo n.º 31
0
 public void InitializeModuleClass(Boo.Lang.Compiler.Ast.ClassDefinition moduleClass)
 {
     _moduleClassNamespace = (INamespace)_typeSystemServices.GetMemberEntity(moduleClass);
     _moduleClass          = moduleClass;
 }
Exemplo n.º 32
0
 public override void LeaveClassDefinition(AST.ClassDefinition node)
 {
     LeaveTypeDefinition(node);
     base.LeaveClassDefinition(node);
 }
Exemplo n.º 33
0
 public override bool EnterClassDefinition(AST.ClassDefinition node)
 {
     EnterTypeDefinition(node, ClassType.Class);
     return(base.EnterClassDefinition(node));
 }
Exemplo n.º 34
0
        public object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
        {
            if (typeDeclaration.Templates.Count > 0)
            {
                AddError(typeDeclaration, "Generic type definitions are not supported.");
            }
            B.TypeDefinition oldType = currentType;
            B.TypeDefinition typeDef;
            switch (typeDeclaration.Type)
            {
            case ClassType.Class:
                typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration));
                break;

            case ClassType.Interface:
                typeDef = new B.InterfaceDefinition(GetLexicalInfo(typeDeclaration));
                break;

            case ClassType.Enum:
                typeDef = new B.EnumDefinition(GetLexicalInfo(typeDeclaration));
                break;

            case ClassType.Struct:
                typeDef = new B.StructDefinition(GetLexicalInfo(typeDeclaration));
                break;

            case ClassType.Module:
                typeDef = new B.ClassDefinition(GetLexicalInfo(typeDeclaration));
                typeDeclaration.Modifier |= Modifiers.Static;
                break;

            default:
                AddError(typeDeclaration, "Unknown class type.");
                return(null);
            }
            if (currentType != null)
            {
                typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Private);
            }
            else
            {
                typeDef.Modifiers = ConvertModifier(typeDeclaration, B.TypeMemberModifiers.Internal);
            }
            typeDef.Name = typeDeclaration.Name;
            typeDef.EndSourceLocation = GetLocation(typeDeclaration.EndLocation);
            ConvertAttributes(typeDeclaration.Attributes, typeDef.Attributes);
            ConvertTypeReferences(typeDeclaration.BaseTypes, typeDef.BaseTypes);

            if (currentType != null)
            {
                currentType.Members.Add(typeDef);
            }
            else
            {
                module.Members.Add(typeDef);
            }
            currentType = typeDef;
            typeDeclaration.AcceptChildren(this, data);
            currentType = oldType;
            return(typeDef);
        }