LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - manual.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 61 77 79.2 %
Date: 2024-11-12 21:42:17 Functions: 2 2 100.0 %

          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          16 : MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      29             : {
      30          16 :         BAT *mod, *fcn, *sig, *adr, *com;
      31          16 :         bat *mx = getArgReference_bat(stk, pci, 0);
      32          16 :         bat *fx = getArgReference_bat(stk, pci, 1);
      33          16 :         bat *sx = getArgReference_bat(stk, pci, 2);
      34          16 :         bat *ax = getArgReference_bat(stk, pci, 3);
      35          16 :         bat *cx = getArgReference_bat(stk, pci, 4);
      36          16 :         Module *moduleList;
      37          16 :         int length;
      38          16 :         int top = 0;
      39          16 :         Module list[256];
      40             : 
      41          16 :         mod = COLnew(0, TYPE_str, 0, TRANSIENT);
      42          16 :         fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
      43          16 :         sig = COLnew(0, TYPE_str, 0, TRANSIENT);
      44          16 :         adr = COLnew(0, TYPE_str, 0, TRANSIENT);
      45          16 :         com = COLnew(0, TYPE_str, 0, TRANSIENT);
      46          16 :         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          16 :         list[top++] = cntxt->usermodule;
      56          16 :         getModuleList(&moduleList, &length);
      57          16 :         if (moduleList == NULL)
      58           0 :                 goto bailout;
      59        1110 :         while (top < 256 && top <= length) {
      60        1094 :                 list[top] = moduleList[top - 1];
      61        1094 :                 top++;
      62             :         }
      63          16 :         freeModuleList(moduleList);
      64             : 
      65        1126 :         for (int k = 0; k < top; k++) {
      66        1110 :                 Module s = list[k];
      67      285270 :                 for (int j = 0; j < MAXSCOPE; j++) {
      68      284160 :                         if (s->space[j]) {
      69      170775 :                                 for (Symbol t = s->space[j]; t != NULL; t = t->peer) {
      70      162971 :                                         if (t->kind == FUNCTIONsymbol && t->def->stmt[0]->fcnname[0] == '#')
      71           0 :                                                 continue;
      72      162971 :                                         char buf[1024];
      73      162971 :                                         char *comment = NULL;
      74      162971 :                                         if (t->kind == FUNCTIONsymbol) {
      75          16 :                                                 comment = t->def->help;
      76          16 :                                                 (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
      77             :                                         } else {
      78      162955 :                                                 assert(t->func);
      79      162955 :                                                 comment = t->func->comment;
      80      162955 :                                                 (void) cfcnDefinition(t, buf, TRUE, buf, sizeof(buf));
      81             :                                         }
      82      162971 :                                         char *tt = strstr(buf, " address ");
      83      162971 :                                         if (tt) {
      84      162955 :                                                 *tt = 0;
      85      162955 :                                                 tt += 9;
      86             :                                         }
      87      162971 :                                         if (BUNappend(mod, s->name, false) != GDK_SUCCEED
      88      162971 :                                                 || BUNappend(fcn, t->name,
      89             :                                                                          false) != GDK_SUCCEED
      90      162987 :                                                 || BUNappend(com, comment ? comment : "",
      91             :                                                                          false) != GDK_SUCCEED
      92      162971 :                                                 || BUNappend(sig, buf, false) != GDK_SUCCEED
      93      162987 :                                                 || BUNappend(adr, tt ? tt : "",
      94             :                                                                          false) != GDK_SUCCEED) {
      95           0 :                                                 goto bailout;
      96             :                                         }
      97             :                                 }
      98             :                         }
      99             :                 }
     100             :         }
     101             : 
     102          16 :         *mx = mod->batCacheid;
     103          16 :         BBPkeepref(mod);
     104          16 :         *fx = fcn->batCacheid;
     105          16 :         BBPkeepref(fcn);
     106          16 :         *sx = sig->batCacheid;
     107          16 :         BBPkeepref(sig);
     108          16 :         *ax = adr->batCacheid;
     109          16 :         BBPkeepref(adr);
     110          16 :         *cx = com->batCacheid;
     111          16 :         BBPkeepref(com);
     112          16 :         (void) mb;
     113          16 :         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         324 : LIB_STARTUP_FUNC(init_manual_mal)
     135         324 : { mal_module("manual", NULL, manual_init_funcs); }

Generated by: LCOV version 1.14