⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inspect.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f inspect@a Martin Kersten@v 1@+ Inspection This module introduces a series of commands that provide accessto information stored within the interpreter data structures.In all cases, the pseudo BAT operation is returned thatshould be garbage collected after being used.The main performance drain would be to use a pseudo BAT directly tosuccessively access it components. This can be avoided by first assigningthe pseudo BAT to a variable.Inspection is organized for two purposes, for interactive useand as a bases for reflective code. The latter needs BATsto work with. The former merely dumps the result in a tablefor the front-ends to consume.@malmodule inspect;command getDefinition(mod:str,fcn:str) :bat[:str,:str] address INSPECTgetDefinitioncomment "Returns a string representation of a specific function.";command getSignature(mod:str,fcn:str) :bat[:str,:str] address INSPECTgetSignaturecomment "Returns the function signature(s).";command getAddress(mod:str,fcn:str) :bat[:str,:str] address INSPECTgetAddresscomment "Returns the function signature(s).";command getComment(mod:str,fcn:str) :bat[:str,:str]address INSPECTgetCommentcomment "Returns the function help information.";command getSource(mod:str,fcn:str):straddress INSPECTgetSourcecomment "Return the original input for a function.";command getKind():bat[:oid,:str]address INSPECTgetkindcomment "Obtain the instruction kind.";command getModule():bat[:oid,:str]address INSPECTgetAllModulescomment "Obtain the function name.";command getFunction():bat[:oid,:str]address INSPECTgetAllFunctionscomment "Obtain the function name.";command getSignatures():bat[:oid,:str]address INSPECTgetAllSignaturescomment "Obtain the function signatures.";command getAddresses():bat[:oid,:str]address INSPECTgetAllAddressescomment "Obtain the function address.";pattern getSize():lngaddress INSPECTgetSizecomment "Return the storage size for the current function (in bytes).";command getSize(mod:str):bat[:str,:lng]address INSPECTgetModuleSizecomment "Return the storage size for a module (in bytes).";command getSize(mod:str,fcn:str):lngaddress INSPECTgetFunctionSizecomment "Return the storage size for a function (in bytes).";pattern getType(v:bat[:any_1,:any_2]) (ht:str, tt:str)address INSPECTtypeNamecomment "Return the internal type of a variable (expression).";pattern getType(v:any_1) :str address INSPECTtypeNamecomment "Return the type of a variable (expression).";command getTypeName(v:int):str address INSPECTtypenamecomment "Get the type name associated with a type id.";pattern getTypeIndex(v:any_1):int address INSPECTtypeIndexcomment "Return the type index of a variable.";command getAtomNames():bat[:int,:str] address INSPECTatom_namescomment "Collect a BAT with the atom names.";command getAtomSuper():bat[:int,:str] address INSPECTatom_sup_namescomment "Collect a BAT with the atom names.";command getAtomSizes():bat[:int,:int] address INSPECTatom_sizescomment "Collect a BAT with the atom sizes.";command getEnvironment():bat[:str,:str]address INSPECTgetEnvironmentcomment "Collect the environment variables.";@-@{@+ Implementation@include prelude.mx@h#ifdef _INSPECT_H#endif /* _INSPECT_H */@c#include "mal_config.h"#include "gdk.h"#include <stdarg.h>#include <time.h>#include "mal_resolve.h"#include "mal_client.h"#include "mal_exception.h"#include "mal_debugger.h"#include "mal_interpreter.h"#include "mal_namespace.h"#ifdef WIN32#ifndef LIBINSPECT#define inspect_export extern __declspec(dllimport)#else#define inspect_export extern __declspec(dllexport)#endif#else#define inspect_export extern#endifinspect_export str INSPECTgetModuleIds(int *ret);inspect_export str INSPECTsymbolFind(int *ret, int kind);inspect_export str INSPECTfactoryNames(int *ret);inspect_export str INSPECTgetFunctionIds(int *ret);inspect_export str INSPECTpatternNames(int *ret);inspect_export str INSPECTcommandNames(int *ret);inspect_export str INSPECTgetFunction(int *ret);inspect_export str INSPECTgetModule(int *ret);inspect_export str INSPECTgetkind(int *ret);inspect_export str INSPECTgetaddress(int *ret);inspect_export str INSPECTgetAllSignatures(int *ret);inspect_export str INSPECTgetAllModules(int *ret);inspect_export str INSPECTgetAllFunctions(int *ret);inspect_export str INSPECTgetAllAddresses(int *ret);inspect_export str INSPECTgetDefinition(int *ret, str *nme, str *fcn);inspect_export str INSPECTgetSignature(int *ret, str *mod, str *fcn);inspect_export str INSPECTgetAddress(int *ret, str *mod, str *fcn);inspect_export str INSPECTgetComment(int *ret, str *mod, str *fcn);inspect_export str INSPECTgetSource(str *ret, str *mod, str *fcn);inspect_export str INSPECTgetModuleSize(int *ret, str *mod);inspect_export str INSPECTgetFunctionSize(lng *ret, str *mod, str *fcn);inspect_export str INSPECTgetSize(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);inspect_export str INSPECTgetEnvironment(int *ret);inspect_export str INSPECTsymbolType(int *ret, str *mod, str *fcn);inspect_export str INSPECTatom_names(int *ret);inspect_export str INSPECTatom_sup_names(int *ret);inspect_export str INSPECTatom_sizes(int *ret);inspect_export str INSPECTshowFunction(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);inspect_export str INSPECTshowFunction3(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);inspect_export str INSPECTtypename(str *ret, int *tpe);inspect_export str INSPECTtype(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);inspect_export str INSPECTtypeName(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);inspect_export str INSPECTtypeIndex(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);@+ Symbol table Mal symbol table and environment analysis.@cstrINSPECTgetModuleIds(int *ret){	Client c;	Module s;	int i = 0;	BAT *b = BATnew(TYPE_void, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getModuleIds", "failed to create BAT");	c = MCgetClient();	for (s = c->nspace; s; s = s->outer, i++)		BUNins(b, (ptr) &int_nil, s->name, FALSE);	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,scope,names)@	return MAL_SUCCEED;}strINSPECTsymbolFind(int *ret, int kind){	Client c;	Module s;	Symbol t;	int i;	BAT *b = BATnew(TYPE_str, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.symbolFind", "failed to create BAT");	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					InstrPtr sig = getSignature(t);					if (kind && kind != sig->token)						continue;					BUNins(b, getModuleId(sig), getFunctionId(sig), FALSE);				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,symbol,name)@	return MAL_SUCCEED;}strINSPECTfactoryNames(int *ret){	return INSPECTsymbolFind(ret, FACTORYsymbol);}strINSPECTgetFunctionIds(int *ret){	return INSPECTsymbolFind(ret, FUNCTIONsymbol);}strINSPECTpatternNames(int *ret){	return INSPECTsymbolFind(ret, PATTERNsymbol);}strINSPECTcommandNames(int *ret){	return INSPECTsymbolFind(ret, COMMANDsymbol);}@-Collect symbol table information in a series of BATs for analysisand display. Note, the elements are aligned using a counter,which makes it susceptable for intermediate updates@cstrINSPECTgetAllFunctions(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getgetFunctionId", "failed to create BAT");	BATseqbase(b, k);	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					InstrPtr sig = getSignature(t);					BUNins(b, &k, getFunctionId(sig), FALSE);					k++;				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,symbol,function)@	return MAL_SUCCEED;}strINSPECTgetAllModules(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.getmodule", "failed to create BAT");	BATseqbase(b, k);	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					InstrPtr sig = getSignature(t);					BUNins(b, &k, getModuleId(sig), FALSE);					k++;				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,symbol,module)@	return MAL_SUCCEED;}strINSPECTgetkind(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.get@1", "failed to create BAT");	BATseqbase(b, k);	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					InstrPtr sig = getSignature(t);					str kind = operatorName(sig->token);					BUNins(b, &k, kind, FALSE);					k++;				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,symbol,kind)@	return MAL_SUCCEED;}strINSPECTgetaddress(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	if (b == 0)		throw(MAL, "inspect.get@1", "failed to create BAT");	BATseqbase(b, k);	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					str kind = t->def->binding;					if (kind == 0)						kind = "";					BUNins(b, &k, &kind, FALSE);					k++;				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view,symbol, address)@	return MAL_SUCCEED;}strINSPECTgetAllSignatures(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	char sig[4096],*a;	if (b == 0)		throw(MAL, "inspect.get@1", "failed to create BAT");	BATseqbase(b, k);	c = MCgetClient();	s = c->nspace;	while (s) {		for (i = 0; s && i < MAXSCOPE; i++)			if (s->subscope[i]) {				for (t = s->subscope[i]; t; t = t->peer) {					fcnDefinition(t->def, getSignature(t), sig, 0);					a= strstr(sig,"address");					if(a) *a = 0;					BUNins(b, &k, strchr(sig, '('), FALSE);					k++;				}			}		s = s->outer;	}	if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ);	@:Pseudo(view, symbol,address)@	return MAL_SUCCEED;}strINSPECTgetAllAddresses(int *ret){	Client c;	Module s;	Symbol t;	int i;	oid k = 0;	BAT *b = BATnew(TYPE_oid, TYPE_str, 256);	char sig[4096],*a;	if (b == 0)		throw(MAL, "inspect.get@1", "failed to create BAT");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -