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

Generated by: LCOV version 1.14