本文整理汇总了C#中FuncDef类的典型用法代码示例。如果您正苦于以下问题:C# FuncDef类的具体用法?C# FuncDef怎么用?C# FuncDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FuncDef类属于命名空间,在下文中一共展示了FuncDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override Null Visit(FuncDef node)
{
// Define the function
node.symbol = new Symbol {
kind = SymbolKind.Func,
isStatic = node.isStatic,
def = node,
type = new ErrorType()
};
scope.Define(node.symbol);
// Visit the children differently than base.Visit(node) because we
// want to define arguments in the body scope, not the parent scope.
// Note that we don't visit the body, that's for ComputeTypesPass.
node.returnType.Accept(this);
if (node.block != null) {
// Define arguments in the scope of the body
node.block.scope = new Scope(scope, log, ScopeKind.Func);
scope = node.block.scope;
foreach (VarDef argDef in node.argDefs)
argDef.Accept(this);
scope = scope.parent;
} else {
// Define arguments in a temporary scope if no body is present
scope = new Scope(scope, log, ScopeKind.Func);
foreach (VarDef argDef in node.argDefs)
argDef.Accept(this);
scope = scope.parent;
}
return null;
}
示例2: void
/*
** The first parameter (pDef) is a function implementation. The
** second parameter (pExpr) is the first argument to this function.
** If pExpr is a column in a virtual table, then let the virtual
** table implementation have an opportunity to overload the function.
**
** This routine is used to allow virtual table implementations to
** overload MATCH, LIKE, GLOB, and REGEXP operators.
**
** Return either the pDef argument (indicating no change) or a
** new FuncDef structure that is marked as ephemeral using the
** SQLITE_FUNC_EPHEM flag.
*/
FuncDef *sqlite3VtabOverloadFunction(
sqlite3 *db, /* Database connection for reporting malloc problems */
FuncDef *pDef, /* Function to possibly overload */
int nArg, /* Number of arguments to the function */
Expr *pExpr /* First argument to the function */
)
{
Table *pTab;
sqlite3_vtab *pVtab;
sqlite3_module *pMod;
void (*xFunc)(sqlite3_context*,int,sqlite3_value**) = 0;
void *pArg = 0;
FuncDef *pNew;
int rc = 0;
char *zLowerName;
unsigned char *z;
/* Check to see the left operand is a column in a virtual table */
if( NEVER(pExpr==0) ) return pDef;
if( pExpr->op!=TK_COLUMN ) return pDef;
pTab = pExpr->pTab;
if( NEVER(pTab==0) ) return pDef;
if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef;
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
assert( pVtab!=0 );
assert( pVtab->pModule!=0 );
pMod = (sqlite3_module *)pVtab->pModule;
if( pMod->xFindFunction==0 ) return pDef;
/* Call the xFindFunction method on the virtual table implementation
** to see if the implementation wants to overload this function
*/
zLowerName = sqlite3DbStrDup(db, pDef->zName);
if( zLowerName ){
for(z=(unsigned char*)zLowerName; *z; z++){
*z = sqlite3UpperToLower[*z];
}
rc = pMod->xFindFunction(pVtab, nArg, zLowerName, &xFunc, &pArg);
sqlite3DbFree(db, zLowerName);
}
if( rc==0 ){
return pDef;
}
/* Create a new ephemeral function definition for the overloaded
** function */
pNew = sqlite3DbMallocZero(db, sizeof(*pNew)
+ sqlite3Strlen30(pDef->zName) + 1);
if( pNew==0 ){
return pDef;
}
*pNew = *pDef;
pNew->zName = (char *)&pNew[1];
memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
pNew->xFunc = xFunc;
pNew->pUserData = pArg;
pNew->flags |= SQLITE_FUNC_EPHEM;
return pNew;
}
示例3: Visit
public override Null Visit(FuncDef node)
{
// Don't visit the body, that's for ComputeTypesPass
node.returnType.Accept(this);
foreach (VarDef argDef in node.argDefs) {
argDef.Accept(this);
}
// Construct a function type from the parsed return and argument types
node.symbol.type = new FuncType {
returnType = GetInstanceType(node.returnType, true),
argTypes = node.argDefs.ConvertAll(arg => GetInstanceType(arg.type, false))
};
return null;
}
示例4: Visit
public override Null Visit(FuncDef node)
{
// Forbid default arguments for the moment
foreach (VarDef arg in node.argDefs) {
if (arg.value != null) {
log.ErrorDefaultArgNotAllowed(arg.location);
}
}
// Validate the presence of the function body
if (node.info.inExternal != (node.block == null)) {
log.ErrorFunctionBody(node.location, node.info.inExternal);
}
base.Visit(node);
return null;
}
示例5: sqlite3VtabOverloadFunction
/*
** The first parameter (pDef) is a function implementation. The
** second parameter (pExpr) is the first argument to this function.
** If pExpr is a column in a virtual table, then let the virtual
** table implementation have an opportunity to overload the function.
**
** This routine is used to allow virtual table implementations to
** overload MATCH, LIKE, GLOB, and REGEXP operators.
**
** Return either the pDef argument (indicating no change) or a
** new FuncDef structure that is marked as ephemeral using the
** SQLITE_FUNC_EPHEM flag.
*/
static FuncDef sqlite3VtabOverloadFunction(
sqlite3 db, /* Database connection for reporting malloc problems */
FuncDef pDef, /* Function to possibly overload */
int nArg, /* Number of arguments to the function */
Expr pExpr /* First argument to the function */
)
{
Table pTab;
sqlite3_vtab pVtab;
sqlite3_module pMod;
dxFunc xFunc = null;//void (*xFunc)(sqlite3_context*,int,sqlite3_value*) = 0;
object pArg = null;
FuncDef pNew;
int rc = 0;
string zLowerName;
string z;
/* Check to see the left operand is a column in a virtual table */
if ( NEVER( pExpr == null ) )
return pDef;
if ( pExpr.op != TK_COLUMN )
return pDef;
pTab = pExpr.pTab;
if ( NEVER( pTab == null ) )
return pDef;
if ( ( pTab.tabFlags & TF_Virtual ) == 0 )
return pDef;
pVtab = sqlite3GetVTable( db, pTab ).pVtab;
Debug.Assert( pVtab != null );
Debug.Assert( pVtab.pModule != null );
pMod = (sqlite3_module)pVtab.pModule;
if ( pMod.xFindFunction == null )
return pDef;
/* Call the xFindFunction method on the virtual table implementation
** to see if the implementation wants to overload this function
*/
zLowerName = pDef.zName;//sqlite3DbStrDup(db, pDef.zName);
if ( zLowerName != null )
{
//for(z=(unsigned char)zLowerName; *z; z++){
// *z = sqlite3UpperToLower[*z];
//}
rc = pMod.xFindFunction( pVtab, nArg, zLowerName.ToLowerInvariant(), ref xFunc, ref pArg );
sqlite3DbFree( db, ref zLowerName );
}
if ( rc == 0 )
{
return pDef;
}
/* Create a new ephemeral function definition for the overloaded
** function */
//sqlite3DbMallocZero(db, sizeof(*pNew)
// + sqlite3Strlen30(pDef.zName) + 1);
//if ( pNew == null )
//{
// return pDef;
//}
pNew = pDef.Copy();
pNew.zName = pDef.zName;
//pNew.zName = (char )&pNew[1];
//memcpy(pNew.zName, pDef.zName, sqlite3Strlen30(pDef.zName)+1);
pNew.xFunc = xFunc;
pNew.pUserData = pArg;
pNew.flags |= SQLITE_FUNC_EPHEM;
return pNew;
}
示例6: freeEphemeralFunction
/*
** If the input FuncDef structure is ephemeral, then free it. If
** the FuncDef is not ephermal, then do nothing.
*/
static void freeEphemeralFunction( sqlite3 db, FuncDef pDef )
{
if ( ALWAYS( pDef ) && ( pDef.flags & SQLITE_FUNC_EPHEM ) != 0 )
{
pDef = null;
sqlite3DbFree( db, ref pDef );
}
}
示例7: sqlite3VdbeAddOp4
//FUNCDEF
static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, FuncDef pP4, int p4type )
{
union_p4 _p4 = new union_p4();
_p4.pFunc = pP4;
int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 );
sqlite3VdbeChangeP4( p, addr, _p4, p4type );
return addr;
}
示例8: sqlite3VdbeChangeP4
//P4_FUNCDEF
static void sqlite3VdbeChangeP4( Vdbe p, int addr, FuncDef pFunc, int n )
{
union_p4 _p4 = new union_p4();
_p4.pFunc = pFunc;
sqlite3VdbeChangeP4( p, addr, _p4, n );
}
示例9: codeAttach
/// <summary>
/// This procedure generates VDBE code for a single invocation of either the
/// sqlite_detach() or sqlite_attach() SQL user functions.
/// </summary>
/// <param name='pParse'>
/// The parser context
/// </param>
/// <param name='type'>
/// Either SQLITE_ATTACH or SQLITE_DETACH
/// </param>
/// <param name='pFunc'>
/// FuncDef wrapper for detachFunc() or attachFunc()
/// </param>
/// <param name='pAuthArg'>
/// Expression to pass to authorization callback
/// </param>
/// <param name='pFilename'>
/// Name of database file
/// </param>
/// <param name='pDbname'>
/// Name of the database to use internally
/// </param>
/// <param name='pKey'>
/// Database key for encryption extension
/// </param>
static void codeAttach(
Parse pParse,
int type,
FuncDef pFunc,
Expr pAuthArg,
Expr pFilename,
Expr pDbname,
Expr pKey
)
{
NameContext sName;
Vdbe v;
sqlite3 db = pParse.db;
int regArgs;
sName = new NameContext();// memset( &sName, 0, sizeof(NameContext));
sName.pParse = pParse;
if (
SQLITE_OK != (resolveAttachExpr(sName, pFilename)) ||
SQLITE_OK != (resolveAttachExpr(sName, pDbname)) ||
SQLITE_OK != (resolveAttachExpr(sName, pKey))
)
{
pParse.nErr++;
goto attach_end;
}
#if !SQLITE_OMIT_AUTHORIZATION
if( pAuthArg ){
char *zAuthArg;
if( pAuthArg->op==TK_STRING ){
zAuthArg = pAuthArg->u.zToken;
}else{
zAuthArg = 0;
}
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
if(rc!=SQLITE_OK ){
goto attach_end;
}
}
#endif //* SQLITE_OMIT_AUTHORIZATION */
v = sqlite3GetVdbe(pParse);
regArgs = sqlite3GetTempRange(pParse, 4);
sqlite3ExprCode(pParse, pFilename, regArgs);
sqlite3ExprCode(pParse, pDbname, regArgs + 1);
sqlite3ExprCode(pParse, pKey, regArgs + 2);
Debug.Assert(v != null /*|| db.mallocFailed != 0 */ );
if (v != null)
{
sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs + 3 - pFunc.nArg, regArgs + 3);
Debug.Assert(pFunc.nArg == -1 || (pFunc.nArg & 0xff) == pFunc.nArg);
sqlite3VdbeChangeP5(v, (u8)(pFunc.nArg));
sqlite3VdbeChangeP4(v, -1, pFunc, P4_FUNCDEF);
/* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
** statement only). For DETACH, set it to false (expire all existing
** statements).
*/
sqlite3VdbeAddOp1(v, OP_Expire, (type == SQLITE_ATTACH) ? 1 : 0);
}
attach_end:
sqlite3ExprDelete(db, ref pFilename);
sqlite3ExprDelete(db, ref pDbname);
sqlite3ExprDelete(db, ref pKey);
}
示例10: sqlite3FindFunction
/*
** Locate a user function given a name, a number of arguments and a flag
** indicating whether the function prefers UTF-16 over UTF-8. Return a
** pointer to the FuncDef structure that defines that function, or return
** NULL if the function does not exist.
**
** If the createFlag argument is true, then a new (blank) FuncDef
** structure is created and liked into the "db" structure if a
** no matching function previously existed. When createFlag is true
** and the nArg parameter is -1, then only a function that accepts
** any number of arguments will be returned.
**
** If createFlag is false and nArg is -1, then the first valid
** function found is returned. A function is valid if either xFunc
** or xStep is non-zero.
**
** If createFlag is false, then a function with the required name and
** number of arguments may be returned even if the eTextRep flag does not
** match that requested.
*/
static FuncDef sqlite3FindFunction(
sqlite3 db, /* An open database */
string zName, /* Name of the function. Not null-terminated */
int nName, /* Number of characters in the name */
int nArg, /* Number of arguments. -1 means any number */
u8 enc, /* Preferred text encoding */
u8 createFlag /* Create new entry if true and does not otherwise exist */
)
{
FuncDef p; /* Iterator variable */
FuncDef pBest = null; /* Best match found so far */
int bestScore = 0;
int h; /* Hash value */
Debug.Assert( enc == SQLITE_UTF8 || enc == SQLITE_UTF16LE || enc == SQLITE_UTF16BE );
h = ( sqlite3UpperToLower[(u8)zName[0]] + nName ) % ArraySize( db.aFunc.a );
/* First search for a match amongst the application-defined functions.
*/
p = functionSearch( db.aFunc, h, zName, nName );
while ( p != null )
{
int score = matchQuality( p, nArg, enc );
if ( score > bestScore )
{
pBest = p;
bestScore = score;
}
p = p.pNext;
}
/* If no match is found, search the built-in functions.
**
** If the SQLITE_PreferBuiltin flag is set, then search the built-in
** functions even if a prior app-defined function was found. And give
** priority to built-in functions.
**
** Except, if createFlag is true, that means that we are trying to
** install a new function. Whatever FuncDef structure is returned it will
** have fields overwritten with new information appropriate for the
** new function. But the FuncDefs for built-in functions are read-only.
** So we must not search for built-ins when creating a new function.
*/
if ( 0 == createFlag && ( pBest == null || ( db.flags & SQLITE_PreferBuiltin ) != 0 ) )
{
#if SQLITE_OMIT_WSD
FuncDefHash pHash = GLOBAL( FuncDefHash, sqlite3GlobalFunctions );
#else
FuncDefHash pHash = sqlite3GlobalFunctions;
#endif
bestScore = 0;
p = functionSearch( pHash, h, zName, nName );
while ( p != null )
{
int score = matchQuality( p, nArg, enc );
if ( score > bestScore )
{
pBest = p;
bestScore = score;
}
p = p.pNext;
}
}
/* If the createFlag parameter is true and the search did not reveal an
** exact match for the name, number of arguments and encoding, then add a
** new entry to the hash table and return it.
*/
if ( createFlag != 0 && ( bestScore < 6 || pBest.nArg != nArg ) &&
( pBest = new FuncDef() ) != null )
{ //sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
//pBest.zName = (char *)&pBest[1];
pBest.nArg = (i16)nArg;
pBest.iPrefEnc = enc;
pBest.zName = zName; //memcpy(pBest.zName, zName, nName);
//pBest.zName[nName] = 0;
//.........这里部分代码省略.........
示例11: matchQuality
/* During the search for the best function definition, this procedure
** is called to test how well the function passed as the first argument
** matches the request for a function with nArg arguments in a system
** that uses encoding enc. The value returned indicates how well the
** request is matched. A higher value indicates a better match.
**
** The returned value is always between 0 and 6, as follows:
**
** 0: Not a match, or if nArg<0 and the function is has no implementation.
** 1: A variable arguments function that prefers UTF-8 when a UTF-16
** encoding is requested, or vice versa.
** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
** requested, or vice versa.
** 3: A variable arguments function using the same text encoding.
** 4: A function with the exact number of arguments requested that
** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
** 5: A function with the exact number of arguments requested that
** prefers UTF-16LE when UTF-16BE is requested, or vice versa.
** 6: An exact match.
**
*/
static int matchQuality( FuncDef p, int nArg, int enc )
{
int match = 0;
if ( p.nArg == -1 || p.nArg == nArg
|| ( nArg == -1 && ( p.xFunc != null || p.xStep != null ) )
)
{
match = 1;
if ( p.nArg == nArg || nArg == -1 )
{
match = 4;
}
if ( enc == p.iPrefEnc )
{
match += 2;
}
else if ( ( enc == SQLITE_UTF16LE && p.iPrefEnc == SQLITE_UTF16BE ) ||
( enc == SQLITE_UTF16BE && p.iPrefEnc == SQLITE_UTF16LE ) )
{
match += 1;
}
}
return match;
}
示例12: Visit
public override Null Visit(FuncDef node)
{
// Don't initialize arguments
node.block.Accept(this);
return null;
}
示例13: sqlite3Attach
/*
** Called by the parser to compile an ATTACH statement.
**
** ATTACH p AS pDbname KEY pKey
*/
static void sqlite3Attach( Parse pParse, Expr p, Expr pDbname, Expr pKey )
{
FuncDef attach_func = new FuncDef(
3, /* nArg */
SQLITE_UTF8, /* iPrefEnc */
0, /* flags */
null, /* pUserData */
null, /* pNext */
attachFunc, /* xFunc */
null, /* xStep */
null, /* xFinalize */
"sqlite_attach", /* zName */
null /* pHash */
);
codeAttach( pParse, SQLITE_ATTACH, attach_func, p, p, pDbname, pKey );
}
示例14: sqlite3Detach
/*
** Called by the parser to compile a DETACH statement.
**
** DETACH pDbname
*/
static void sqlite3Detach( Parse pParse, Expr pDbname )
{
FuncDef detach_func = new FuncDef(
1, /* nArg */
SQLITE_UTF8, /* iPrefEnc */
0, /* flags */
null, /* pUserData */
null, /* pNext */
detachFunc, /* xFunc */
null, /* xStep */
null, /* xFinalize */
"sqlite_detach", /* zName */
null /* pHash */
);
codeAttach( pParse, SQLITE_DETACH, detach_func, pDbname, null, null, pDbname );
}
示例15: CodeAttach
static void CodeAttach(Parse parse, AUTH type, FuncDef func, Expr authArg, Expr filename, Expr dbName, Expr key)
{
Context ctx = parse.Ctx;
NameContext sName;
sName = new NameContext();
sName.Parse = parse;
if (ResolveAttachExpr(sName, filename) != RC.OK || ResolveAttachExpr(sName, dbName) != RC.OK || ResolveAttachExpr(sName, key) != RC.OK)
{
parse.Errs++;
goto attach_end;
}
#if !OMIT_AUTHORIZATION
if (authArg != null)
{
string authArgToken = (authArg.OP == TK.STRING ? authArg.u.Token : null);
ARC arc = Auth.Check(parse, type, authArgToken, null, null);
if (arc != ARC.OK)
goto attach_end;
}
#endif
Vdbe v = parse.GetVdbe();
int regArgs = Expr.GetTempRange(parse, 4);
Expr.Code(parse, filename, regArgs);
Expr.Code(parse, dbName, regArgs + 1);
Expr.Code(parse, key, regArgs + 2);
Debug.Assert(v != null || ctx.MallocFailed);
if (v != null)
{
v.AddOp3(OP.Function, 0, regArgs + 3 - func.Args, regArgs + 3);
Debug.Assert(func.Args == -1 || (func.Args & 0xff) == func.Args);
v.ChangeP5((byte)(func.Args));
v.ChangeP4(-1, func, Vdbe.P4T.FUNCDEF);
// Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this statement only). For DETACH, set it to false (expire all existing statements).
v.AddOp1(OP.Expire, (type == AUTH.ATTACH ? 1 : 0));
}
attach_end:
Expr.Delete(ctx, ref filename);
Expr.Delete(ctx, ref dbName);
Expr.Delete(ctx, ref key);
}