private void OnCompilerItemActivated(object sender, EventArgs e) { ListViewItem lvi = m_lvCompilerErrors.SelectedItems[0]; string filename = lvi.Text; int row = 0; int column = 0; int.TryParse(lvi.SubItems[1].Text, out row); int.TryParse(lvi.SubItems[2].Text, out column); ChameleonEditor ed = m_editors.GetEditorByFilename(filename); if (ed != null) { m_editors.CurrentEditor = ed; int pos = ed.NativeInterface.FindColumn(row - 1, column); ed.Selection.Start = pos; ed.Selection.End = pos; ed.Selection.Length = 0; ed.Focus(); } }
private void DoCompile(object sender, EventArgs e) { ChameleonEditor ed = m_editors.CurrentEditor; if (ed.Modified) { if (!m_editors.SaveFile(ed, ed.FileLocation, false, true)) { return; } } m_compiler.CompileFile(ed.FileInfo); }
public virtual bool ExamineSource(ChameleonEditor ed, Range searchRange, bool global) { bool overallResult = true; List <CodeRuleBase> rules = m_localRules; if (global) { rules = m_globalRules; } foreach (CodeRuleBase rule in rules) { bool ruleResult = rule.ExamineSource(ed, searchRange); overallResult &= overallResult; } return(overallResult); }
protected void AddError(ChameleonEditor ed, int lineNum, string errorMessage) { Line l = ed.Lines[lineNum]; int pos = l.StartPosition; Regex reNotWhitespace = new Regex("[^\\s]"); Range startRange = ed.FindReplace.Find(l.Range, reNotWhitespace); int startPos = l.StartPosition; int endPos = l.EndPosition; if (startRange != null) { startPos = startRange.Start; } CodeRuleError error = new CodeRuleError(); error.range = new Range(startPos, endPos, ed); error.text = errorMessage; ed.AddError(error); }
public CppContext(ChameleonEditor editor) { m_editor = editor; m_cmw = Singleton <CtagsManagerWrapper> .Instance; }
public string GetExpression(int pos, bool onlyWord, ChameleonEditor editor, bool forCC) { bool cont = true; int depth = 0; ChameleonEditor ctrl = (editor == null) ? m_editor : editor; int position = pos; int at = position; bool prevGt = false; bool prevColon = false; while (cont && depth >= 0) { char ch = ctrl.PreviousChar(pos, ref at, true); position = at; //Eof? if (ch == 0) { at = 0; break; } //Comment? int style = ctrl.Styles.GetStyleAt(pos); if (IsCommentOrString(pos)) { continue; } switch (ch) { case ';': { // don't include this token at = ctrl.NativeInterface.PositionAfter(at); cont = false; prevColon = false; break; } case '-': { if (prevGt) { prevGt = false; //if previous char was '>', we found an arrow so reduce the depth //which was increased depth--; } else { if (depth <= 0) { //don't include this token at = ctrl.NativeInterface.PositionAfter(at); cont = false; } } prevColon = false; break; } case ' ': case '\n': case '\v': case '\t': case '\r': { prevGt = false; prevColon = false; if (depth <= 0) { cont = false; break; } break; } case '{': case '=': { prevGt = false; prevColon = false; cont = false; break; } case '(': case '[': { depth--; prevGt = false; prevColon = false; if (depth < 0) { //don't include this token at = ctrl.NativeInterface.PositionAfter(at); cont = false; } break; } case ',': case '*': case '&': case '!': case '~': case '+': case '^': case '|': case '%': case '?': { prevGt = false; prevColon = false; if (depth <= 0) { //don't include this token at = ctrl.NativeInterface.PositionAfter(at); cont = false; } break; } case '>': { prevGt = true; prevColon = false; depth++; break; } case '<': { prevGt = false; prevColon = false; depth--; if (depth < 0) { //don't include this token at = ctrl.NativeInterface.PositionAfter(at); cont = false; } break; } case ')': case ']': { prevGt = false; prevColon = false; depth++; break; } default: { prevGt = false; prevColon = false; break; } } } if (at < 0) { at = 0; } string expr = new Range(at, pos, ctrl).Text; if (!forCC) { // If we do not require the expression for CodeCompletion // return the un-touched buffer return(expr); } //remove comments from it CPPScannerWrapper sc = new CPPScannerWrapper(); sc.SetText(expr); string expression = ""; int type = 0; for (type = sc.Lex(); type != 0;) { string token = sc.TokenText(); expression += token + " "; } return(expression); }
private void OnFileSaveAsRemote(object sender, EventArgs e) { ChameleonEditor editor = m_editors.CurrentEditor; m_editors.SaveFile(editor, FileLocation.Remote, true, false); }
private void OnFileSave(object sender, EventArgs e) { ChameleonEditor editor = m_editors.CurrentEditor; m_editors.SaveFile(editor, editor.FileLocation, false, true); }
void OnCompilerEvent(object sender, CompilerEventArgs e) { Action updateCompilerDetails = () => { switch (e.Status) { case CompileStatus.Started: { m_lvCompilerErrors.Items.Clear(); m_lvCompilerErrors.CompileResultMessage = ""; toolStatusCompile.Text = "Compile started"; break; } case CompileStatus.Finished: { int numErrors = e.Messages.Where(m => m.MessageType == CompilerMessageType.Error).Count(); ListViewItem resultLVI = new ListViewItem(); resultLVI.Text = ""; if (numErrors == 0) { //resultLVI.Text = "Compile successful"; m_lvCompilerErrors.CompileResultMessage = "Compile successful"; } else { m_lvCompilerErrors.CompileResultMessage = string.Format("Compile failed: {0} errors", numErrors); } resultLVI.Group = m_lvCompilerErrors.Groups["groupCompileResult"]; m_lvCompilerErrors.Items.Add(resultLVI); var items = new ListView.ListViewItemCollection(m_lvCompilerErrors); foreach (CompilerMessage cm in e.Messages) { ListViewItem lvi = new ListViewItem(); lvi.Text = cm.Filename; lvi.SubItems.Add(cm.Line.ToString()); lvi.SubItems.Add(cm.Column.ToString()); lvi.SubItems.Add(cm.Message); lvi.Group = m_lvCompilerErrors.Groups["groupErrors"]; if (cm.MessageType == CompilerMessageType.Warning) { lvi.ImageIndex = 0; } else if (cm.MessageType == CompilerMessageType.Error) { lvi.ImageIndex = 1; } m_lvCompilerErrors.Items.Add(lvi); } m_lvCompilerErrors.Columns[0].Width = -1; if (numErrors > 0) { tabControl1.SelectedTab = m_tabCompilerErrors; toolStatusCompile.Text = "Compile failed"; } else { toolStatusCompile.Text = "Compile succeeded"; ChameleonEditor editor = m_editors.GetEditorByFilename(e.Filename); if (editor != null) { editor.IsCompiled = true; } } break; } } }; if (this.InvokeRequired) { this.Invoke(updateCompilerDetails); } else { updateCompilerDetails(); } }
public override bool ExamineSource(ChameleonEditor ed, ScintillaNet.Range searchRange) { m_checkSucceeded = false; ANTLRParser parser = Singleton <ANTLRParser> .Instance; if (!parser.ParseCompleted) { return(false); } ASTNode root = parser.GetAST(); List <ASTNode> conditions = (from n in root.Descendants() where n.text == "condition" select n).ToList(); string astText = root.ASTToString(); foreach (ASTNode condition in conditions) { List <ASTNode> assignments = (from n in condition.Descendants() where n.text == "assign" || n.text == "=" select n).ToList(); if (assignments.Count > 0) { foreach (ASTNode assignment in assignments) { int actualLine = searchRange.StartingLine.Number + assignment.lineNumber - 1; string errorText = "Assignment not allowed in boolean conditions"; AddError(ed, actualLine, errorText); } } } List <ASTNode> whiles = (from n in root.Descendants() where n.text == "while" select n).ToList(); foreach (ASTNode wh in whiles) { if (wh.firstChild.text != "condition") { List <ASTNode> pieces = new List <ASTNode>(); Func <ASTNode, bool> getWhilePieces = (node => { bool keepGoing = true; if (node.text == "body") { keepGoing = false; } else { pieces.Add(node); } return(keepGoing); }); wh.TraverseAST(false, getWhilePieces); List <ASTNode> assignmentPieces = pieces.Where(node => node.text == "assign" || node.text == "=").ToList(); if (assignmentPieces.Count > 0) { foreach (ASTNode assignmentPiece in assignmentPieces) { int actualLine = searchRange.StartingLine.Number + assignmentPiece.lineNumber - 1; string errorText = "Assignment not allowed in boolean conditions"; AddError(ed, actualLine, errorText); } } } } m_checkSucceeded = true; return(m_checkSucceeded); }
public override bool ExamineSource(ChameleonEditor ed, ScintillaNet.Range searchRange) { bool m_checkSucceeded = true; CtagsManagerWrapper cmw = Singleton <CtagsManagerWrapper> .Instance; ANTLRParser parser = Singleton <ANTLRParser> .Instance; int lineNum = searchRange.StartingLine.Number; Tag fn = cmw.FunctionFromFileLine(ed.Filename, lineNum + 1, false); List <Tag> locals = ed.Context.GetLocalVariables(searchRange.Start); if (locals == null) { m_checkSucceeded = false; return(false); } List <Tag> singleCharVars = locals.Where(t => t.name.Length == 1).ToList(); if (singleCharVars.Count > 0) { //string functionText = ed.Context.GetFunctionText(lineNum); //parser.SetSource(functionText, ed.Filename); if (!parser.ParseCompleted) { // act like nothing's wrong return(true); } foreach (Tag t in singleCharVars) { ASTNode root = parser.GetAST(); string astText = root.ASTToString(); List <ASTNode> usages = (from n in root.Descendants() where n.text == t.name && n.type == 10 select n).ToList(); if (usages.Count > 0) { ASTNode firstUsage = usages[0]; ASTNode ancestor = firstUsage.GetAncestor(4); if (ancestor != null && ancestor.text == "for") { continue; } } int errorLine = -1; if (t.lineNumber < 0) { //string varDeclaration = t.scope + " " + t.name; //int declarationPos = searchRange.Text.IndexOf(varDeclaration); errorLine = searchRange.StartingLine.Number; /* * if(declarationPos != -1) * { * int actualPos = searchRange.Start + declarationPos; * errorLine = ed.Lines.FromPosition(actualPos).Number; * } */ } else { errorLine = searchRange.StartingLine.Number + t.lineNumber; } if (errorLine < 0) { continue; } string errorText = "Single-character variable names only allowed as loop indices"; AddError(ed, errorLine, errorText); } } return(m_checkSucceeded); }
public virtual bool ExamineSource(ChameleonEditor ed, Range searchRange) { return(true); }