From 0031cbb24bee0d2aa3c308488085e941ab14ebc8 Mon Sep 17 00:00:00 2001 From: Markus Pfeiffer Date: Wed, 11 Jul 2018 05:56:28 +0100 Subject: [PATCH] Move input check for SyntaxTree to SYNTAX_TREE --- lib/syntaxtree.gi | 5 ----- src/syntaxtree.c | 10 +++++----- tst/testinstall/syntaxtree.tst | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/syntaxtree.gi b/lib/syntaxtree.gi index 21ab5e29a3..ed8bf222f4 100644 --- a/lib/syntaxtree.gi +++ b/lib/syntaxtree.gi @@ -3,11 +3,6 @@ # InstallGlobalFunction( SyntaxTree, function(f) - # TODO: Maybe move this to the kernel function - if IsOperation(f) or IsKernelFunction(f) then - Error("f has to be a GAP function (not an operation or a kernel function)"); - fi; - return Objectify( SyntaxTreeType, rec( file := FilenameFunc(f) , line := StartlineFunc(f) , tree := SYNTAX_TREE(f) ) ); diff --git a/src/syntaxtree.c b/src/syntaxtree.c index 6cf9827391..1acc4f099e 100644 --- a/src/syntaxtree.c +++ b/src/syntaxtree.c @@ -62,9 +62,9 @@ typedef struct { static const CompilerT Compilers[]; #define COMPILER_ARITY(...) (sizeof((ArgT[]){ __VA_ARGS__ }) / sizeof(ArgT)) #define COMPILER(tnum, compiler, ...) \ - [tnum] = \ - { tnum, compiler, #tnum, COMPILER_ARITY(__VA_ARGS__), { __VA_ARGS__ } } - + [tnum] = { \ + tnum, compiler, #tnum, COMPILER_ARITY(__VA_ARGS__), { __VA_ARGS__ } \ + } #define COMPILER_(tnum, ...) \ COMPILER(tnum, SyntaxTreeDefaultCompiler, __VA_ARGS__) @@ -863,8 +863,8 @@ Obj FuncSYNTAX_TREE(Obj self, Obj func) { Obj result; - if (!IS_FUNC(func)) { - ErrorQuit("SYNTAX_TREE: must be a function (not a %s)", + if (!IS_FUNC(func) || IsKernelFunction(func) || IS_OPERATION(func)) { + ErrorQuit("SYNTAX_TREE: must be a plain GAP function", (Int)TNAM_OBJ(func), 0L); } diff --git a/tst/testinstall/syntaxtree.tst b/tst/testinstall/syntaxtree.tst index 6946e1fa84..0581ffad18 100644 --- a/tst/testinstall/syntaxtree.tst +++ b/tst/testinstall/syntaxtree.tst @@ -1,7 +1,9 @@ # gap> SYNTAX_TREE(1); -Error, SYNTAX_TREE: must be a function (not a integer) +Error, SYNTAX_TREE: must be a plain GAP function +gap> SYNTAX_TREE(\+); +Error, SYNTAX_TREE: must be a plain GAP function # Just try compiling all functions we can find in the workspace # to see nothing crashes.