diff --git a/SourcepawnCondenser/SourcepawnCondenser/Condenser.cs b/SourcepawnCondenser/SourcepawnCondenser/Condenser.cs index bf44967b..4f3899bc 100644 --- a/SourcepawnCondenser/SourcepawnCondenser/Condenser.cs +++ b/SourcepawnCondenser/SourcepawnCondenser/Condenser.cs @@ -38,122 +38,122 @@ public SMDefinition Condense() switch (ct.Kind) { case TokenKind.FunctionIndicator: + { + var newIndex = ConsumeSMFunction(); + if (newIndex != -1) { - var newIndex = ConsumeSMFunction(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.EnumStruct: + { + var newIndex = ConsumeSMEnumStruct(); + if (newIndex != -1) { - var newIndex = ConsumeSMEnumStruct(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.Enum: + { + var newIndex = ConsumeSMEnum(); + if (newIndex != -1) { - var newIndex = ConsumeSMEnum(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.Struct: + { + var newIndex = ConsumeSMStruct(); + if (newIndex != -1) { - var newIndex = ConsumeSMStruct(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.PreprocessorDirective: + { + var newIndex = ConsumeSMPPDirective(); + if (newIndex != -1) { - var newIndex = ConsumeSMPPDirective(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.Constant: + { + var newIndex = ConsumeSMConstant(); + if (newIndex != -1) { - var newIndex = ConsumeSMConstant(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.MethodMap: + { + var newIndex = ConsumeSMMethodmap(); + if (newIndex != -1) { - var newIndex = ConsumeSMMethodmap(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.TypeSet: + { + var newIndex = ConsumeSMTypeset(); + if (newIndex != -1) { - var newIndex = ConsumeSMTypeset(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.TypeDef: + { + var newIndex = ConsumeSMTypedef(); + if (newIndex != -1) { - var newIndex = ConsumeSMTypedef(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - break; + position = newIndex + 1; + continue; } + + break; + } case TokenKind.Identifier: + { + var newIndex = ConsumeSMVariable(); + if (newIndex != -1) { - var newIndex = ConsumeSMVariable(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } - - // If Variable is not found try function - newIndex = ConsumeSMFunction(); - if (newIndex != -1) - { - position = newIndex + 1; - continue; - } + position = newIndex + 1; + continue; } - break; + + // If Variable is not found try function + newIndex = ConsumeSMFunction(); + if (newIndex != -1) + { + position = newIndex + 1; + continue; + } + } + break; } ++position; diff --git a/SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMFunctionConsumer.cs b/SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMFunctionConsumer.cs index c94531a0..7b4be075 100644 --- a/SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMFunctionConsumer.cs +++ b/SourcepawnCondenser/SourcepawnCondenser/CondenserFunctions/SMFunctionConsumer.cs @@ -20,66 +20,66 @@ private int ConsumeSMFunction() switch (t[startPosition].Value) { case "stock": + { + if (startPosition + 1 < length) { - if (startPosition + 1 < length) + if (t[startPosition + 1].Kind == TokenKind.FunctionIndicator) { - if (t[startPosition + 1].Kind == TokenKind.FunctionIndicator) + if (t[startPosition + 1].Value == "static") { - if (t[startPosition + 1].Value == "static") - { - kind = SMFunctionKind.StockStatic; - ++iteratePosition; - break; - } + kind = SMFunctionKind.StockStatic; + ++iteratePosition; + break; } } - - kind = SMFunctionKind.Stock; - break; } + + kind = SMFunctionKind.Stock; + break; + } case "native": - { - kind = SMFunctionKind.Native; - break; - } + { + kind = SMFunctionKind.Native; + break; + } case "forward": - { - kind = SMFunctionKind.Forward; - break; - } + { + kind = SMFunctionKind.Forward; + break; + } case "public": + { + if (startPosition + 1 < length) { - if (startPosition + 1 < length) + if (t[startPosition + 1].Kind == TokenKind.FunctionIndicator) { - if (t[startPosition + 1].Kind == TokenKind.FunctionIndicator) + if (t[startPosition + 1].Value == "native") { - if (t[startPosition + 1].Value == "native") - { - kind = SMFunctionKind.PublicNative; - ++iteratePosition; - break; - } + kind = SMFunctionKind.PublicNative; + ++iteratePosition; + break; } } - - kind = SMFunctionKind.Public; - break; } + + kind = SMFunctionKind.Public; + break; + } case "static": - { - kind = SMFunctionKind.Static; - break; - } + { + kind = SMFunctionKind.Static; + break; + } case "normal": - { - kind = SMFunctionKind.Normal; - break; - } + { + kind = SMFunctionKind.Normal; + break; + } default: - { - functionReturnType = t[startPosition].Value; - break; - } + { + functionReturnType = t[startPosition].Value; + break; + } } var functionCommentString = string.Empty; diff --git a/SourcepawnCondenser/SourcepawnCondenser/Tokenizer/Tokenizer.cs b/SourcepawnCondenser/SourcepawnCondenser/Tokenizer/Tokenizer.cs index 7d25eff2..08478a06 100644 --- a/SourcepawnCondenser/SourcepawnCondenser/Tokenizer/Tokenizer.cs +++ b/SourcepawnCondenser/SourcepawnCondenser/Tokenizer/Tokenizer.cs @@ -272,72 +272,72 @@ public static List TokenizeString(string Source, bool IgnoreMultipleEOL) case "public": case "normal": case "static": - { - token.Add(new Token(identString, TokenKind.FunctionIndicator, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.FunctionIndicator, startIndex)); + break; + } case "enum": - { - var fullString = Source.Substring(startIndex, endIndex - startIndex + 7); - token.Add(fullString == "enum struct" - ? new Token(fullString, TokenKind.EnumStruct, startIndex) - : new Token(identString, TokenKind.Enum, startIndex)); + { + var fullString = Source.Substring(startIndex, endIndex - startIndex + 7); + token.Add(fullString == "enum struct" + ? new Token(fullString, TokenKind.EnumStruct, startIndex) + : new Token(identString, TokenKind.Enum, startIndex)); - break; - } + break; + } case "struct": + { + var enumStructStart = startIndex - 5; + if (enumStructStart >= 0) { - var enumStructStart = startIndex - 5; - if (enumStructStart >= 0) + // Avoid double matches + var fullString = Source.Substring(enumStructStart, endIndex - enumStructStart); + if (fullString == "enum struct") { - // Avoid double matches - var fullString = Source.Substring(enumStructStart, endIndex - enumStructStart); - if (fullString == "enum struct") - { - break; - } + break; } - - token.Add(new Token(identString, TokenKind.Struct, startIndex)); - break; } + + token.Add(new Token(identString, TokenKind.Struct, startIndex)); + break; + } case "const": - { - token.Add(new Token(identString, TokenKind.Constant, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.Constant, startIndex)); + break; + } case "methodmap": - { - token.Add(new Token(identString, TokenKind.MethodMap, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.MethodMap, startIndex)); + break; + } case "property": - { - token.Add(new Token(identString, TokenKind.Property, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.Property, startIndex)); + break; + } case "typeset": case "funcenum": - { - token.Add(new Token(identString, TokenKind.TypeSet, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.TypeSet, startIndex)); + break; + } case "typedef": case "functag": - { - token.Add(new Token(identString, TokenKind.TypeDef, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.TypeDef, startIndex)); + break; + } case "new": - { - token.Add(new Token(identString, TokenKind.New, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.New, startIndex)); + break; + } default: - { - token.Add(new Token(identString, TokenKind.Identifier, startIndex)); - break; - } + { + token.Add(new Token(identString, TokenKind.Identifier, startIndex)); + break; + } } i = endIndex - 1; diff --git a/UI/Components/DASMElement/DASMElement.xaml.cs b/UI/Components/DASMElement/DASMElement.xaml.cs index d3a10ce7..343b4bb8 100644 --- a/UI/Components/DASMElement/DASMElement.xaml.cs +++ b/UI/Components/DASMElement/DASMElement.xaml.cs @@ -378,45 +378,45 @@ private void RenderCodeView(SmxCodeV1Section code, string name, int address) break; case V1Param.Address: + { + DebugSymbolEntry sym = null; + if (file_.DebugSymbols != null) { - DebugSymbolEntry sym = null; - if (file_.DebugSymbols != null) - { - sym = file_.DebugSymbols.FindDataRef(value); - } - - buffer.Append(string.Format(" 0x{0:x}", value)); - if (sym != null) - { - comment.Append(string.Format(" {0}", sym.Name)); - } - else - { - comment.Append(string.Format(" {0}", value)); - } - - break; + sym = file_.DebugSymbols.FindDataRef(value); } + + buffer.Append(string.Format(" 0x{0:x}", value)); + if (sym != null) + { + comment.Append(string.Format(" {0}", sym.Name)); + } + else + { + comment.Append(string.Format(" {0}", value)); + } + + break; + } case V1Param.Stack: + { + DebugSymbolEntry sym = null; + if (file_.DebugSymbols != null) { - DebugSymbolEntry sym = null; - if (file_.DebugSymbols != null) - { - sym = file_.DebugSymbols.FindStackRef(insn.Address, value); - } - - buffer.Append(string.Format(" 0x{0:x}", value)); - if (sym != null) - { - comment.Append(string.Format(" {0}", sym.Name)); - } - else - { - comment.Append(string.Format(" {0}", value)); - } - - break; + sym = file_.DebugSymbols.FindStackRef(insn.Address, value); } + + buffer.Append(string.Format(" 0x{0:x}", value)); + if (sym != null) + { + comment.Append(string.Format(" {0}", sym.Name)); + } + else + { + comment.Append(string.Format(" {0}", value)); + } + + break; + } case V1Param.Function: var fun = file_.FindFunctionName(value); buffer.Append(string.Format(" 0x{0:x}", value)); diff --git a/UI/Components/EditorElement/EditorElement.xaml.cs b/UI/Components/EditorElement/EditorElement.xaml.cs index c6f48437..578d3468 100644 --- a/UI/Components/EditorElement/EditorElement.xaml.cs +++ b/UI/Components/EditorElement/EditorElement.xaml.cs @@ -606,35 +606,35 @@ private void HandleContextMenuCommand(object sender, RoutedEventArgs e) switch ((string)((MenuItem)sender).Tag) { case "0": - { - editor.Undo(); - break; - } + { + editor.Undo(); + break; + } case "1": - { - editor.Redo(); - break; - } + { + editor.Redo(); + break; + } case "2": - { - editor.Cut(); - break; - } + { + editor.Cut(); + break; + } case "3": - { - editor.Copy(); - break; - } + { + editor.Copy(); + break; + } case "4": - { - editor.Paste(); - break; - } + { + editor.Paste(); + break; + } case "5": - { - editor.SelectAll(); - break; - } + { + editor.SelectAll(); + break; + } } } diff --git a/UI/Components/EditorElement/EditorElementIntellisenseController.cs b/UI/Components/EditorElement/EditorElementIntellisenseController.cs index fa5f0e2a..a5878b3f 100644 --- a/UI/Components/EditorElement/EditorElementIntellisenseController.cs +++ b/UI/Components/EditorElement/EditorElementIntellisenseController.cs @@ -428,92 +428,92 @@ private bool ISAC_EvaluateKeyDownEvent(Key k) { case Key.Enter: case Key.Tab: + { + var tabToAutoc = Program.OptionsObject.Editor_TabToAutocomplete; + if ((k == Key.Tab && !tabToAutoc) || (k == Key.Enter && tabToAutoc)) { - var tabToAutoc = Program.OptionsObject.Editor_TabToAutocomplete; - if ((k == Key.Tab && !tabToAutoc) || (k == Key.Enter && tabToAutoc)) - { - return false; - } + return false; + } - var startOffset = editor.CaretOffset - 1; - var endOffset = startOffset; - for (var i = startOffset; i >= 0; --i) + var startOffset = editor.CaretOffset - 1; + var endOffset = startOffset; + for (var i = startOffset; i >= 0; --i) + { + if (!IsValidFunctionChar(editor.Document.GetCharAt(i))) { - if (!IsValidFunctionChar(editor.Document.GetCharAt(i))) - { - break; - } - - endOffset = i; + break; } - var length = startOffset - endOffset; - string replaceString; - var setCaret = false; - if (AC_IsFuncC) - { - replaceString = ((ACNode)AutoCompleteBox.SelectedItem).EntryName; - if (acEntrys[AutoCompleteBox.SelectedIndex].IsExecuteable) - { - replaceString += "(" + (Program.OptionsObject.Editor_AutoCloseBrackets ? ")" : ""); - setCaret = true; - } - } - else - { - replaceString = ((ISNode)MethodAutoCompleteBox.SelectedItem).EntryName; - if (isEntrys[MethodAutoCompleteBox.SelectedIndex].IsExecuteable) - { - replaceString += "(" + (Program.OptionsObject.Editor_AutoCloseBrackets ? ")" : ""); - setCaret = true; - } - } + endOffset = i; + } - editor.Document.Replace(endOffset, length + 1, replaceString); - if (setCaret) + var length = startOffset - endOffset; + string replaceString; + var setCaret = false; + if (AC_IsFuncC) + { + replaceString = ((ACNode)AutoCompleteBox.SelectedItem).EntryName; + if (acEntrys[AutoCompleteBox.SelectedIndex].IsExecuteable) { - editor.CaretOffset--; + replaceString += "(" + (Program.OptionsObject.Editor_AutoCloseBrackets ? ")" : ""); + setCaret = true; } - - return true; } - case Key.Up: + else { - if (AC_IsFuncC) + replaceString = ((ISNode)MethodAutoCompleteBox.SelectedItem).EntryName; + if (isEntrys[MethodAutoCompleteBox.SelectedIndex].IsExecuteable) { - AutoCompleteBox.SelectedIndex = Math.Max(0, AutoCompleteBox.SelectedIndex - 1); - AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem); - } - else - { - MethodAutoCompleteBox.SelectedIndex = Math.Max(0, MethodAutoCompleteBox.SelectedIndex - 1); - MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem); + replaceString += "(" + (Program.OptionsObject.Editor_AutoCloseBrackets ? ")" : ""); + setCaret = true; } + } - return true; + editor.Document.Replace(endOffset, length + 1, replaceString); + if (setCaret) + { + editor.CaretOffset--; } - case Key.Down: + + return true; + } + case Key.Up: + { + if (AC_IsFuncC) { - if (AC_IsFuncC) - { - AutoCompleteBox.SelectedIndex = Math.Min(AutoCompleteBox.Items.Count - 1, - AutoCompleteBox.SelectedIndex + 1); - AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem); - } - else - { - MethodAutoCompleteBox.SelectedIndex = Math.Min(MethodAutoCompleteBox.Items.Count - 1, - MethodAutoCompleteBox.SelectedIndex + 1); - MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem); - } + AutoCompleteBox.SelectedIndex = Math.Max(0, AutoCompleteBox.SelectedIndex - 1); + AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem); + } + else + { + MethodAutoCompleteBox.SelectedIndex = Math.Max(0, MethodAutoCompleteBox.SelectedIndex - 1); + MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem); + } - return true; + return true; + } + case Key.Down: + { + if (AC_IsFuncC) + { + AutoCompleteBox.SelectedIndex = Math.Min(AutoCompleteBox.Items.Count - 1, + AutoCompleteBox.SelectedIndex + 1); + AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem); } - case Key.Escape: + else { - HideISAC(); - return true; + MethodAutoCompleteBox.SelectedIndex = Math.Min(MethodAutoCompleteBox.Items.Count - 1, + MethodAutoCompleteBox.SelectedIndex + 1); + MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem); } + + return true; + } + case Key.Escape: + { + HideISAC(); + return true; + } } } diff --git a/UI/Components/EditorElement/Foldings/EditorFoldingStrategy.cs b/UI/Components/EditorElement/Foldings/EditorFoldingStrategy.cs index 1ad65ad5..d5225349 100644 --- a/UI/Components/EditorElement/Foldings/EditorFoldingStrategy.cs +++ b/UI/Components/EditorElement/Foldings/EditorFoldingStrategy.cs @@ -46,127 +46,127 @@ public IEnumerable CreateNewFoldings(ITextSource document) switch (CommentMode) { case 0: + { + switch (c) { - switch (c) + case '/': { - case '/': - { - if ((i + 1) < document.TextLength) - { - var oneCharAfter = document.GetCharAt(i + 1); - if (oneCharAfter == '*') - { - CommentMode = 2; - startOffsets.Push(i); - } - else if (oneCharAfter == '/') - { - CommentMode = 1; - } - } - break; - } - case '{': + if ((i + 1) < document.TextLength) + { + var oneCharAfter = document.GetCharAt(i + 1); + if (oneCharAfter == '*') { + CommentMode = 2; startOffsets.Push(i); - break; - } - case '}': - { - if (startOffsets.Count > 0) - { - var startOffset = startOffsets.Pop(); - if (startOffset < lastNewLineOffset) - { - newFoldings.Add(new NewFolding(startOffset, i + 1)); - } - } - break; } - case '"': + else if (oneCharAfter == '/') { - CommentMode = 3; - break; + CommentMode = 1; } - case '\'': + } + break; + } + case '{': + { + startOffsets.Push(i); + break; + } + case '}': + { + if (startOffsets.Count > 0) + { + var startOffset = startOffsets.Pop(); + if (startOffset < lastNewLineOffset) { - CommentMode = 4; - break; + newFoldings.Add(new NewFolding(startOffset, i + 1)); } + } + break; + } + case '"': + { + CommentMode = 3; + break; + } + case '\'': + { + CommentMode = 4; + break; } - break; } + break; + } case 2: + { + if (c == '/') { - if (c == '/') + if (i > 0) { - if (i > 0) + if (document.GetCharAt(i - 1) == '*') { - if (document.GetCharAt(i - 1) == '*') + var startOffset = startOffsets.Pop(); + CommentMode = 0; + if (startOffset < lastNewLineOffset) { - var startOffset = startOffsets.Pop(); - CommentMode = 0; - if (startOffset < lastNewLineOffset) - { - newFoldings.Add(new NewFolding(startOffset, i + 1)); - } + newFoldings.Add(new NewFolding(startOffset, i + 1)); } } } - break; } + break; + } case 3: + { + // if quote found, search backwards for backslashes + if (c == '"') { - // if quote found, search backwards for backslashes - if (c == '"') + var slashes = 0; + for (var j = i - 1; j >= 0; j--) { - var slashes = 0; - for (int j = i - 1; j >= 0; j--) + if (document.GetCharAt(j) == '\\') { - if (document.GetCharAt(j) == '\\') - { - slashes++; - } - else - { - break; - } + slashes++; } - // if the total amount of subsequent backslashes found is even - // it means the quote is not escaped - if (slashes % 2 == 0) + else { - CommentMode = 0; + break; } } - break; + // if the total amount of subsequent backslashes found is even + // it means the quote is not escaped + if (slashes % 2 == 0) + { + CommentMode = 0; + } } + break; + } case 4: + { + // if apostrophe found, search backwards for backslashes + if (c == '\'') { - // if apostrophe found, search backwards for backslashes - if (c == '\'') + var slashes = 0; + for (var j = i - 1; j >= 0; j--) { - var slashes = 0; - for (int j = i - 1; j >= 0; j--) + if (document.GetCharAt(j) == '\\') { - if (document.GetCharAt(j) == '\\') - { - slashes++; - } - else - { - break; - } + slashes++; } - // if the total amount of subsequent backslashes found is even - // it means the apostrophe is not escaped - if (slashes % 2 == 0) + else { - CommentMode = 0; + break; } } - break; + // if the total amount of subsequent backslashes found is even + // it means the apostrophe is not escaped + if (slashes % 2 == 0) + { + CommentMode = 0; + } } + break; + } } } } diff --git a/Utils/SPSyntaxTidy/SPTokenizer.cs b/Utils/SPSyntaxTidy/SPTokenizer.cs index 4bd98da0..9a7f5375 100644 --- a/Utils/SPSyntaxTidy/SPTokenizer.cs +++ b/Utils/SPSyntaxTidy/SPTokenizer.cs @@ -58,7 +58,7 @@ public static SPToken[] Tokenize(string source) { // if found, count the amount of them var slashAmount = 0; - for (int k = j - 1; k >= 0; k--) + for (var k = j - 1; k >= 0; k--) { if (buffer[k - 1] == '\\') {