private AbstractNode AddParms(AbstractNode invocation, IList<object> parameters)
        {
            if (invocation == null)
            {
                throw new ArgumentNullException("invocation");
            }

            var m = invocation as Statement;
            if (m != null)
                invocation = m.DeepCopy();
            else
            {

                var q = invocation as Expression;
                if (q != null)
                {
                    invocation = q.DeepCopy();
                }
                else
                {
                    throw new Exception("Found a " + invocation.GetType());
                }
            }

            InvocationExpression ie = FirstInvocationExpression(invocation);

            foreach (var o in parameters)
            {
                ie.AddArg(o);
            }

            return invocation;
        }
Example #2
0
		public static string ToText(AbstractNode node)
		{
			var output = new CSharpOutputVisitor();
			node.AcceptVisitor(output, null);

			return output.Text;
		}
		public override string GenerateCode(AbstractNode node, string indentation)
		{
			IOutputAstVisitor visitor = CreateOutputVisitor();
			int indentCount = 0;
			foreach (char c in indentation) {
				if (c == '\t')
					indentCount += 4;
				else
					indentCount += 1;
			}
			visitor.OutputFormatter.IndentationLevel = indentCount / 4;
			if (node is Statement)
				visitor.OutputFormatter.Indent();
			node.AcceptVisitor(visitor, null);
			string text = visitor.Text;
			if (node is Statement && !text.EndsWith("\n"))
				text += Environment.NewLine;
			return text;
		}
		public override string GenerateCode(AbstractNode node, string indentation)
		{
			StringBuilder errorBuilder = new StringBuilder();
			ConverterSettings settings = new ConverterSettings("codegeneration.cs");
			string output = null;
			
			Node booNode = (Node)node.AcceptVisitor(new ConvertVisitor(settings), null);
			
			if (settings.Errors.Count > 0) {
				foreach (CompilerError error in settings.Errors) {
					errorBuilder.AppendLine(error.ToString());
				}
			} else {
				if (settings.Warnings.Count > 0) {
					foreach (CompilerWarning warning in settings.Warnings) {
						errorBuilder.AppendLine(warning.ToString());
					}
				}
				booNode.Accept(new RemoveRedundantTypeReferencesVisitor());
				using (StringWriter w = new StringWriter()) {
					BooPrinterVisitor printer = new BooPrinterVisitor(w);
					int indentCount = 0;
					foreach (char c in indentation) {
						if (c == '\t')
							indentCount += 4;
						else
							indentCount += 1;
					}
					indentCount /= 4;
					while (indentCount-- > 0)
						printer.Indent();
					booNode.Accept(printer);
					output = w.ToString();
				}
			}
			if (errorBuilder.Length > 0) {
				MessageService.ShowMessage(errorBuilder.ToString());
			}
			return output;
		}
Example #5
0
		/// <summary>
		/// Inserts code at the line before target AST node.
		/// </summary>
		public static void InsertCodeBefore(this ITextEditor editor, AbstractNode target, AbstractNode insert)
		{
			InsertCode(editor, target, insert, editor.Document.GetPreviousLineEndOffset(target.StartLocation), false);
		}
Example #6
0
		/// <summary>
		/// Inserts code at the next line after target AST node.
		/// </summary>
		public static void InsertCodeAfter(this ITextEditor editor, AbstractNode target, AbstractNode insert, bool updateCaretPos = false)
		{
			InsertCode(editor, target, insert, editor.Document.GetLineEndOffset(target.EndLocation), updateCaretPos);
		}
Example #7
0
		public static void InsertCode(this ITextEditor editor, AbstractNode target, AbstractNode insert, int insertOffset, bool updateCaretPos)
		{
			if (insertOffset < 0)
				return;
			
			var regionCorrectVisitor = new SetRegionInclusionVisitor();
			insert.AcceptVisitor(regionCorrectVisitor, null);
			
			var doc = editor.Document;
			var codeGen = editor.Language.Properties.CodeGenerator;
			
			string indent = DocumentUtilitites.GetWhitespaceAfter(doc, doc.GetLineStartOffset(target.StartLocation));
			string code = codeGen.GenerateCode(insert, indent);
			
			doc.Insert(insertOffset, code);
			if (updateCaretPos) {
				editor.Caret.Offset = insertOffset + code.Length - 1;
			}
		}
Example #8
0
            protected void UnlockWith(AbstractNode location)
            {
                CodeLocation = new AchievementCodeLocation();

                CodeLocation.From.Line = location.StartLocation.Line;
                CodeLocation.From.Column = location.StartLocation.Column;

                CodeLocation.To.Line = location.EndLocation.Line;
                CodeLocation.To.Column = location.EndLocation.Column;

                IsAchievementUnlocked = true;
            }
 private InvocationExpression FirstInvocationExpression(AbstractNode invocation)
 {
     var v = new FindInvocationExpressionVisitor();
     invocation.AcceptVisitor(v, null);
     return v.Expr;
 }
		public override void InsertCodeAtEnd(DomRegion region, IRefactoringDocument document, params AbstractNode[] nodes)
		{
			RegionPassedToInsertCodeAtEnd = region;
			DocumentPassedToInsertCodeAtEnd = document;
			NodePassedToInsertCodeAtEnd = nodes.FirstOrDefault();
		}
		public override string GenerateCode(AbstractNode node, string indentation)
		{
			throw new NotImplementedException();
		}