private CodeRange GetSelectedRange() { int start, end; azuki.GetSelection(out start, out end); return(CodeRange.ConvertFromIndiciesSkippingWhitespaces(Code, ref start, ref end)); }
public ElementListViewItem(CodeRange range, CstNode element) : base(new[] { element.Name.LocalName, element.Value }) { Range = range; Element = element; ToolTipText = element.ToString(); }
/// <summary> /// Instruments production code for measuring code coverage and returns the modifieid code. /// </summary> /// <param name="support">A support to measure coverage.</param> /// <param name="fileInfo">A <c>FileInfo</c> instance to be instrumented.</param> /// <returns>The modified production code.</returns> public string InstrumentStatementAndPredicate( LanguageSupport support, FileInfo fileInfo) { var root = support.CodeToXml.GenerateFromFile(fileInfo.FullName); var inserter = support.AstTransformer; var fileId = RegisterFile(fileInfo); // ステートメントを挿入できるようにブロックを補う inserter.SupplementBlock(root); // switch文を正しく測定できるようにdefault節を追加する inserter.SupplementDefaultCase(root); var analyzer = support.AstAnalyzer; var funcs = analyzer.FindFunctions(root); foreach (var func in funcs) { var funcName = analyzer.GetFunctionName(func); var funcId = RegisterFunction(fileId, funcName, CodeRange.Locate(func)); InstrumentStatement(support, fileId, funcId, inserter, func); InstrumentBranch(support, fileId, funcId, inserter, func); } // Add import for logging executed items inserter.InsertImport(root); return(support.XmlToCode.Generate(root)); }
System.Drawing.Point GetExecutionCursor(bool start) { System.Drawing.Point cursor = new System.Drawing.Point(); IExecutionSession session = Solution.Current.ExecutionSession; if (null != session) { CodeRange codeRange = new CodeRange(); if (session.GetExecutionCursor(ref codeRange)) { if (false != start) { cursor.X = codeRange.StartInclusive.CharNo - 1; cursor.Y = codeRange.StartInclusive.LineNo - 1; } else { cursor.X = codeRange.EndExclusive.CharNo - 1; cursor.Y = codeRange.EndExclusive.LineNo - 1; } } } return(cursor); }
public static Literal Calculate(BinaryOp op, Literal left, Literal right) { var range = new CodeRange(left, right); object val = CalculateValue(op, left, right); var type = TypeEvaluator.GetType(left.ValueType, op, right.ValueType); return new Literal(range, type, val); }
private static void ConvertIndiciesToRange( CstNode node, string code, int inclusiveStart, int exclusiveEnd, CodeRange range) { var newRange = CodeRange.ConvertFromIndicies(code, inclusiveStart, exclusiveEnd); var newInclusiveStart = char.IsWhiteSpace(code[inclusiveStart - 1]) ? inclusiveStart - 1 : inclusiveStart; var newExclusiveEnd = char.IsWhiteSpace(code[exclusiveEnd]) ? exclusiveEnd + 1 : exclusiveEnd; var elem = CodeRange.ConvertFromIndiciesSkippingWhitespaces( code, ref newInclusiveStart, ref newExclusiveEnd) .FindInnermostNode(node); Assert.That(CodeRange.Locate(elem), Is.EqualTo(newRange)); newRange.ConvertToIndicies(code, out newInclusiveStart, out newExclusiveEnd); Assert.That(newRange, Is.EqualTo(range)); Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart)); Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd)); var scode = new StructuredCode(code); Assert.That( CodeRange.ConvertFromIndicies(scode, inclusiveStart, exclusiveEnd), Is.EqualTo(range)); newRange.ConvertToIndicies(scode, out newInclusiveStart, out newExclusiveEnd); Assert.That(newInclusiveStart, Is.EqualTo(inclusiveStart)); Assert.That(newExclusiveEnd, Is.EqualTo(exclusiveEnd)); }
public ConstDefinition(CodeRange start, Identifier id, LaxExpression value) : base(start, id) { if (value == null) throw new ArgumentNullException("value"); this.Value = value; }
public void ParseCodeRange() { var e = Generator.GenerateTreeFromCodePath( @"C:\Users\exKAZUu\Desktop\CodeGenerator.java"); var range = new CodeRange(new CodeLocation(302, 0), new CodeLocation(306, 0)); Console.WriteLine(range.FindOutermostNode(e)); }
public AstToken(string name, string text, CodeRange range) { Contract.Requires(name != null); Contract.Requires(text != null); Name = name; Text = text; Range = range; }
public Token(string name, string text, CodeRange range, string ruleId) { Contract.Requires(name != null); Contract.Requires(text != null); Contract.Requires(ruleId != null); Name = name; Text = text; Range = range; RuleId = ruleId; }
public static AstToken FromXml(XElement element) { CodeRange range; if (CodeRange.TryParse(element, element, out range)) { return(new AstToken(element.Name.LocalName, element.Value, range)); } return(new AstToken(element.Name.LocalName, element.Value)); }
protected Definition(CodeRange pos, Identifier name) { if (pos == null) throw new ArgumentNullException("pos"); if (name == null) throw new ArgumentNullException("name"); CodeRange = pos.Expand2(name); Name = name; }
private void InstrumentStatement( LanguageSupport support, long fileId, long funcId, AstTransformer inserter, XElement func) { var stmts = support.AstAnalyzer.FindStatements(func); foreach (var stmt in stmts) { var position = CodeRange.Locate(stmt); var stmtId = RegisterStatement(fileId, funcId, position); inserter.InsertStatementBefore(stmt, stmtId, CodeTransformer.Done, ElementType.Statement); } }
protected virtual CstToken DeserializeToken() { var name = Deserializer.DeserializeString(); var ruleId = Deserializer.DeserializeString(); var text = Deserializer.DeserializeString(); var beforeInsertedText = Deserializer.DeserializeString(); var afterInsertedText = Deserializer.DeserializeString(); var range = CodeRange.Desrialize(Deserializer); return(new CstToken( name, text, beforeInsertedText, afterInsertedText, ruleId, range)); }
private void InstrumentBranch( LanguageSupport support, long fileId, long funcId, AstTransformer inserter, XElement func) { var branches = support.AstAnalyzer.FindBranches(func); foreach (var branch in branches) { var position = CodeRange.Locate(branch); var branchId = RegisterBranch(fileId, funcId, position); inserter.InsertPredicate(branch, branchId, ElementType.Decision); } }
public static IEnumerable <Tuple <int, LocationInfo> > GetSimilarElements( CstGenerator cstGenerator, IEnumerable <LocationInfo> locations, IEnumerable <FileInfo> targets, int range = 5, bool inner = true, bool outer = true) { var path2Ast = new Dictionary <string, CstNode>(); var paths = locations.Select(l => l.FileInfo).Concat(targets) .Select(f => f.FullName) .ToHashSet(); foreach (var path in paths) { path2Ast.Add(path, cstGenerator.GenerateTreeFromCodePath(path)); } var elements = new List <CstNode>(); foreach (var location in locations) { var root = path2Ast[location.FileInfo.FullName]; elements.Add(location.CodeRange.FindOutermostNode(root)); } var names = AdoptNodeNames(elements); var candidates = new Dictionary <string, IEnumerable <CstNode> >(); foreach (var keyAndValue in path2Ast) { candidates.Add( keyAndValue.Key, keyAndValue.Value.Descendants() .Where(e => names.Contains(e.Name))); } var commonKeys = elements.GetCommonKeys(range, true, true); return(candidates.SelectMany( kv => { var fileInfo = new FileInfo(kv.Key); return kv.Value.Select( e => Tuple.Create( e.GetSurroundingKeys(range, inner, outer) .Count(commonKeys.Contains), e)) .Select( t => Tuple.Create( t.Item1, new LocationInfo { FileInfo = fileInfo, CodeRange = CodeRange.Locate(t.Item2), })); }) .OrderByDescending(t => t.Item1)); }
public Dictionary <CodeRange, CstNode> ExtractRange2Elements(CstNode ast) { var elements = ExtractElements(ast); // Elements having the same range can appear so can't use ToDictiornary var ret = new Dictionary <CodeRange, CstNode>(); foreach (var element in elements) { var range = CodeRange.Locate(element); ret[range] = element; } return(ret); }
protected override void VerifyLocation(string code, CstNode root) { foreach (var node in root.AllTokens()) { Assert.That(node.Range.GetCodeFragment(code), Is.EqualTo(node.Text)); } foreach (var node in root.DescendantsAndSelf()) { Assert.That( CodeRange.LocateWithHiddens(node).GetCodeFragment(code), Is.EqualTo(node.Code)); } }
public void FindElement() { var cst = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(@" public class Hello { public static void main(String[] args) { System.out.println(1); } }"); var stmt = cst.Descendants("statement").First(); var pos = CodeRange.Locate(stmt); Assert.That(pos.FindInnermostNode(cst), Is.EqualTo(stmt)); Assert.That(pos.FindOutermostNode(cst), Is.EqualTo(stmt.Parent)); }
internal void HandleScriptActivation() { //Check if its in playback mode, as it should be treated differently due to blocking if (player == null) { if (textCore.ChangeScript(ScriptTabControl.CurrentTab)) { CheckTabControlVisibility(false); } else { return; } } else { CheckTabControlVisibility(false); TextEditorCommand command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript); command.AppendArgument(ScriptTabControl.CurrentTab); textCore.PlaybackCommand(command); } // Resize canvas to fit the next script. //if (numSlider != null) // numSlider.Visibility = Visibility.Collapsed; UpdateCanvasDimension(); IExecutionSession session = Solution.Current.ExecutionSession; UpdateScriptDisplay(Solution.Current.ActiveScript); UpdateCaretPosition(false); textCanvas.BreakpointsUpdated(); if (null != session) { CodeRange executionCursor = new CodeRange(); if (session.GetExecutionCursor(ref executionCursor)) { textCanvas.SetExecutionCursor(executionCursor); } } if (null != textEditorControl.textCore.CurrentTextBuffer) { textCanvas.ScrollOwner.ScrollToVerticalOffset( textEditorControl.textCore.VerticalScrollPosition); } }
private static CodeRange ConvertRangeToIndicies( string code, CstNode node, out int inclusiveStart, out int exclusiveEnd) { var range = CodeRange.Locate(node); range.ConvertToIndicies(code, out inclusiveStart, out exclusiveEnd); Assert.That( code.Substring(inclusiveStart, exclusiveEnd - inclusiveStart), Is.EqualTo(node.Code.Trim())); range.ConvertToIndicies(new StructuredCode(code), out inclusiveStart, out exclusiveEnd); Assert.That( code.Substring(inclusiveStart, exclusiveEnd - inclusiveStart), Is.EqualTo(node.Code.Trim())); return(range); }
public void Locate() { var code = @" public class Hello { public static void main(String[] args) { } }"; var xml = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(code); var id = xml.Descendants("IDENTIFIER").First(); var range = CodeRange.Locate(id); Assert.That(range.GetCodeFragment(code), Is.EqualTo(id.TokenText)); Assert.That( range.GetCodeFragment(new StructuredCode(code)), Is.EqualTo(id.TokenText)); }
public CstToken( string name, string text, string beforeInsertedText, string afterInsertedText, string ruleId, CodeRange range) { Contract.Requires(name != null); Contract.Requires(text != null); Contract.Requires(beforeInsertedText != null); Contract.Requires(afterInsertedText != null); Contract.Requires(ruleId != null); Name = name; Text = text; BeforeInsertedText = beforeInsertedText; AfterInsertedText = afterInsertedText; Range = range; RuleId = ruleId; }
private void markToolStripMenuItem_Click(object sender, EventArgs e) { // Calculate the selected range var selectedRange = GetSelectedRange(); // Get the selected element // TODO: Should be use FindInnerElement or FindOuterElement ? var element = selectedRange.FindOuterElement(_activeFile.Ast); var range = CodeRange.Locate(element); if (!_activeFile.Range2Elements.ContainsKey(range)) { _activeFile.Range2Elements.Add(range, element); NormalizeAllRange2Element(); // To show good element lists DrawMarkers(_activeFile.Range2Elements, 0, 1); ListElements(_activeFile.Range2Elements, lvMarkedElements); } }
public CstToken(string name, string text, string ruleId, CodeRange range) : this(name, text, "", "", ruleId, range) { }
public SyntaxError(CodeRange pos, string message) : base(pos, message) { }
private SeedNode(CstNode node, CodeRange targetRange, CodeRange surroundingRange) { Node = node; TargetRange = targetRange; SurroundingRange = surroundingRange; }
public void SetExecutionCursor(ProtoCore.CodeModel.CodeRange executionCursor) { this.executionCursor = executionCursor; }
protected override long RegisterStatement( long fileId, long funcId, CodeRange position) { Console.WriteLine("Statement position: " + position); return Id++; }
public FuncDefinition(CodeRange pos, Identifier name) : base(pos, name) { }
public TestCase(string relativePath, string name, CodeRange pos) { RelativePath = relativePath; Name = name; Position = pos; }
public TestCase(string relativePath, string name, XElement node) : this(relativePath, name, CodeRange.Locate(node)) { }
public Literal GetLiteral(CodeRange pos) { var type = new LaxType(DataType.Unit, new Unit(Name)); return new Literal(pos, type, null); }
public UnitDefinition(CodeRange start, Identifier name) : base(start, name) { }
/// <summary> /// Generate a BinaryOp that strongly connects a value with the unit following directly afterwards. /// </summary> public static BinaryOp UnitOp(CodeRange pos) { var bop = new BinaryOp("*", 18, Associate.LeftToRight); bop.CodeRange = pos; return bop; }
protected override long RegisterStatement( long fileId, long funcId, CodeRange position) { Console.WriteLine("Statement position: " + position); return(Id++); }
public Identifier(CodeRange pos, string name) : base(ExprType.Identifier) { this.CodeRange = pos; this.Name = name; }
/// <summary> /// Registers a statement with the specified file and function id which contains the statement and returns the branch id. /// </summary> /// <param name="fileId"> A file id which contains the function. </param> /// <param name="funcId"> A function id which contains the branch. </param> /// <param name="position"> The position of the statement. </param> /// <returns> The statement id. </returns> protected abstract long RegisterStatement( long fileId, long funcId, CodeRange position);
/// <summary> /// Registers a branch such as if, while, do-while, for and ? (ternary expression) with the specified file and function id which contains the branch and returns the branch id. /// </summary> /// <param name="fileId"> A file id which contains the function. </param> /// <param name="funcId"> A function id which contains the branch. </param> /// <param name="position"> The position of the branch. </param> /// <returns> The branch id. </returns> protected abstract long RegisterBranch( long fileId, long funcId, CodeRange position);
public FunctionCall(CodeRange pos, Identifier functionName) : base(ExprType.FunctionCall) { CodeRange = pos; Name = functionName; }
protected override long RegisterBranch( long fileId, long funcId, CodeRange position) { Console.WriteLine("Branch position: " + position.SmartPositionString); return Id++; }
public Token(string token, CodeRange codeRange) { TokenText = token ?? ""; CodeRange = codeRange; }
public void ResetExecutionCursor() { executionCursor = new CodeRange(); }
public Literal(CodeRange pos, LaxType type, object val) : base(ExprType.Literal) { this.CodeRange = pos; this.ValueType = type; this.Value = val; }
protected override long RegisterFunction( long fileId, string functionName, CodeRange position) { Console.WriteLine("Function name: " + functionName + ", pos: " + position); return Id++; }
public Token(string name, string text, CodeRange range) : this(name, text, range, STNode.DefaultRuleId) {}
public string GetFragment(CodeRange range) { var startIndex = GetIndex(range.StartLocation); var exclusiveEndIndex = GetIndex(range.EndLocation); return Code.Substring(startIndex, exclusiveEndIndex - startIndex); }
protected override long RegisterFunction( long fileId, string functionName, CodeRange position) { Console.WriteLine("Function name: " + functionName + ", pos: " + position); return(Id++); }
/// <summary> /// Used to report on unexpected errors /// </summary> /// <param name="pos"></param> /// <param name="ex"></param> public SyntaxError(CodeRange pos, Exception ex) : base(pos, "Compiler crashed: " + ex.Message, ex) { }
public VarDefinition(CodeRange start, Identifier id) : base(start, id) { }
public ElementListViewItem(CodeRange range, XElement element) : base(new[] { element.Name.LocalName, element.Value }) { Range = range; Element = element; ToolTipText = element.ToString(); }
/// <summary> /// Registers a function with the specified name and returns the function id. /// </summary> /// <param name="fileId"> A file id which contains the function. </param> /// <param name="functionName"> A function name to be registered. </param> /// <param name="position"> The position of the function. </param> /// <returns> The function id. </returns> protected abstract long RegisterFunction( long fileId, string functionName, CodeRange position);
public CoverageElement(string relativePath, XElement node, Tagger tagger) { RelativePath = relativePath; Position = CodeRange.Locate(node); Qualifiers = tagger.Tag(node); }
public BinaryOp(CodeRange pos, string token) : base(ExprType.BinaryOp, PrecedenceFromToken(token), AssociateFrom(token)) { this.CodeRange = pos; this.Operator = token; }