Inheritance: Boo.Lang.Compiler.Ast.CallableDefinition, IExplicitMember, INodeWithBody
		public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
		{
			B.Method m = new B.Method(GetLexicalInfo(methodDeclaration));
			m.Name = methodDeclaration.Name;
			m.Modifiers = ConvertModifier(methodDeclaration, B.TypeMemberModifiers.Private);
			ConvertAttributes(methodDeclaration.Attributes, m.Attributes);
			if (currentType != null) currentType.Members.Add(m);
			if (methodDeclaration.HandlesClause.Count > 0) {
				// TODO: Convert handles clauses to [Handles] attribute
				AddError(methodDeclaration, "Handles-clause is not supported.");
			}
			m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, m);
			if (methodDeclaration.Templates.Count > 0) {
				AddError(methodDeclaration, "Declaring generic methods is not supported.");
			}
			ConvertParameters(methodDeclaration.Parameters, m.Parameters);
			m.EndSourceLocation = GetEndLocation((INode)methodDeclaration.Body ?? methodDeclaration);
			m.ReturnType = ConvertTypeReference(methodDeclaration.TypeReference);
			m.Body = ConvertMethodBlock(methodDeclaration.Body);
			if (m.Name == "Main" && m.IsStatic && m.Parameters.Count <= 1 &&
			    (methodDeclaration.TypeReference.Type == "System.Void" || methodDeclaration.TypeReference.Type == "System.Int32"))
			{
				entryPointMethod = m;
			}
			return m;
		}
 public void CheckEntryPoint(Method node)
 {
     if ((node.get_IsStatic() && node.get_IsPublic()) && ((node.get_Name() == "Main") && (this.GetType(node.get_ReturnType()) == this.get_TypeSystemServices().VoidType)))
     {
         ContextAnnotations.SetEntryPoint(base._context, node);
     }
 }
Example #3
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);
			}
 public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
 {
     B.Method m = new B.Method(GetLexicalInfo(methodDeclaration));
     m.Name      = methodDeclaration.Name;
     m.Modifiers = ConvertModifier(methodDeclaration, B.TypeMemberModifiers.Private);
     ConvertAttributes(methodDeclaration.Attributes, m.Attributes);
     if (currentType != null)
     {
         currentType.Members.Add(m);
     }
     if (methodDeclaration.HandlesClause.Count > 0)
     {
         // TODO: Convert handles clauses to [Handles] attribute
         AddError(methodDeclaration, "Handles-clause is not supported.");
     }
     m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, m);
     if (methodDeclaration.Templates.Count > 0)
     {
         AddError(methodDeclaration, "Declaring generic methods is not supported.");
     }
     ConvertParameters(methodDeclaration.Parameters, m.Parameters);
     m.EndSourceLocation = GetEndLocation((INode)methodDeclaration.Body ?? methodDeclaration);
     m.ReturnType        = ConvertTypeReference(methodDeclaration.TypeReference);
     m.Body = ConvertMethodBlock(methodDeclaration.Body);
     if (m.Name == "Main" && m.IsStatic && m.Parameters.Count <= 1 &&
         (methodDeclaration.TypeReference.Type == "System.Void" || methodDeclaration.TypeReference.Type == "System.Int32"))
     {
         entryPointMethod = m;
     }
     return(m);
 }
Example #5
0
		Method CreateGetter(Field f)
		{
			Method m = new Method();
			m.Name = "get";

			// value = ViewState["<f.Name>"]
			m.Body.Statements.Add(
				new ExpressionStatement(
					new BinaryExpression(
						BinaryOperatorType.Assign,
						new ReferenceExpression("value"),
						CreateViewStateSlice(f)
						)
					)
				);

			if (null != _default)
			{
				// return <_default> unless value
				ReturnStatement rs = new ReturnStatement(_default);
				rs.Modifier = new StatementModifier(StatementModifierType.Unless, new ReferenceExpression("value"));
				m.Body.Statements.Add(rs);
			}

			// return value
			m.Body.Statements.Add(
				new ReturnStatement(
					new ReferenceExpression("value")
					)
				);

			return m;
		}
 public override void LeaveMethod(Method node)
 {
     if (node.Body.IsEmpty)
     {
         RemoveCurrentNode();
     }
 }
Example #7
0
        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            if (macro.Arguments.Count != 0)
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo,"No arguments allowed for action statement"));
                return null;
            }

            Method mergeRowsMethod = new Method("MergeRows");
            mergeRowsMethod.Modifiers = TypeMemberModifiers.Override;
            mergeRowsMethod.Parameters.Add(new ParameterDeclaration("left", new SimpleTypeReference(typeof(Row).FullName)));
            mergeRowsMethod.Parameters.Add(new ParameterDeclaration("right", new SimpleTypeReference(typeof(Row).FullName)));
            CodeBuilder.DeclareLocal(mergeRowsMethod, "row", TypeSystemServices.Map(typeof(Row)));
            mergeRowsMethod.Body.Add(
                new BinaryExpression(BinaryOperatorType.Assign,
                                     new ReferenceExpression("row"),
                                     new MethodInvocationExpression(
                                         AstUtil.CreateReferenceExpression(typeof(Row).FullName))
                    )
                );
            mergeRowsMethod.Body.Add(macro.Body);
            mergeRowsMethod.Body.Add(new ReturnStatement(new ReferenceExpression("row")));

            ParentMethods.Add(mergeRowsMethod);
            return null;
        }
 public override void OnMethod(Method node)
 {
     if (LookingFor(node))
     {
         Found(node.ReturnType);
     }
 }
Example #9
0
 public void NormalizeGetter(Method getter)
 {
     if ((getter != null) && (getter.get_Parameters().get_Count() != 0))
     {
         this.ReportError(UnityScriptCompilerErrors.InvalidPropertyGetter(getter.get_LexicalInfo()));
     }
 }
Example #10
0
 public void CheckSetterReturnType(Method setter)
 {
     if (setter.get_ReturnType() != null)
     {
         this.ReportError(UnityScriptCompilerErrors.SetterCanNotDeclareReturnType(setter.get_ReturnType().get_LexicalInfo()));
     }
 }
Example #11
0
		public override void OnMethod(Method node)
		{
			var old = _currentMethod;
			_currentMethod = (IMethod) node.Entity;
			base.OnMethod(node);
			_currentMethod = old;
		}
Example #12
0
		override public void LeaveMethod(Method node)
		{
			MakeStaticIfNeeded(node);
			CantBeMarkedTransient(node);
			CantBeMarkedPartial(node);
			CheckExplicitImpl(node);
			CheckModifierCombination(node);
		}
Example #13
0
 public void NormalizeSetter(Method setter)
 {
     if (setter != null)
     {
         this.NormalizeSetterParameters(setter);
         this.CheckSetterReturnType(setter);
     }
 }
Example #14
0
        public override void LeaveMethod(Method method)
        {
            InternalMethod entity = (InternalMethod)method.Entity;
            if (!entity.IsGenerator) return;

            GeneratorMethodProcessor processor = new GeneratorMethodProcessor(Context, entity);
            processor.Run();
        }
Example #15
0
 IReturnType CreateReturnType(AST.Method node, IMethod method)
 {
     if (node.ReturnType == null)
     {
         return(new BooInferredReturnType(node.Body, OuterClass, false));
     }
     return(CreateReturnType(node.ReturnType, method));
 }
Example #16
0
 protected override IEnumerable<Node> ExpandGeneratorImpl(MacroStatement macro){
     var method = new Method("_key"){
                                        ReturnType = new SimpleTypeReference("string"),
                                        Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Override,
                                        Body = macro.extractMethodBody()
                                    };
     yield return method;
 }
Example #17
0
		public BooMethodBuilder(BooCodeBuilder codeBuilder, Method method)
		{
			if (null == codeBuilder)
				throw new ArgumentNullException("codeBuilder");
			if (null == method)
				throw new ArgumentNullException("method");
			_codeBuilder = codeBuilder;
			_method = method;
		}
Example #18
0
		GeneratorSkeleton CreateGeneratorSkeleton(Node sourceNode, Method enclosingMethod, IType generatorItemType)
		{
			// create the class skeleton for type inference to work
			var builder = SetUpEnumerableClassBuilder(sourceNode, enclosingMethod, generatorItemType);
			var getEnumeratorBuilder = SetUpGetEnumeratorMethodBuilder(sourceNode, builder, generatorItemType);

			enclosingMethod.DeclaringType.Members.Add(builder.ClassDefinition);

			return new GeneratorSkeleton(builder, getEnumeratorBuilder, generatorItemType);
		}
Example #19
0
 void CheckExtensionSemantics(Method node)
 {
     if (!((IMethod)node.Entity).IsExtension)
         return;
     if (NodeType.Method == node.NodeType
         && (node.IsStatic || node.DeclaringType is Module)
         && node.Parameters.Count != 0)
         return;
     Errors.Add(CompilerErrorFactory.InvalidExtensionDefinition(node));
 }
 public void CheckForEmptyCoroutine(Method node)
 {
     if (this.IsEmptyCoroutine(node))
     {
         ReturnStatement statement;
         ReturnStatement statement1 = statement = new ReturnStatement(LexicalInfo.Empty);
         statement.set_Expression(Expression.Lift(this.EmptyEnumeratorReference));
         node.get_Body().Add(statement);
     }
 }
Example #21
0
		public BooMethodBuilder(BooCodeBuilder codeBuilder, string name, IType returnType, TypeMemberModifiers modifiers)
		{
			if (null == codeBuilder)
				throw new ArgumentNullException("codeBuilder");
			if (null == name)
				throw new ArgumentNullException("name");
			
			_codeBuilder = codeBuilder;			
			_method = _codeBuilder.CreateMethod(name, returnType, modifiers);
		}
 public override void OnMethod(Method node)
 {
     if (!node.get_IsPrivate())
     {
         this.SetPublicByDefault(node);
         if (!node.get_IsFinal() && !node.get_IsStatic())
         {
             node.set_Modifiers(node.get_Modifiers() | 0x80);
         }
     }
 }
        public InternalGenericParameter(TypeSystemServices tss, GenericParameterDeclaration declaration)
        {
            _tss = tss;
            _declaration = declaration;

            // Determine and remember declaring type and declaring method (if applicable)
            _declaringMethod = declaration.ParentNode as Method;
            _declaringType = (
                _declaringMethod == null ?
                declaration.ParentNode as TypeDefinition : _declaringMethod.DeclaringType);
        }
Example #24
0
        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            Method accumulate = new Method("FinishAggregation");
            accumulate.Modifiers = TypeMemberModifiers.Override;
            accumulate.Parameters.Add(new ParameterDeclaration("aggregate", CodeBuilder.CreateTypeReference(typeof(Row))));

            accumulate.Body = macro.Body;

            ParentMethods.Add(accumulate);

            return null;
        }
        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            Method rowProcessed = new Method("OnFinishedProcessing");
            rowProcessed.Modifiers = TypeMemberModifiers.Override;
            rowProcessed.Parameters.Add(new ParameterDeclaration("op", CodeBuilder.CreateTypeReference(typeof(IOperation))));

            rowProcessed.Body = macro.Body;

            ParentMethods.Add(rowProcessed);

            return null;
        }
 public override void LeaveMethod(Method node)
 {
     TypeReference returnType = node.ReturnType;
     if (returnType is SimpleTypeReference)
     {
         SimpleTypeReference simpleTypeReference = (SimpleTypeReference)returnType;
         if (simpleTypeReference.Name == "void")
         {
             node.ReturnType = null;
         }
     }
 }
Example #27
0
		private void CheckParameterUniqueness(Method method)
		{
			Boo.Lang.List parameters = new Boo.Lang.List();
			foreach (ParameterDeclaration parameter in method.Parameters)
			{
				if (parameters.Contains(parameter.Name))
				{
					Errors.Add(
						CompilerErrorFactory.DuplicateParameterName(
							parameter, parameter.Name, GetEntity(method).ToString()));
				}				
				parameters.Add(parameter.Name);
			}
		}
Example #28
0
        private Method CreateGetColumnsToGroupByMethod(MacroStatement macro, IEnumerable<string> columns)
        {
            Method method = new Method("GetColumnsToGroupBy");
            method.Modifiers = TypeMemberModifiers.Override;
            ArrayLiteralExpression ale = new ArrayLiteralExpression(macro.LexicalInfo);
            ale.Type = new ArrayTypeReference(CodeBuilder.CreateTypeReference(typeof(string)));

            foreach (string column in columns)
            {
                ale.Items.Add(new StringLiteralExpression(column));
            }
            method.Body.Statements.Add(new ReturnStatement(ale));
            return method;
        }
Example #29
0
		public static void SetEntryPoint(CompilerContext context, Method method)
		{
			if (null == method)
			{
				throw new ArgumentNullException("method");
			}
			
			Method current = GetEntryPoint(context);
			if (null != current)
			{
				throw CompilerErrorFactory.MoreThanOneEntryPoint(method);
			}
			context.Properties[EntryPointKey] = method;
		}
Example #30
0
 public override void OnMethod(Method node)
 {
     // If method is generic, enter its namespace
     if (node.GenericParameters.Count != 0)
     {
         EnterNamespace((INamespace)TypeSystemServices.GetEntity(node));
         base.OnMethod(node);
         LeaveNamespace();
     }
     else
     {
         base.OnMethod(node);
     }
 }
        public override bool EnterMethod(Method node)
        {
            var parameters = new List<MethodParameter>();

            // add parameters...
            // TODO: Clean Me
            foreach (var parameter in node.Parameters)
            {
                parameters.Add(new MethodParameter
                {
                    Name = parameter.Name,
                    Type = parameter.Type.ToString()
                });
            }

            //           method in class                   ?? method in property, in class
            var parent = node.ParentNode as TypeDefinition ?? node.ParentNode.ParentNode as TypeDefinition;
            MethodTreeNode method = null;

            // find if the method has already been declared (if so, we're an overload)
            foreach (var child in currentScope.Children)
            {
                if (child.Name == node.Name)
                {
                    method = (MethodTreeNode)child;
                }
            }

            if (method == null)
            {
                // new method
                method = new MethodTreeNode(new EntitySourceOrigin(GetEntity(node)), node.ReturnType != null ? node.ReturnType.ToString() : "void", parent != null ? parent.Name : "");
                method.Parameters = parameters;

                Push(method, node.LexicalInfo.Line);
            }
            else
            {
                // method overload
                var overload = new MethodTreeNode(new EntitySourceOrigin(GetEntity(node)), node.ReturnType != null ? node.ReturnType.ToString() : "void", parent != null ? parent.Name : "");
                overload.Parameters = parameters;

                method.Overloads.Add(overload);

                Push(overload, node.LexicalInfo.Line);
            }

            return base.EnterMethod(node);
        }
        /// <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);
        }
Example #33
0
        public override void OnMethod(AST.Method node)
        {
            //LoggingService.Debug("Method: " + node.FullName + " (" + node.Modifiers + ")");
            DefaultMethod method = new DefaultMethod(node.Name, null, GetModifier(node), GetRegion(node), GetClientRegion(node), OuterClass);

            foreach (AST.Attribute a in node.Attributes)
            {
                if (a.Name == "Extension" || a.Name == "Boo.Lang.Extension" ||
                    a.Name == "ExtensionAttribute" || a.Name == "Boo.Lang.ExtensionAttribute")
                {
                    method.IsExtensionMethod = true;
                }
            }

            ConvertAttributes(node, method);
            ConvertTemplates(node, method);
            // return type must be assigned AFTER ConvertTemplates
            method.ReturnType = CreateReturnType(node, method);
            ConvertParameters(node.Parameters, method);
            _currentClass.Peek().Methods.Add(method);
            method.UserData = node;
        }
 public override void OnMethod(Boo.Lang.Compiler.Ast.Method node)
 {
     CheckExtensionSemantics(node);
 }