Inheritance: Boo.Lang.Compiler.Ast.CallableDefinition, IExplicitMember, INodeWithBody
コード例 #1
0
		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;
		}
コード例 #2
0
 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);
     }
 }
コード例 #3
0
ファイル: CodeReifierTest.cs プロジェクト: 0xb1dd1e/boo
			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);
			}
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: ViewStateAttribute.cs プロジェクト: 0xb1dd1e/boo
		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;
		}
コード例 #6
0
 public override void LeaveMethod(Method node)
 {
     if (node.Body.IsEmpty)
     {
         RemoveCurrentNode();
     }
 }
コード例 #7
0
ファイル: ActionMacro.cs プロジェクト: f4i2u1/rhino-etl
        /// <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;
        }
コード例 #8
0
 public override void OnMethod(Method node)
 {
     if (LookingFor(node))
     {
         Found(node.ReturnType);
     }
 }
コード例 #9
0
ファイル: Parse.cs プロジェクト: CarlosHBC/UnityDecompiled
 public void NormalizeGetter(Method getter)
 {
     if ((getter != null) && (getter.get_Parameters().get_Count() != 0))
     {
         this.ReportError(UnityScriptCompilerErrors.InvalidPropertyGetter(getter.get_LexicalInfo()));
     }
 }
コード例 #10
0
ファイル: Parse.cs プロジェクト: CarlosHBC/UnityDecompiled
 public void CheckSetterReturnType(Method setter)
 {
     if (setter.get_ReturnType() != null)
     {
         this.ReportError(UnityScriptCompilerErrors.SetterCanNotDeclareReturnType(setter.get_ReturnType().get_LexicalInfo()));
     }
 }
コード例 #11
0
ファイル: DetectInnerGenerics.cs プロジェクト: Rfvgyhn/boo
		public override void OnMethod(Method node)
		{
			var old = _currentMethod;
			_currentMethod = (IMethod) node.Entity;
			base.OnMethod(node);
			_currentMethod = old;
		}
コード例 #12
0
ファイル: PreErrorChecking.cs プロジェクト: 0xb1dd1e/boo
		override public void LeaveMethod(Method node)
		{
			MakeStaticIfNeeded(node);
			CantBeMarkedTransient(node);
			CantBeMarkedPartial(node);
			CheckExplicitImpl(node);
			CheckModifierCombination(node);
		}
コード例 #13
0
ファイル: Parse.cs プロジェクト: CarlosHBC/UnityDecompiled
 public void NormalizeSetter(Method setter)
 {
     if (setter != null)
     {
         this.NormalizeSetterParameters(setter);
         this.CheckSetterReturnType(setter);
     }
 }
コード例 #14
0
ファイル: ProcessGenerators.cs プロジェクト: Bombadil77/boo
        public override void LeaveMethod(Method method)
        {
            InternalMethod entity = (InternalMethod)method.Entity;
            if (!entity.IsGenerator) return;

            GeneratorMethodProcessor processor = new GeneratorMethodProcessor(Context, entity);
            processor.Run();
        }
コード例 #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));
 }
コード例 #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;
 }
コード例 #17
0
ファイル: BooMethodBuilder.cs プロジェクト: 0xb1dd1e/boo
		public BooMethodBuilder(BooCodeBuilder codeBuilder, Method method)
		{
			if (null == codeBuilder)
				throw new ArgumentNullException("codeBuilder");
			if (null == method)
				throw new ArgumentNullException("method");
			_codeBuilder = codeBuilder;
			_method = method;
		}
コード例 #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);
		}
コード例 #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));
 }
コード例 #20
0
 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);
     }
 }
コード例 #21
0
ファイル: BooMethodBuilder.cs プロジェクト: 0xb1dd1e/boo
		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);
		}
コード例 #22
0
 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);
         }
     }
 }
コード例 #23
0
        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);
        }
コード例 #24
0
ファイル: TerminateMacro.cs プロジェクト: f4i2u1/rhino-etl
        /// <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;
        }
コード例 #25
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 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;
        }
コード例 #26
0
 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;
         }
     }
 }
コード例 #27
0
ファイル: CheckIdentifiers.cs プロジェクト: HaKDMoDz/GNet
		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);
			}
		}
コード例 #28
0
ファイル: GroupByMacro.cs プロジェクト: nkmajeti/rhino-tools
        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;
        }
コード例 #29
0
ファイル: ContextAnnotations.cs プロジェクト: 0xb1dd1e/boo
		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;
		}
コード例 #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);
     }
 }
コード例 #31
0
        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);
        }
コード例 #32
0
        /// <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);
        }
コード例 #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;
        }
コード例 #34
0
 public override void OnMethod(Boo.Lang.Compiler.Ast.Method node)
 {
     CheckExtensionSemantics(node);
 }