Line data Source code
1 : /*
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 : *
6 : * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
7 : */
8 :
9 : /*
10 : * (c) Martin Kersten
11 : * This module provides a wrapping of the help function in the .../mal/mal_modules.c
12 : * and the list of all MAL functions for analysis using SQL.
13 : */
14 : #include "monetdb_config.h"
15 : #include "gdk.h"
16 : #include <time.h>
17 : #include "mal_resolve.h"
18 : #include "mal_client.h"
19 : #include "mal_exception.h"
20 : #include "mal_debugger.h"
21 : #include "mal_interpreter.h"
22 : #include "mal_namespace.h"
23 :
24 : static str
25 8 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
26 : {
27 : BAT *mod, *fcn, *sig, *adr, *com;
28 8 : bat *mx = getArgReference_bat(stk,pci,0);
29 8 : bat *fx = getArgReference_bat(stk,pci,1);
30 8 : bat *sx = getArgReference_bat(stk,pci,2);
31 8 : bat *ax = getArgReference_bat(stk,pci,3);
32 8 : bat *cx = getArgReference_bat(stk,pci,4);
33 : Module s;
34 : Module* moduleList;
35 : int length;
36 : int j, k, top = 0;
37 : Symbol t;
38 : Module list[256];
39 : char buf[BUFSIZ], *tt;
40 :
41 8 : mod = COLnew(0, TYPE_str, 0, TRANSIENT);
42 8 : fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
43 8 : sig = COLnew(0, TYPE_str, 0, TRANSIENT);
44 8 : adr = COLnew(0, TYPE_str, 0, TRANSIENT);
45 8 : com = COLnew(0, TYPE_str, 0, TRANSIENT);
46 8 : if (mod == NULL || fcn == NULL || sig == NULL || adr == NULL || com == NULL) {
47 0 : BBPreclaim(mod);
48 0 : BBPreclaim(fcn);
49 0 : BBPreclaim(sig);
50 0 : BBPreclaim(adr);
51 0 : BBPreclaim(com);
52 0 : throw(MAL, "manual.functions", SQLSTATE(HY013) MAL_MALLOC_FAIL);
53 : }
54 :
55 8 : list[top++] = cntxt->usermodule;
56 8 : getModuleList(&moduleList, &length);
57 8 : if (moduleList == NULL)
58 0 : goto bailout;
59 590 : while (top < 256 && top <= length) {
60 582 : list[top] = moduleList[top - 1];
61 582 : top++;
62 : }
63 8 : freeModuleList(moduleList);
64 :
65 598 : for (k = 0; k < top; k++) {
66 590 : s = list[k];
67 590 : if (s->space) {
68 151630 : for (j = 0; j < MAXSCOPE; j++) {
69 151040 : if (s->space[j]) {
70 109233 : for (t = s->space[j]; t != NULL; t = t->peer) {
71 104947 : if (t->def->stmt[0]->fcnname[0] == '#')
72 8 : continue;
73 104939 : (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
74 104939 : tt = strstr(buf, "address ");
75 104939 : if (tt) {
76 104155 : *tt = 0;
77 104155 : tt += 8;
78 : }
79 209878 : if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED ||
80 209878 : BUNappend(fcn, t->def->stmt[0]->fcnname, false) != GDK_SUCCEED ||
81 256185 : BUNappend(com, t->def->help ? t->def->help : "", false) != GDK_SUCCEED ||
82 209878 : BUNappend(sig,buf,false) != GDK_SUCCEED ||
83 105723 : BUNappend(adr, tt ? tt : "", false) != GDK_SUCCEED) {
84 0 : goto bailout;
85 : }
86 : }
87 : }
88 : }
89 : }
90 : }
91 :
92 8 : BBPkeepref( *mx = mod->batCacheid);
93 8 : BBPkeepref( *fx = fcn->batCacheid);
94 8 : BBPkeepref( *sx = sig->batCacheid);
95 8 : BBPkeepref( *ax = adr->batCacheid);
96 8 : BBPkeepref( *cx = com->batCacheid);
97 : (void)mb;
98 8 : return MAL_SUCCEED;
99 :
100 0 : bailout:
101 0 : BBPreclaim(mod);
102 0 : BBPreclaim(fcn);
103 0 : BBPreclaim(sig);
104 0 : BBPreclaim(adr);
105 0 : BBPreclaim(com);
106 0 : throw(MAL, "manual.functions", GDK_EXCEPTION);
107 : }
108 :
109 : #include "mel.h"
110 : mel_func manual_init_funcs[] = {
111 : pattern("manual", "functions", MANUALcreateOverview, false, "Produces a table with all MAL functions known", args(5,5, batarg("mod",str),batarg("fcn",str),batarg("sig",str),batarg("adr",str),batarg("com",str))),
112 : { .imp=NULL }
113 : };
114 : #include "mal_import.h"
115 : #ifdef _MSC_VER
116 : #undef read
117 : #pragma section(".CRT$XCU",read)
118 : #endif
119 257 : LIB_STARTUP_FUNC(init_manual_mal)
120 257 : { mal_module("manual", NULL, manual_init_funcs); }
|