From 4ab08d85d42d00fe689d0119eed269ed98b226c8 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 12:33:36 +0200 Subject: Fix vscodeautocomplete detection --- src/Lang/Cpp/CppParser.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index ca5edbb..35066fe 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -409,13 +409,13 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { logicalLine += "\n" + nextLineTxt.slice(0, i); - return logicalLine.replace(/^\s+|\s+$/g, ""); + break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { logicalLine += "\n" + nextLineTxt.slice(0, i); - return logicalLine.replace(/^\s+|\s+$/g, ""); + break; } } @@ -425,9 +425,12 @@ export default class CppParser implements ICodeParser { return ""; } - if (!this.isVsCodeAutoComplete(nextLineTxt)) { + if (this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n" + nextLineTxt; + logicalLine.replace(/\*\//g, ""); } + + return logicalLine.trim(); } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); -- cgit v1.2.3 From ab10903637ceacb95fb47003ca512925b8d7faa3 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 13:10:15 +0200 Subject: Fix tests --- src/Lang/Cpp/CppParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 35066fe..35f551c 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -430,7 +430,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - return logicalLine.trim(); + return logicalLine.replace(/^\s+|\s+$/g, ""); } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); -- cgit v1.2.3 From e6388bf4711db2802d9cb8de5a2577b5dffafff3 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 14:02:06 +0200 Subject: Fix for real --- src/Lang/Cpp/CppParser.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 35f551c..0eb8a23 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -386,7 +386,7 @@ export default class CppParser implements ICodeParser { let nextLineTxt: string = this.activeEditor.document.lineAt(nextLine.line).text.trim(); - // VSCode may enter a * on itself, we don"t want that in our method + // VSCode may enter a * on itself, we don't want that in our method if (nextLineTxt === "*") { nextLineTxt = ""; } @@ -399,6 +399,7 @@ export default class CppParser implements ICodeParser { while (linesToGet-- > 0) { // Check for end of expression. nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); + let finalSlice = 0; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -408,13 +409,12 @@ export default class CppParser implements ICodeParser { } else if (nextLineTxt[i] === ")") { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { - logicalLine += "\n" + nextLineTxt.slice(0, i); + finalSlice = i; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { - - logicalLine += "\n" + nextLineTxt.slice(0, i); + finalSlice = i; break; } } @@ -425,12 +425,19 @@ export default class CppParser implements ICodeParser { return ""; } - if (this.isVsCodeAutoComplete(nextLineTxt)) { - logicalLine += "\n" + nextLineTxt; + if (!this.isVsCodeAutoComplete(nextLineTxt)) { + logicalLine += "\n"; + if (finalSlice > 0) { + logicalLine += nextLineTxt.slice(0, finalSlice); + } else { + logicalLine += nextLineTxt; + } logicalLine.replace(/\*\//g, ""); } - return logicalLine.replace(/^\s+|\s+$/g, ""); + if (finalSlice > 0) { + return logicalLine.replace(/^\s+|\s+$/g, ""); + } } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); -- cgit v1.2.3 From 1cf0a3b9762ad5734352fa25514e50caf27ae52f Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 15:28:09 +0200 Subject: Ignore restrict keyword --- src/Lang/Cpp/CppParser.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 0eb8a23..c6a72fb 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -121,6 +121,7 @@ export default class CppParser implements ICodeParser { "const", "struct", "enum", + "restrict", ]; this.stripKeywords = [ -- cgit v1.2.3 From 6e749554cc7a47849bd63d7ec1027f084d26b505 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 16:50:54 +0200 Subject: Add arraypointers --- src/Lang/Cpp/CppParser.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index c6a72fb..2ea3c3f 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -563,6 +563,22 @@ export default class CppParser implements ICodeParser { return nodes.filter((n) => n instanceof CppParseTree).length === 2; } + private IsArrayPtr(nodes: Array) { + if (nodes.filter((n) => n instanceof CppParseTree).length === 1) { + const treeIdx = nodes.findIndex((n) => n instanceof CppParseTree); + if (treeIdx !== -1) { + const nextElem = nodes[treeIdx + 1]; + if (nextElem instanceof CppToken) { + const match = nextElem.value.match(/^\[[0-9]*\]$/g); + if (match !== undefined && match !== null) { + return match.length > 0; + } + } + } + } + return false; + } + private StripNonTypeNodes(tree: CppParseTree) { tree.nodes = tree.nodes // All strippable keywords. @@ -625,7 +641,7 @@ export default class CppParser implements ICodeParser { let cursor: CppParseTree = tree; - while (this.IsFuncPtr(cursor.nodes) === true) { + while (this.IsFuncPtr(cursor.nodes) === true || this.IsArrayPtr(cursor.nodes) === true) { cursor = cursor.nodes.find((n) => n instanceof CppParseTree) as CppParseTree; } @@ -713,6 +729,10 @@ export default class CppParser implements ICodeParser { return this.GetArgumentFromFuncPtr(copy); } + if (this.IsArrayPtr(copy.nodes) === true) { + return this.GetArgumentFromFuncPtr(copy); + } + // Handle member pointers for (let token: number = 0; token < copy.nodes.length - 1; token++) { const firstToken: CppToken = copy.nodes[token] as CppToken; -- cgit v1.2.3 From 3c16da1b09b4a7490e2139d1ee3b96e4ed096806 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Tue, 8 Oct 2019 19:13:55 +0200 Subject: End of declaration problem fixed If the terminating character is the first one on the next line it can cause the buffer to fill and thus produce malformed text to parse. --- src/Lang/Cpp/CppParser.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 2ea3c3f..3b13721 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -401,6 +401,7 @@ export default class CppParser implements ICodeParser { nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); let finalSlice = 0; + let endOfDeclaration = false; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -411,11 +412,13 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { finalSlice = i; + endOfDeclaration = true; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { finalSlice = i; + endOfDeclaration = true; break; } } @@ -428,7 +431,7 @@ export default class CppParser implements ICodeParser { if (!this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n"; - if (finalSlice > 0) { + if (endOfDeclaration === true) { logicalLine += nextLineTxt.slice(0, finalSlice); } else { logicalLine += nextLineTxt; @@ -436,7 +439,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - if (finalSlice > 0) { + if (endOfDeclaration) { return logicalLine.replace(/^\s+|\s+$/g, ""); } } -- cgit v1.2.3 From a5b9a5497abd07c157c8faa5af17a3a16ffe90ad Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Tue, 8 Oct 2019 21:52:10 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20use=20unnecessary=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lang/Cpp/CppParser.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/Lang') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 3b13721..dcdfcba 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -400,8 +400,7 @@ export default class CppParser implements ICodeParser { while (linesToGet-- > 0) { // Check for end of expression. nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); - let finalSlice = 0; - let endOfDeclaration = false; + let finalSlice = -1; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -412,13 +411,11 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { finalSlice = i; - endOfDeclaration = true; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { finalSlice = i; - endOfDeclaration = true; break; } } @@ -431,7 +428,7 @@ export default class CppParser implements ICodeParser { if (!this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n"; - if (endOfDeclaration === true) { + if (finalSlice >= 0) { logicalLine += nextLineTxt.slice(0, finalSlice); } else { logicalLine += nextLineTxt; @@ -439,7 +436,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - if (endOfDeclaration) { + if (finalSlice >= 0) { return logicalLine.replace(/^\s+|\s+$/g, ""); } } -- cgit v1.2.3