From ec691aad83da0adcf13986fd3d24b213ef963116 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 5 Nov 2017 01:52:33 +0100 Subject: -- Added support for void function no return get generated for them. -- Added support for return of void pointers. They will get generated. -- Added support for return a pointer to a bool. There an extra return is added in addtion to "true" and "false". "null". --- src/CodeParser/CParser/CParser.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CodeParser/CParser/CParser.ts b/src/CodeParser/CParser/CParser.ts index 6de9ae0..942b65f 100644 --- a/src/CodeParser/CParser/CParser.ts +++ b/src/CodeParser/CParser/CParser.ts @@ -240,13 +240,27 @@ export default class CParser implements ICodeParser { returnArg.Type.nodes = []; } + // Check if return type is a pointer + const ptrReturnIndex = returnArg.Type.nodes + .findIndex((n) => n instanceof Token && n.Type === TokenType.Pointer); + + // Special case for void functions. + const voidReturnIndex = returnArg.Type.nodes + .findIndex((n) => n instanceof Token && n.Type === TokenType.Symbol && n.Value === "void"); + // Special case for bool return type. const boolReturnIndex: number = returnArg.Type.nodes .findIndex((n) => n instanceof Token && n.Type === TokenType.Symbol && n.Value === "bool"); + if (boolReturnIndex !== -1) { retVals.push("true"); retVals.push("false"); - } else { + if (ptrReturnIndex !== -1) { + retVals.push("null"); + } + } else if (voidReturnIndex !== -1 && ptrReturnIndex !== -1) { + retVals.push(returnArg.Type.Yield()); + } else if (voidReturnIndex === -1 && returnArg.Type.nodes.length > 0) { retVals.push(returnArg.Type.Yield()); } -- cgit v1.2.3