当前位置: 首页>>代码示例>>C#>>正文


C# BlockStatement.Add方法代码示例

本文整理汇总了C#中BlockStatement.Add方法的典型用法代码示例。如果您正苦于以下问题:C# BlockStatement.Add方法的具体用法?C# BlockStatement.Add怎么用?C# BlockStatement.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockStatement的用法示例。


在下文中一共展示了BlockStatement.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TransformBlock

		Ast.BlockStatement TransformBlock(ILBlock block)
		{
			Ast.BlockStatement astBlock = new BlockStatement();
			if (block != null) {
				if (block.EntryGoto != null)
					astBlock.Add((Statement)TransformExpression(block.EntryGoto));
				foreach(ILNode node in block.Body) {
					astBlock.AddRange(TransformNode(node));
				}
			}
			return astBlock;
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:12,代码来源:AstMethodBodyBuilder.cs

示例2: GetActions

		public override IEnumerable<CodeAction> GetActions (RefactoringContext context)
		{
			// lambda
			var lambda = context.GetNode<LambdaExpression> ();
			if (lambda != null && lambda.ArrowToken.Contains(context.Location)) {
				if (ContainsLocalReferences (context, lambda, lambda.Body))
					yield break;

				bool noReturn = false;
				BlockStatement body;
				if (lambda.Body is BlockStatement) {
					body = (BlockStatement)lambda.Body.Clone ();
				} else {
					if (!(lambda.Body is Expression))
						yield break;
					body = new BlockStatement ();

					var type = LambdaHelper.GetLambdaReturnType (context, lambda);
					if (type == null || type.ReflectionName == "System.Void") {
						noReturn = true;
						body.Add ((Expression)lambda.Body.Clone ());
					} else {
						body.Add (new ReturnStatement ((Expression)lambda.Body.Clone ()));
					}
				}
				var method = GetMethod (context, (LambdaResolveResult)context.Resolve (lambda), body, noReturn);
				yield return GetAction (context, lambda, method);
			}

			// anonymous method
			var anonymousMethod = context.GetNode<AnonymousMethodExpression> ();
			if (anonymousMethod != null && anonymousMethod.DelegateToken.Contains(context.Location)) {
				if (ContainsLocalReferences (context, anonymousMethod, anonymousMethod.Body))
					yield break;

				var method = GetMethod (context, (LambdaResolveResult)context.Resolve (anonymousMethod), 
										(BlockStatement)anonymousMethod.Body.Clone ());
				yield return GetAction (context, anonymousMethod, method);
			}
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:40,代码来源:ExtractAnonymousMethodAction.cs

示例3: Insert

			public override void Insert()
			{
				BlockStatement newBlock = new BlockStatement();
				// Move all statements except for the first
				Statement next;
				for (Statement stmt = firstStatement.GetNextStatement(); stmt != lastStatement; stmt = next) {
					next = stmt.GetNextStatement();
					newBlock.Add(stmt.Detach());
				}
				// Replace the first statement with the new (un)checked block
				if (isChecked)
					firstStatement.ReplaceWith(new CheckedStatement { Body = newBlock });
				else
					firstStatement.ReplaceWith(new UncheckedStatement { Body = newBlock });
				// now also move the first node into the new block
				newBlock.Statements.InsertAfter(null, firstStatement);
			}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:17,代码来源:AddCheckedBlocks.cs

示例4: BlockStatement

        public BlockStatement BlockStatement(INode ParentNode=null, IStatement Parent=null)
        {
            var OldPreviousCommentString = PreviousComment;
            PreviousComment = new StringBuilder ();

            var bs = new BlockStatement() { Location=la.Location, ParentNode=ParentNode, Parent=Parent};

            if (Expect(OpenCurlyBrace))
            {
                if (ParseStructureOnly && laKind != CloseCurlyBrace)
                    Lexer.SkipCurrentBlock();
                else
                {
                    while (!IsEOF && laKind != (CloseCurlyBrace))
                    {
                        var prevLocation = la.Location;
                        var s = Statement(Scope: ParentNode as IBlockNode, Parent: bs);

                        // Avoid infinite loops -- hacky?
                        if (prevLocation == la.Location)
                        {
                            Step();
                            break;
                        }

                        bs.Add(s);
                    }
                }

                if (!Expect(CloseCurlyBrace) && IsEOF)
                {
                    bs.EndLocation = la.Location;
                    return bs;
                }
            }
            if(t!=null)
                bs.EndLocation = t.EndLocation;

            PreviousComment = OldPreviousCommentString;
            return bs;
        }
开发者ID:rainers,项目名称:D_Parser,代码行数:41,代码来源:Parser_Impl.cs

示例5: TransformByteCode

        AstNode TransformByteCode(ILExpression byteCode, List<Ast.Expression> args)
        {
            ILCode opCode = byteCode.Code;
            object operand = byteCode.Operand;
            AstType operandAsTypeRef = AstBuilder.ConvertType(operand as Cecil.TypeReference);
            ILExpression operandAsByteCode = operand as ILExpression;
            Ast.Expression arg1 = args.Count >= 1 ? args[0] : null;
            Ast.Expression arg2 = args.Count >= 2 ? args[1] : null;
            Ast.Expression arg3 = args.Count >= 3 ? args[2] : null;

            BlockStatement branchCommand = null;
            if (byteCode.Operand is ILLabel) {
                branchCommand = new BlockStatement();
                branchCommand.Add(new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name));
            }

            switch((Code)opCode) {
                    #region Arithmetic
                    case Code.Add:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
                    case Code.Add_Ovf:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
                    case Code.Add_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
                    case Code.Div:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
                    case Code.Div_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
                    case Code.Mul:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
                    case Code.Mul_Ovf:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
                    case Code.Mul_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
                    case Code.Rem:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
                    case Code.Rem_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
                    case Code.Sub:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
                    case Code.Sub_Ovf:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
                    case Code.Sub_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
                    case Code.And:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseAnd, arg2);
                    case Code.Or:         return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseOr, arg2);
                    case Code.Xor:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ExclusiveOr, arg2);
                    case Code.Shl:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftLeft, arg2);
                    case Code.Shr:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);
                    case Code.Shr_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);

                    case Code.Neg:        return new Ast.UnaryOperatorExpression(UnaryOperatorType.Minus, arg1);
                    case Code.Not:        return new Ast.UnaryOperatorExpression(UnaryOperatorType.BitNot, arg1);
                    #endregion
                    #region Arrays
                case Code.Newarr:
                    {
                        var ace = new Ast.ArrayCreateExpression();
                        ace.Type = operandAsTypeRef;
                        ace.Arguments.Add(arg1);
                        return ace;
                    }
                case Code.Ldlen:
                    return arg1.Member("Length");
                case Code.Ldelem_I:
                case Code.Ldelem_I1:
                case Code.Ldelem_I2:
                case Code.Ldelem_I4:
                case Code.Ldelem_I8:
                case Code.Ldelem_U1:
                case Code.Ldelem_U2:
                case Code.Ldelem_U4:
                case Code.Ldelem_R4:
                case Code.Ldelem_R8:
                case Code.Ldelem_Ref:
                    return arg1.Indexer(arg2);
                case Code.Ldelem_Any:
                    return InlineAssembly(byteCode, args);
                case Code.Ldelema:
                    return MakeRef(arg1.Indexer(arg2));

                case Code.Stelem_I:
                case Code.Stelem_I1:
                case Code.Stelem_I2:
                case Code.Stelem_I4:
                case Code.Stelem_I8:
                case Code.Stelem_R4:
                case Code.Stelem_R8:
                case Code.Stelem_Ref:
                    return new Ast.AssignmentExpression(arg1.Indexer(arg2), arg3);
                case Code.Stelem_Any:
                    return InlineAssembly(byteCode, args);
                    #endregion
                    #region Branching
                    case Code.Br:      return new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name);
                    case Code.Brfalse: return new Ast.IfElseStatement(new Ast.UnaryOperatorExpression(UnaryOperatorType.Not, arg1), branchCommand);
                    case Code.Brtrue:  return new Ast.IfElseStatement(arg1, branchCommand);
                    case Code.Beq:     return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, arg2), branchCommand);
                    case Code.Bge:     return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand);
                    case Code.Bge_Un:  return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand);
                    case Code.Bgt:     return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand);
                    case Code.Bgt_Un:  return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand);
                    case Code.Ble:     return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand);
                    case Code.Ble_Un:  return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand);
                    case Code.Blt:     return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand);
                    case Code.Blt_Un:  return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand);
                    case Code.Bne_Un:  return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.InEquality, arg2), branchCommand);
                    #endregion
                    #region Comparison
                    case Code.Ceq:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, arg2);
                    case Code.Cgt:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2);
                case Code.Cgt_Un:
                    // can also mean Inequality, when used with object references
//.........这里部分代码省略.........
开发者ID:petr-k,项目名称:ILSpy,代码行数:101,代码来源:AstMethodBodyBuilder.cs

示例6: GetExplicitInterfaceTypes

        /// <summary>
        /// Builds and adds the needed nested types in a current type representing explicit interfaces
        /// </summary>
        /// <param name="currentType"></param>
        public static void GetExplicitInterfaceTypes(TypeDeclaration currentType)
        {
            //Trim the type name to avoid errors with generic types
            string currentTypeName = currentType.Name.TrimEnd("_Base".ToCharArray()).TrimEnd("_T".ToCharArray());

            //SEARCH FOR THE METHODS IN THE CURRENT TYPE THAT SHOULD BE IMPLEMENTED IN A NESTED CLASS
            List<MethodDeclaration> methodsOfCurrentType = new List<MethodDeclaration>();
            foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in Cache.GetPrivateImplementation())
            {
                foreach (MethodDeclaration m in kvp.Value)
                {
                    if (m.TypeMember.Name == currentTypeName)
                        methodsOfCurrentType.Add(m);
                }
            }

            //CREATE A DICTIONARY WITH THE NESTEDCLASS AND METHODS NEEDED (SORTED)
            Dictionary<AstType, List<MethodDeclaration>> privateImplClass = new Dictionary<AstType, List<MethodDeclaration>>();
            foreach (MethodDeclaration m in methodsOfCurrentType)
            {
                foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in Cache.GetPrivateImplementation())
                {
                    if (kvp.Value.Contains(m))
                    {
                        //If the method private implementation is corresponding to the current key type in the loop, continue
                        if (GetTypeName(m.PrivateImplementationType) == GetTypeName(kvp.Key))
                        {
                            //REMOVE THE METHOD FROM THE CURRENT TYPE                            
                            currentType.Members.Remove(m);
                            RemoveHeaderNode(m, currentType);

                            //REMOVE THE PRIVATE IMPLEMENTATION
                            m.PrivateImplementationType = Ast.AstType.Null;

                            //Add the method in the sorted dictionary
                            if (privateImplClass.ContainsKey(kvp.Key))
                                privateImplClass[kvp.Key].Add((MethodDeclaration)m.Clone());

                            else
                                privateImplClass.Add(kvp.Key, new List<MethodDeclaration>() { (MethodDeclaration)m.Clone() });

                        }
                    }
                }
            }

            //CREATE FROM THE NESTED CLASS THE NESTEDTYPEDECLARATION NODE
            foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in privateImplClass)
            {
                TypeDeclaration type = new TypeDeclaration();
                string nestedTypeName = "_interface_" + GetTypeName(kvp.Key);
                type.NameToken = new Identifier(nestedTypeName, TextLocation.Empty);
                type.Name = nestedTypeName;
                type.ModifierTokens.Add(new CppModifierToken(TextLocation.Empty, Modifiers.Public));

                if (kvp.Key is SimpleType)
                {
                    foreach (AstType tp in (kvp.Key as SimpleType).TypeArguments)
                        type.TypeParameters.Add(new TypeParameterDeclaration() { NameToken = new Identifier(GetTypeName(tp), TextLocation.Empty) });
                }

                //ADD BASE TYPES
                SimpleType baseType = new SimpleType(GetTypeName(kvp.Key));
                if (kvp.Key is SimpleType)
                {
                    foreach (AstType tp in (kvp.Key as SimpleType).TypeArguments)
                        baseType.TypeArguments.Add((AstType)tp.Clone());
                }

                type.AddChild(baseType, TypeDeclaration.BaseTypeRole);

                //REMOVE THE BASE TYPE BECAUSE THE NESTED TYPE WILL INHERIT FROM IT
                try
                {
                    currentType.BaseTypes.Remove(currentType.BaseTypes.First(x => GetTypeName(x) == GetTypeName(baseType)));
                }
                catch (InvalidOperationException)
                {
                    //The element is not present in the list
                    //Safe to ignore this :)
                }

                //ADD METHODS
                type.Members.AddRange(kvp.Value);

                //ADD FIELD
                HeaderFieldDeclaration fdecl = new HeaderFieldDeclaration();
                SimpleType nestedType = new SimpleType(nestedTypeName);
                foreach (TypeParameterDeclaration tp in type.TypeParameters)
                    nestedType.TypeArguments.Add(new SimpleType(tp.Name));

                ExplicitInterfaceTypeDeclaration ntype = new Ast.ExplicitInterfaceTypeDeclaration(type);

                fdecl.ReturnType = nestedType;
                string _tmp = "_" + GetTypeName(fdecl.ReturnType).ToLower();
                fdecl.Variables.Add(new VariableInitializer(_tmp));
//.........这里部分代码省略.........
开发者ID:AlexAlbala,项目名称:Alter-Native,代码行数:101,代码来源:Resolver.cs

示例7: VisitLambdaExpression

        public void VisitLambdaExpression(LambdaExpression node)
        {
            // Convert "() => 0" to "() => { return 0; }"
            if (node.Body.NodeType == NodeType.Expression) {
                var expression = (Expression)node.Body;
                var block = new BlockStatement();
                expression.ReplaceWith(block);
                block.Add(new ReturnStatement(expression));
            }

            VisitChildren(node);
        }
开发者ID:evanw,项目名称:minisharp,代码行数:12,代码来源:Lower.cs

示例8: UpdateBlockPartly

        public static IBlockNode UpdateBlockPartly(this BlockStatement bs, string code, int caretOffset, CodeLocation caretLocation, out bool isInsideNonCodeSegment)
        {
            isInsideNonCodeSegment = false;
            var finalParentMethod = bs.ParentNode as DMethod;
            var finalStmtsList = bs._Statements;

            var startLoc = bs.Location;
            int startStmtIndex;
            for(startStmtIndex = finalStmtsList.Count-1; startStmtIndex >= 0; startStmtIndex--) {
                var n = finalStmtsList [startStmtIndex];
                if (n.EndLocation.Line > 0 && n.EndLocation.Line < caretLocation.Line) {
                    startLoc = --startStmtIndex == -1 ?
                        bs.Location : finalStmtsList [startStmtIndex].EndLocation;
                    break;
                }
            }

            var startOff = startLoc.Line > 1 ? DocumentHelper.GetOffsetByRelativeLocation (code, caretLocation, caretOffset, startLoc) : 0;

            if (startOff >= caretOffset)
                return null;

            var tempParentBlock = new DMethod();//new DBlockNode();
            var tempBlockStmt = new BlockStatement { ParentNode = tempParentBlock };
            tempParentBlock.Body = tempBlockStmt;
            tempBlockStmt.Location = startLoc;
            tempParentBlock.Location = startLoc;

            using (var sv = new StringView (code, startOff, caretOffset - startOff))
            using (var p = DParser.Create(sv)) {
                p.Lexer.SetInitialLocation (startLoc);
                p.Step ();

                if(p.laKind == DTokens.OpenCurlyBrace)
                    p.Step();

                while (!p.IsEOF) {

                    if (p.laKind == DTokens.CloseCurlyBrace) {
                        p.Step ();
                        /*if (metaDecls.Count > 0)
                            metaDecls.RemoveAt (metaDecls.Count - 1);*/
                        continue;
                    }

                    var stmt = p.Statement (true, false, tempParentBlock, tempBlockStmt);
                    if (stmt != null)
                        tempBlockStmt.Add(stmt);
                    else
                        p.Step();
                }

                tempBlockStmt.EndLocation = new CodeLocation(p.la.Column+1,p.la.Line);
                tempParentBlock.EndLocation = tempBlockStmt.EndLocation;

                if(isInsideNonCodeSegment = p.Lexer.endedWhileBeingInNonCodeSequence)
                    return null;
            }

            DoubleDeclarationSilencer.RemoveDoubles(finalParentMethod, tempParentBlock);

            tempParentBlock.Parent = finalParentMethod;
            //tempParentBlock.Add(new PseudoStaticStmt { Block = tempBlockStmt, ParentNode = tempParentBlock, Location = tempBlockStmt.Location, EndLocation = tempBlockStmt.EndLocation });

            return tempParentBlock;
        }
开发者ID:Extrawurst,项目名称:D_Parser,代码行数:66,代码来源:IncrementalParsing.cs

示例9: BlockStatement

        public BlockStatement BlockStatement(INode ParentNode=null, IStatement Parent=null)
        {
            var OldPreviousCommentString = PreviousComment;
            PreviousComment = "";

            var bs = new BlockStatement() { StartLocation=la.Location, ParentNode=ParentNode, Parent=Parent};
            LastParsedObject = bs;

            if (Expect(OpenCurlyBrace))
            {
                if (ParseStructureOnly && laKind != CloseCurlyBrace)
                {
                    Lexer.SkipCurrentBlock();
                    laKind = la.Kind;
                }
                else
                    while (!IsEOF && laKind != (CloseCurlyBrace))
                    {
                        var s = Statement(Scope: ParentNode as IBlockNode);
                        bs.Add(s);
                    }
                if (Expect(CloseCurlyBrace))
                    LastParsedObject = null;

                if (!IsEOF)
                    LastParsedObject = bs;
            }
            if(t!=null)
                bs.EndLocation = t.EndLocation;

            PreviousComment = OldPreviousCommentString;
            return bs;
        }
开发者ID:nazriel,项目名称:Mono-D,代码行数:33,代码来源:Parser_Impl.cs

示例10: UpdateBlockPartly

        public static void UpdateBlockPartly(this BlockStatement bs, string code, int caretOffset, CodeLocation caretLocation, out bool isInsideNonCodeSegment)
        {
            isInsideNonCodeSegment = false;
            var finalParentMethod = bs.ParentNode as DMethod;
            var finalStmtsList = bs._Statements;

            var startLoc = bs.Location;
            int startStmtIndex;
            for(startStmtIndex = finalStmtsList.Count-1; startStmtIndex >= 0; startStmtIndex--) {
                var n = finalStmtsList [startStmtIndex];
                if (n.EndLocation.Line > 0 && n.EndLocation.Line < caretLocation.Line) {
                    startLoc = --startStmtIndex == -1 ?
                        bs.Location : finalStmtsList [startStmtIndex].EndLocation;
                    break;
                }
            }

            var startOff = startLoc.Line > 1 ? DocumentHelper.GetOffsetByRelativeLocation (code, caretLocation, caretOffset, startLoc) : 0;

            if (startOff >= caretOffset)
                return;

            var tempParentBlock = new DMethod ();
            var tempBlockStmt = new BlockStatement { ParentNode = tempParentBlock };

            try{
                using (var sv = new StringView (code, startOff, caretOffset - startOff))
                using (var p = DParser.Create(sv)) {
                    p.Lexer.SetInitialLocation (startLoc);
                    p.Step ();

                    if(p.laKind == DTokens.OpenCurlyBrace)
                        p.Step();

                    while (!p.IsEOF) {

                        if (p.laKind == DTokens.CloseCurlyBrace) {
                            p.Step ();
                            /*if (metaDecls.Count > 0)
                                metaDecls.RemoveAt (metaDecls.Count - 1);*/
                            continue;
                        }

                        var stmt = p.Statement (true, true, tempParentBlock, tempBlockStmt);
                        if(stmt != null)
                            tempBlockStmt.Add(stmt);
                    }

                    tempBlockStmt.EndLocation = new CodeLocation(p.la.Column+1,p.la.Line);

                    if(isInsideNonCodeSegment = p.Lexer.endedWhileBeingInNonCodeSequence)
                        return;
                }
            }catch(Exception ex) {
                Console.WriteLine (ex.Message);
            }

            // Remove old statements from startLoc until caretLocation
            int i = startStmtIndex + 1;
            while (i < finalStmtsList.Count && finalStmtsList [i].Location < caretLocation)
                finalStmtsList.RemoveAt (i);

            // Insert new statements
            if (tempBlockStmt.EndLocation > bs.EndLocation)
                bs.EndLocation = tempBlockStmt.EndLocation;
            foreach (var stmt in tempBlockStmt._Statements)
            {
                stmt.ParentNode = finalParentMethod;
                stmt.Parent = bs;
            }
            AssignInStatementDeclarationsToNewParentNode(tempBlockStmt, finalParentMethod);
            finalStmtsList.InsertRange(startStmtIndex+1, tempBlockStmt._Statements);

            if (finalParentMethod != null) {
                var finalParentChildren = finalParentMethod.AdditionalChildren;
                // Remove old parent block children
                int startDeclIndex;
                for(startDeclIndex = finalParentChildren.Count-1; startDeclIndex >= 0; startDeclIndex--) {
                    var n = finalParentChildren [startDeclIndex];
                    if (n == null) {
                        finalParentChildren.RemoveAt (startDeclIndex);
                        continue;
                    }
                    if (n.Location < startLoc)
                        break;
                    if (n.Location < caretLocation)
                        finalParentChildren.RemoveAt(startDeclIndex);
                }

                // Insert new special declarations
                foreach (var decl in tempParentBlock)
                    decl.Parent = finalParentMethod;
                finalParentChildren.InsertRange(startDeclIndex+1, tempParentBlock);

                finalParentMethod.UpdateChildrenArray ();
                if (bs.EndLocation > finalParentMethod.EndLocation)
                    finalParentMethod.EndLocation = bs.EndLocation;
            }

            //TODO: Handle DBlockNode parents?
//.........这里部分代码省略.........
开发者ID:rainers,项目名称:D_Parser,代码行数:101,代码来源:IncrementalParsing.cs

示例11: VisitInvocationExpression

			public override void VisitInvocationExpression (InvocationExpression invocationExpression)
			{
				base.VisitInvocationExpression (invocationExpression);

				var hasRefs = invocationExpression.Arguments.OfType<DirectionExpression> ().Any ();

				if (hasRefs) {

					var args = invocationExpression.Arguments.OfType<DirectionExpression> ().ToList ();

					var target = invocationExpression.Target;

					var lblock = new BlockStatement {

					};

					for (int i = 0; i < args.Count; i++) {
						var a = args [i];
						var vname = "_p" + i;
						var va = new VariableDeclarationStatement (AstType.Null, vname, new ArrayCreateExpression {
							Initializer = new ArrayInitializerExpression (a.Expression.Clone ())
						});
						a.ReplaceWith (new IdentifierExpression (vname));
						lblock.Add (va);
					}
					var rname = "_r";
					var ra = new VariableDeclarationStatement (AstType.Null, rname, invocationExpression.Clone ());
					lblock.Add (ra);
					for (int i = 0; i < args.Count; i++) {
						var a = args [i];
						var vname = "_p" + i;
						var va = new AssignmentExpression (a.Expression.Clone (), 
							new IndexerExpression (
								new IdentifierExpression (vname), new PrimitiveExpression (0)));
						lblock.Add (va);
					}
					lblock.Add (new ReturnStatement (new IdentifierExpression (rname)));

					var lambda = new LambdaExpression {
						Body = lblock,
					};

					var ilambda = new InvocationExpression (lambda);

					invocationExpression.ReplaceWith (ilambda);
				}
			}
开发者ID:RReverser,项目名称:Netjs,代码行数:47,代码来源:CsToTs.cs

示例12: VisitMethodDeclaration

			public override void VisitMethodDeclaration (MethodDeclaration methodDeclaration)
			{
				base.VisitMethodDeclaration (methodDeclaration);

				if (methodDeclaration.Body.IsNull && methodDeclaration.GetParent<TypeDeclaration> ().ClassType != ClassType.Interface ) {
					var block = new BlockStatement ();
					block.Add (new ThrowStatement (new ObjectCreateExpression (new SimpleType ("NotSupportedException"))));
					methodDeclaration.Body = block;

				}
			}
开发者ID:RReverser,项目名称:Netjs,代码行数:11,代码来源:CsToTs.cs

示例13: VisitTryCatchStatement

			public override void VisitTryCatchStatement (TryCatchStatement tryCatchStatement)
			{
				base.VisitTryCatchStatement (tryCatchStatement);

				var catches = tryCatchStatement.CatchClauses.ToList ();
				if (catches.Count == 0)
					return;

				var varName = catches.Where (x => !string.IsNullOrEmpty (x.VariableName)).Select (x => x.VariableName).FirstOrDefault ();
				if (varName == null) {
					varName = "_ex";
				}

				//
				// Fix first
				//
				foreach (var c in catches) {
					if (string.IsNullOrEmpty (c.VariableName)) {
						c.VariableName = varName;
					}
				}

				//
				// Merge them
				//
				if (catches.Count > 0) {
					var body = new BlockStatement ();
					var newCatch = new CatchClause {
						VariableName = varName,
						Body = body,
					};

					IfElseStatement lastIf = null;

					foreach (var c in catches) {

						var cbody = c.Body;
						cbody.Remove ();

						var iff = new IfElseStatement (GetNotNullTypeCheck (varName, c.Type), cbody);

						if (lastIf == null)
							body.Add (iff);
						else
							lastIf.FalseStatement = iff;

						lastIf = iff;

						c.Remove ();
					}

					var rethrow = new ThrowStatement (new IdentifierExpression (varName));

					if (lastIf == null)
						body.Add (rethrow);
					else
						lastIf.FalseStatement = rethrow;

					tryCatchStatement.CatchClauses.Add (newCatch);
				}
			}
开发者ID:RReverser,项目名称:Netjs,代码行数:61,代码来源:CsToTs.cs

示例14: Generate

        private string Generate(String fieldName, String propertyTypeName, string indent)
        {
            String lowerName = fieldName.Substring(0, 1).ToLowerInvariant() + fieldName.Substring(1);
            String upperName = fieldName.Substring(0, 1).ToUpperInvariant() + fieldName.Substring(1);

            String getterName = lowerName;
            String setterName = "set" + upperName + ":";

            // Create the field declaration
            //FieldDeclaration fieldDeclaration = GetFieldDeclaration(lowerName, new SimpleType (propertyTypeName));
            String fieldDeclaration = String.Format("private {0} {1};", propertyTypeName, lowerName);

            // Create the property declaration
            PropertyDeclaration propertyDeclaration = GetPropertyDeclaration(upperName, new SimpleType (propertyTypeName));

            {
                // Create the attribute
                AttributeSection attributeSection = new AttributeSection ();
                var attribute = GetAttribute(Constants.OBJECTIVE_C_MESSAGE_SHORTFORM, getterName);
                attributeSection.Attributes.Add (attribute);

                // Create the member reference
                MemberReferenceExpression memberReferenceExpression = new MemberReferenceExpression(new ThisReferenceExpression (), lowerName);
                ReturnStatement returnStatement = new ReturnStatement (memberReferenceExpression);

                // Create the "get" region
                propertyDeclaration.Getter = new Accessor();
                propertyDeclaration.Getter.Attributes.Add(attributeSection);
                propertyDeclaration.Getter.Body = new BlockStatement ();
                propertyDeclaration.Getter.Body.Add(returnStatement);
            }

            {
                // Create the attribute
                AttributeSection attributeSection = new AttributeSection ();
                var attribute = GetAttribute(Constants.OBJECTIVE_C_MESSAGE_SHORTFORM, setterName);
                attributeSection.Attributes.Add (attribute);

                BlockStatement blockStatement = new BlockStatement();
                // Create a simple assignment
                MemberReferenceExpression memberReferenceExpression2 = new MemberReferenceExpression(new ThisReferenceExpression (), lowerName);
                AssignmentExpression assignmentExpression = new AssignmentExpression(memberReferenceExpression2, new IdentifierExpression ("value"));
                blockStatement.Add(assignmentExpression);

                // Create the "set" region
                propertyDeclaration.Setter = new Accessor();
                propertyDeclaration.Setter.Attributes.Add(attributeSection);
                propertyDeclaration.Setter.Body = blockStatement;
            }

            // Return the result of the AST generation
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(fieldDeclaration);
            builder.AppendLine();
            builder.AppendLine(this.Options.OutputNode(propertyDeclaration));
            String generated = builder.ToString();

            // Add ident space
            return Indent(generated, indent);
        }
开发者ID:Monobjc,项目名称:monobjc-monodevelop,代码行数:60,代码来源:CreatePropertyDialog.cs

示例15: GenerateCode

		protected override string GenerateCode(ITypeDefinition currentClass)
		{
			MethodDeclaration insertedOverrideMethod = refactoringContext.GetNode().PrevSibling as MethodDeclaration;
			if (insertedOverrideMethod == null)
			{
				// We are not inside of a method declaration
				return null;
			}
			
			using (Script script = refactoringContext.StartScript()) {
				NewLineNode nextNewLineNode = insertedOverrideMethod.NextSibling as NewLineNode;
				
//			if (Options.AddIEquatableInterface) {
				// TODO : add IEquatable<T> to class
//				IAmbience ambience = currentClass.CompilationUnit.Language.GetAmbience();
//
//				IReturnType baseRType = currentClass.CompilationUnit.ProjectContent.GetClass("System.IEquatable", 1).DefaultReturnType;
//
//				IClass newClass = new DefaultClass(currentClass.CompilationUnit, currentClass.FullyQualifiedName, currentClass.Modifiers, currentClass.Region, null);
//
//				foreach (IReturnType type in currentClass.BaseTypes) {
//					newClass.BaseTypes.Add(type);
//				}
//
//
//				newClass.BaseTypes.Add(new ConstructedReturnType(baseRType, new List<IReturnType>() { currentClass.DefaultReturnType }));
//
//				ambience.ConversionFlags = ConversionFlags.IncludeBody;
//
//				string a = ambience.Convert(currentClass);
//
//				int startOffset = editor.Document.PositionToOffset(currentClass.Region.BeginLine, currentClass.Region.BeginColumn);
//				int endOffset = editor.Document.PositionToOffset(currentClass.BodyRegion.EndLine, currentClass.BodyRegion.EndColumn);
//
//				editor.Document.Replace(startOffset, endOffset - startOffset, a);
//			}
				
				if (Options.SurroundWithRegion) {
					script.InsertBefore(insertedOverrideMethod, new PreProcessorDirective(PreProcessorDirectiveType.Region, "Equals and GetHashCode implementation"));
				}
				
				if ("Equals".Equals(selectedMethod.Name, StringComparison.Ordinal)) {
					IList<MethodDeclaration> equalsOverrides = CreateEqualsOverrides(currentClass);
					MethodDeclaration defaultOverride = equalsOverrides.First();
					equalsOverrides = equalsOverrides.Skip(1).ToList();
					
					// Insert children of default Equals method into
					foreach (AstNode element in defaultOverride.Body.Children) {
						script.AddTo(insertedOverrideMethod.Body, element.Clone());
					}
					
					// Add other Equals() overrides after our main inserted method
					if (addOtherMethod.IsChecked == true) {
						if (equalsOverrides.Any()) {
							foreach (var equalsMethod in equalsOverrides) {
								AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
								script.InsertAfter(insertedOverrideMethod, equalsMethod);
							}
						}
						
						AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
						script.InsertAfter(insertedOverrideMethod, CreateGetHashCodeOverride(currentClass));
					}
				} else {
					StringBuilder builder = new StringBuilder();
					
					foreach (AstNode element in CreateGetHashCodeOverride(currentClass).Body.Children) {
						script.AddTo(insertedOverrideMethod.Body, element.Clone());
					}
					
					if (addOtherMethod.IsChecked == true) {
						foreach (var equalsMethod in CreateEqualsOverrides(currentClass)) {
							AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
							script.InsertAfter(insertedOverrideMethod, equalsMethod);
						}
					}
				}
				
				if (Options.AddOperatorOverloads) {
					var checkStatements = new[] {
						new IfElseStatement(
							new InvocationExpression(
								new IdentifierExpression("ReferenceEquals"),
								new List<Expression>() { new IdentifierExpression("lhs"), new IdentifierExpression("rhs") }
							),
							new ReturnStatement(new PrimitiveExpression(true))
						),
						new IfElseStatement(
							new BinaryOperatorExpression(
								new InvocationExpression(
									new IdentifierExpression("ReferenceEquals"),
									new List<Expression>() { new IdentifierExpression("lhs"), new PrimitiveExpression(null) }
								),
								BinaryOperatorType.ConditionalOr,
								new InvocationExpression(
									new IdentifierExpression("ReferenceEquals"),
									new List<Expression>() { new IdentifierExpression("rhs"), new PrimitiveExpression(null) }
								)
							),
							new ReturnStatement(new PrimitiveExpression(false))
//.........这里部分代码省略.........
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:101,代码来源:OverrideEqualsGetHashCodeMethodsDialog.xaml.cs


注:本文中的BlockStatement.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。