Line data Source code
1 : /*
2 : * SPDX-License-Identifier: MPL-2.0
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * Copyright 2024 MonetDB Foundation;
9 : * Copyright August 2008 - 2023 MonetDB B.V.;
10 : * Copyright 1997 - July 2008 CWI.
11 : */
12 :
13 : /*
14 : * (c) Martin Kersten
15 : * This module provides a wrapping of the help function in the .../mal/mal_modules.c
16 : * and the list of all MAL functions for analysis using SQL.
17 : */
18 : #include "monetdb_config.h"
19 : #include "gdk.h"
20 : #include <time.h>
21 : #include "mal_resolve.h"
22 : #include "mal_client.h"
23 : #include "mal_exception.h"
24 : #include "mal_interpreter.h"
25 : #include "mal_namespace.h"
26 :
27 : static str
28 12 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
29 : {
30 12 : BAT *mod, *fcn, *sig, *adr, *com;
31 12 : bat *mx = getArgReference_bat(stk, pci, 0);
32 12 : bat *fx = getArgReference_bat(stk, pci, 1);
33 12 : bat *sx = getArgReference_bat(stk, pci, 2);
34 12 : bat *ax = getArgReference_bat(stk, pci, 3);
35 12 : bat *cx = getArgReference_bat(stk, pci, 4);
36 12 : Module *moduleList;
37 12 : int length;
38 12 : int top = 0;
39 12 : Module list[256];
40 :
41 12 : mod = COLnew(0, TYPE_str, 0, TRANSIENT);
42 12 : fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
43 12 : sig = COLnew(0, TYPE_str, 0, TRANSIENT);
44 12 : adr = COLnew(0, TYPE_str, 0, TRANSIENT);
45 12 : com = COLnew(0, TYPE_str, 0, TRANSIENT);
46 12 : 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 12 : list[top++] = cntxt->usermodule;
56 12 : getModuleList(&moduleList, &length);
57 12 : if (moduleList == NULL)
58 0 : goto bailout;
59 834 : while (top < 256 && top <= length) {
60 822 : list[top] = moduleList[top - 1];
61 822 : top++;
62 : }
63 12 : freeModuleList(moduleList);
64 :
65 846 : for (int k = 0; k < top; k++) {
66 834 : Module s = list[k];
67 214338 : for (int j = 0; j < MAXSCOPE; j++) {
68 213504 : if (s->space[j]) {
69 128031 : for (Symbol t = s->space[j]; t != NULL; t = t->peer) {
70 122199 : if (t->kind == FUNCTIONsymbol && t->def->stmt[0]->fcnname[0] == '#')
71 0 : continue;
72 122199 : char buf[1024];
73 122199 : char *comment = NULL;
74 122199 : if (t->kind == FUNCTIONsymbol) {
75 12 : comment = t->def->help;
76 12 : (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
77 : } else {
78 122187 : assert(t->func);
79 122187 : comment = t->func->comment;
80 122187 : (void) cfcnDefinition(t, buf, TRUE, buf, sizeof(buf));
81 : }
82 122199 : char *tt = strstr(buf, " address ");
83 122199 : if (tt) {
84 122187 : *tt = 0;
85 122187 : tt += 9;
86 : }
87 122199 : if (BUNappend(mod, s->name, false) != GDK_SUCCEED
88 122199 : || BUNappend(fcn, t->name,
89 : false) != GDK_SUCCEED
90 122211 : || BUNappend(com, comment ? comment : "",
91 : false) != GDK_SUCCEED
92 122199 : || BUNappend(sig, buf, false) != GDK_SUCCEED
93 122211 : || BUNappend(adr, tt ? tt : "",
94 : false) != GDK_SUCCEED) {
95 0 : goto bailout;
96 : }
97 : }
98 : }
99 : }
100 : }
101 :
102 12 : *mx = mod->batCacheid;
103 12 : BBPkeepref(mod);
104 12 : *fx = fcn->batCacheid;
105 12 : BBPkeepref(fcn);
106 12 : *sx = sig->batCacheid;
107 12 : BBPkeepref(sig);
108 12 : *ax = adr->batCacheid;
109 12 : BBPkeepref(adr);
110 12 : *cx = com->batCacheid;
111 12 : BBPkeepref(com);
112 12 : (void) mb;
113 12 : return MAL_SUCCEED;
114 :
115 0 : bailout:
116 0 : BBPreclaim(mod);
117 0 : BBPreclaim(fcn);
118 0 : BBPreclaim(sig);
119 0 : BBPreclaim(adr);
120 0 : BBPreclaim(com);
121 0 : throw(MAL, "manual.functions", GDK_EXCEPTION);
122 : }
123 :
124 : #include "mel.h"
125 : mel_func manual_init_funcs[] = {
126 : 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))),
127 : { .imp=NULL }
128 : };
129 : #include "mal_import.h"
130 : #ifdef _MSC_VER
131 : #undef read
132 : #pragma section(".CRT$XCU",read)
133 : #endif
134 334 : LIB_STARTUP_FUNC(init_manual_mal)
135 334 : { mal_module("manual", NULL, manual_init_funcs); }
|