This repository has been archived by the owner on Nov 12, 2017. It is now read-only.
forked from dcodeIO/thinscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This decorator's intend is to eliminate debugging functions at compile time. Currently clears the function body, only.
- Loading branch information
Showing
6 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Eliminates functions when compiling with the NODEBUG preprocessor flag. | ||
// TODO: Add a compiler optimization that removes empty functions and their respective calls. | ||
|
||
function debug(node: Node, context: CheckContext, decorator: Node): void { | ||
assert(node.kind == NodeKind.FUNCTION); | ||
|
||
// Recover from invalid use | ||
if (node.functionReturnType().stringValue != "void") { | ||
context.log.error(decorator.range, "This decorator cannot be used with functions specifying a return value"); | ||
return; | ||
} | ||
|
||
if (context.isDebug) return; | ||
|
||
var body = node.functionBody(); | ||
if (body == null || body.childCount() == 0) { // Import or already empty | ||
return; | ||
} | ||
|
||
// Clear the body | ||
var child = body.firstChild; | ||
while (child != null) { | ||
var next = child.nextSibling;; | ||
child.remove(); | ||
child = next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters