CFunc CFunc::FuncWithBase_InvType(CMyString baseName) const { CMyString sBase, sType1, sType2, sType3, sDescr; ParseFunction(sBase, sType1, sType2, sType3, sDescr); CFunc func = Prefix() + baseName + _T("_"); if (sType1 == sType3) func += sType1 ; else func += sType3 + sType1 ; if (!sDescr.IsEmpty()) func += _T("_") + sDescr; return func; }
void CFunc::GetTypes(ppType& src1, ppType& src2, ppType& dst1, ppType& dst2) const { CMyString sBase, sType1, sType2, sType3, sDescr; ParseFunction(sBase, sType1, sType2, sType3, sDescr); if (sType1.IsEmpty()) throw _T("Bad function type"); src1 = StringToType(sType1); src2 = StringToType(sType2); dst1 = StringToType(sType3); dst2 = dst1; UpdateTypes(src1, src2, dst1, dst2); }
BOOL ParseLine::Parse(LPWSTR line) { if (line[0] == '\0') return FALSE; if (m_strLine) delete[] m_strLine; if (m_strErrorMessage) delete[] m_strErrorMessage; strCopy(m_strLine, line); LPWSTR strCurr = m_strLine; return ParseFunction(strCurr, 0); }
CFunc CFunc::FuncWithBase_InvChannels(CMyString baseName) const { CMyString sBase, sType, sChan1, sChan2, sDescr; ParseFunction(sBase, sType, sDescr); if (sDescr.IsEmpty()) return Prefix() + baseName + _T("_") + sType; sChan1 = firstChanStr(sDescr); sChan2 = firstChanStr(sDescr); CFunc func = Prefix() + baseName + _T("_") + sType + _T("_"); if (sChan2.IsEmpty()) func += sChan1 ; else func += sChan2 + sChan1 ; func += sDescr; return func; }
int CHarmonyHub::ParseControlGroup(const std::string& strControlGroup, std::vector<Function>& vecDeviceFunctions, const std::string& strDeviceID) { const std::string nameTag = "{\"name\":\""; int funcStartPos = strControlGroup.find(nameTag); int funcEndPos = strControlGroup.find("]}"); while(funcStartPos != std::string::npos) { std::string strFunction = strControlGroup.substr(funcStartPos + nameTag.length(), funcEndPos - funcStartPos - nameTag.length()); if(ParseFunction(strFunction, vecDeviceFunctions, strDeviceID) != 0) { return 1; } funcStartPos = strControlGroup.find(nameTag, funcEndPos); funcEndPos = strControlGroup.find("}]}", funcStartPos); } return 0; }
int ConfigReadFile(const char *Path, const char *CommandLine, char **CrayonizerDir, ListNode *CrayonList) { STREAM *S; char *Tempstr=NULL, *Token=NULL; char *ProgName=NULL; const char *ptr, *Args; S=STREAMOpen(Path, "r"); if (! S) return(FALSE); Args=GetToken(CommandLine," ",&ProgName,GETTOKEN_QUOTES); Tempstr=STREAMReadLine(Tempstr,S); while (Tempstr) { StripTrailingWhitespace(Tempstr); StripLeadingWhitespace(Tempstr); ptr=GetToken(Tempstr,"\\S",&Token,0); if (strcasecmp(Token,"CrayonizerDir")==0) *CrayonizerDir=CopyStr(*CrayonizerDir,ptr); else if (strcasecmp(Token,"allowchildcrayon")==0) GlobalFlags |= FLAG_CHILDCRAYON; else if (strcasecmp(Token,"entry")==0) { ptr=GetToken(ptr,"\\S",&Token,0); if (EntryMatchesCommand(Token, ptr, ProgName, Args)) { ConfigReadEntry(S, CrayonList); } else ConfigReadEntry(S, NULL); } else if (strcasecmp(Token,"function")==0) ParseFunction(S, ptr); else if (strcasecmp(Token,"include")==0) ConfigReadFile(ptr, CommandLine, CrayonizerDir, CrayonList); else if (strcasecmp(Token,"selection")==0) StatusBarParseSelection(S, ptr); Tempstr=STREAMReadLine(Tempstr,S); } Destroy(ProgName); Destroy(Tempstr); Destroy(Token); return(TRUE); }
void CFunc::ParseFunction(CMyString& base, CMyString& type1, CMyString& type2, CMyString& type3, CMyString& descr) const { CMyString type; ParseFunction(base,type,descr); int len = type.GetLength(); type1 = firstType(type); int len1 = type1.GetLength(); if (len1 == len) { type2 = type3 = type1; } else { type2 = firstType(type.Mid(len1)); int len2 = type2.GetLength(); if (len1 + len2 == len) { type3 = type2; if (!descr.Found(_T("I"))) type2 = type1; } else { type3 = firstType(type.Mid(len1+len2)); } } }
BOOL ParseLine::ParseFunction(LPWSTR &strCurr, BOOL bRHS) { BOOL bResult = FALSE; skipWhitespaces(strCurr); LPWSTR startOfFunction = strCurr; LPWSTR endOfToken = findEndOfTokenName(strCurr); if (endOfToken == strCurr) return SetErrorMessage(L"Invalid character found", strCurr-m_strLine); if (bRHS) strCopy(RHS.FunctionName, strCurr, endOfToken - strCurr); else strCopy(LHS.FunctionName, strCurr, endOfToken - strCurr); strCurr = endOfToken; skipWhitespaces(strCurr); if (strCurr[0] == '(') { strCurr++; skipWhitespaces(strCurr); if (strCurr[0] != ')') { strCurr--; do { strCurr++; skipWhitespaces(strCurr); if (strCurr[0] == '"') { strCurr++; LPWSTR nextChr = strCurr; do { if (nextChr[0] == '\\') { if (nextChr[1] == '\0') return SetErrorMessage(L"Line continuation by using a backslash is not supported.", strCurr-m_strLine); nextChr += 2; } nextChr = wcspbrk(nextChr, L"\\\""); if (nextChr == NULL) return SetErrorMessage(L"Cannot find end of string", strCurr-m_strLine); } while (nextChr[0] != '"'); if (bRHS) AddParameter(RHS, strCurr, nextChr - strCurr); else AddParameter(LHS, strCurr, nextChr - strCurr); strCurr = nextChr+1; } else { LPWSTR nextChr = wcspbrk(strCurr, L",)"); if (nextChr == NULL) return SetErrorMessage(L"Cannot find next ',' or ')' in function", strCurr-m_strLine); for (nextChr-- ; ((nextChr > strCurr) && (isWhitespace(nextChr[0]))) ; nextChr--); if (nextChr >= strCurr) nextChr++; if (nextChr <= strCurr) return SetErrorMessage(L"Missing parameter", strCurr-m_strLine); if (bRHS) AddParameter(RHS, strCurr, nextChr - strCurr); else AddParameter(LHS, strCurr, nextChr - strCurr); strCurr = nextChr; } skipWhitespaces(strCurr); } while (strCurr[0] == ','); } if (strCurr[0] == '\0') return SetErrorMessage(L"End of line found. Expecting ',' or ')'", strCurr-m_strLine); if (strCurr[0] != ')') return SetErrorMessage(L"Invalid character found. Expecting ',' or ')'", strCurr-m_strLine); strCurr++; bResult = TRUE; } if (bRHS) strCopy(RHS.Function, startOfFunction, strCurr-startOfFunction); else strCopy(LHS.Function, startOfFunction, strCurr-startOfFunction); skipWhitespaces(strCurr); if (strCurr[0] == '=') { if (bRHS) return SetErrorMessage(L"Cannot assign twice. Unexpected '=' found", strCurr-m_strLine); m_bHasRHS = TRUE; strCurr++; LPWSTR endOfFunction = strCurr; return ParseFunction(endOfFunction, TRUE); } if (strCurr[0] == '\0') return TRUE; else if (strCurr[0] == '#') return TRUE; else return SetErrorMessage(L"Invalid character found. Expecting '=' or '('", strCurr-m_strLine); }
TupleCheckStatus FilterInit(Filter *filter, TupleDesc desc, Oid collation) { int i; ParsedFunction func; HeapTuple ftup; HeapTuple ltup; Form_pg_proc pp; Form_pg_language lp; TupleCheckStatus status = NEED_COERCION_CHECK; if (filter->funcstr == NULL) return NO_COERCION; /* parse filter function */ func = ParseFunction(filter->funcstr, true); filter->funcid = func.oid; filter->nargs = func.nargs; for (i = 0; i < filter->nargs; i++) { /* Check for polymorphic types and internal pseudo-type argument */ if (IsPolymorphicType(func.argtypes[i]) || func.argtypes[i] == INTERNALOID) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("filter function does not support a polymorphic function and having a internal pseudo-type argument function: %s", get_func_name(filter->funcid)))); filter->argtypes[i] = func.argtypes[i]; } ftup = SearchSysCache(PROCOID, ObjectIdGetDatum(filter->funcid), 0, 0, 0); pp = (Form_pg_proc) GETSTRUCT(ftup); if (pp->proretset) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("filter function must not return set"))); /* Check data type of the function result value */ if (pp->prorettype == desc->tdtypeid && pp->prorettype != RECORDOID) status = NO_COERCION; else if (pp->prorettype == RECORDOID) { TupleDesc resultDesc = NULL; /* Check for OUT parameters defining a RECORD result */ resultDesc = build_function_result_tupdesc_t(ftup); if (resultDesc) { if (tupledesc_match(desc, resultDesc)) status = NO_COERCION; FreeTupleDesc(resultDesc); } } else if (get_typtype(pp->prorettype) != TYPTYPE_COMPOSITE) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("function return data type and target table data type do not match"))); /* Get default values */ #if PG_VERSION_NUM >= 80400 filter->fn_ndargs = pp->pronargdefaults; if (filter->fn_ndargs > 0) { Datum proargdefaults; bool isnull; char *str; List *defaults; ListCell *l; filter->defaultValues = palloc(sizeof(Datum) * filter->fn_ndargs); filter->defaultIsnull = palloc(sizeof(bool) * filter->fn_ndargs); proargdefaults = SysCacheGetAttr(PROCOID, ftup, Anum_pg_proc_proargdefaults, &isnull); Assert(!isnull); str = TextDatumGetCString(proargdefaults); defaults = (List *) stringToNode(str); Assert(IsA(defaults, List)); pfree(str); filter->econtext = CreateStandaloneExprContext(); i = 0; foreach(l, defaults) { Expr *expr = (Expr *) lfirst(l); ExprState *argstate; ExprDoneCond thisArgIsDone; argstate = ExecInitExpr(expr, NULL); filter->defaultValues[i] = ExecEvalExpr(argstate, filter->econtext, &filter->defaultIsnull[i], &thisArgIsDone); if (thisArgIsDone != ExprSingleResult) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("functions and operators can take at most one set argument"))); i++; }
/* * process ParseSpecifierarations of the form: * * <type> <ParseSpecifier>, <ParseSpecifier>...; * * leaves the ParseSpecifierarations in the symbol table pointed to by * table and returns the number of bytes declared. al is the * allocation type to assign, ilc is the initial location * counter. if al is sc_member then no initialization will * be processed. ztype should be bt_struct for normal and in * structure ParseSpecifierarations and sc_union for in union ParseSpecifierarations. */ int declare(TABLE *table,int al,int ilc,int ztype) { SYM *sp, *sp1, *sp2; TYP *dhead; char stnm[200]; static long old_nbytes; int nbytes; nbytes = 0; ParseSpecifier(table); dhead = head; for(;;) { declid = 0; bit_width = -1; ParseDeclarationPrefix(ztype==bt_union); if( declid != 0) { /* otherwise just struct tag... */ sp = allocSYM(); sp->name = declid; sp->storage_class = al; if (bit_width > 0 && bit_offset > 0) { // share the storage word with the previously defined field nbytes = old_nbytes - ilc; } old_nbytes = ilc + nbytes; if (al != sc_member) { // sp->isTypedef = isTypedef; if (isTypedef) sp->storage_class = sc_typedef; isTypedef = FALSE; } while( (ilc + nbytes) % alignment(head)) { if( al != sc_member && al != sc_external && al != sc_auto) { dseg(); GenerateByte(0); } ++nbytes; } if( al == sc_static) { sp->value.i = nextlabel++; } else if( ztype == bt_union) sp->value.i = ilc; else if( al != sc_auto ) sp->value.i = ilc + nbytes; else sp->value.i = -(ilc + nbytes + head->size); if (bit_width == -1) sp->tp = head; else { sp->tp = allocTYP(); *(sp->tp) = *head; sp->tp->type = bt_bitfield; sp->tp->size = head->size;//tp_int.size; sp->tp->bit_width = bit_width; sp->tp->bit_offset = bit_offset; } if( (sp->tp->type == bt_func) && sp->storage_class == sc_global ) sp->storage_class = sc_external; if(ztype == bt_union) nbytes = imax(nbytes,sp->tp->size); else if(al != sc_external) nbytes += sp->tp->size; if( sp->tp->type == bt_ifunc && (sp1 = search(sp->name,table)) != 0 && sp1->tp->type == bt_func ) { sp1->tp = sp->tp; sp1->storage_class = sp->storage_class; // sp1->value.i = sp->value.i; sp1->IsPrototype = sp->IsPrototype; sp = sp1; } else { sp2 = search(sp->name,table); if (sp2 == NULL) insert(sp,table); else { if (funcdecl==2) sp2->tp = sp->tp; //else if (!sp2->IsPrototype) // insert(sp,table); } } if( sp->tp->type == bt_ifunc) { /* function body follows */ ParseFunction(sp); return nbytes; } if( (al == sc_global || al == sc_static) && sp->tp->type != bt_func && sp->storage_class!=sc_typedef) doinit(sp); } if (funcdecl==TRUE) { if (lastst==comma || lastst==semicolon) break; if (lastst==closepa) goto xit1; } else if (catchdecl==TRUE) { if (lastst==closepa) goto xit1; } else if (lastst == semicolon) break; needpunc(comma); if(declbegin(lastst) == 0) break; head = dhead; } NextToken(); xit1: return nbytes; }
void Compiler::ParseFunctionDef( type_t *type, const char *name ) { def_t *def; function_t f; dfunction_t *df; int i; char parm_names[ MAX_PARMS ][ MAX_NAME ]; int numparms; if ( pr_scope ) { lex.ParseError( "Functions must be global" ); } type = ParseFunction( type, parm_names, &numparms ); def = program.GetDef( type, name, NULL, true, &lex ); // check if this is a prototype or declaration if ( !lex.Check( "{" ) ) { // it's just a prototype, so get the ; and move on lex.Expect( ";" ); return; } if ( def->initialized ) { lex.ParseError( "%s redeclared", name ); } program.locals_start = program.numpr_globals; program.locals_end = program.numpr_globals; pr_scope = def; f = ParseImmediateStatements( type, parm_names, numparms ); pr_scope = NULL; program.locals_end = program.numpr_globals; def->initialized = 1; if ( program.numfunctions >= MAX_FUNCTIONS ) { lex.ParseError( "Exceeded max functions." ); gi.Error( ERR_DROP, "Compile failed." ); } program.setFunction( def->ofs, program.numfunctions ); // fill in the dfunction df = &program.functions[ program.numfunctions ]; program.numfunctions++; df->eventnum = 0; df->first_statement = f.code; df->s_name = def->name; df->s_file = program.s_file; df->numparms = def->type->num_parms; df->minparms = def->type->min_parms; df->locals = program.locals_end - program.locals_start; df->parm_start = program.locals_start; df->parm_total = 0; for( i = 0; i < df->numparms; i++ ) { df->parm_size[ i ] = type_size[ def->type->parm_types[ i ]->type ]; df->parm_total += df->parm_size[ i ]; } program.locals_start = program.locals_end; }
/* * process declarations of the form: * * <type> <specifier>, <specifier>...; * * leaves the declarations in the symbol table pointed to by * table and returns the number of bytes declared. al is the * allocation type to assign, ilc is the initial location * counter. if al is sc_member then no initialization will * be processed. ztype should be bt_struct for normal and in * structure ParseSpecifierarations and sc_union for in union ParseSpecifierarations. */ int declare(TABLE *table,int al,int ilc,int ztype) { SYM *sp, *sp1, *sp2; TYP *dhead, *tp1, *tp2; ENODE *ep1, *ep2; char stnm[200]; int op; int fd; int fn_doneinit = 0; int bcnt; static long old_nbytes; int nbytes; nbytes = 0; if (ParseSpecifier(table)) return nbytes; dhead = head; for(;;) { declid = (char *)NULL; bit_width = -1; ParseDeclarationPrefix(ztype==bt_union); // If a function declaration is taking place and just the type is // specified without a parameter name, assign an internal compiler // generated name. if (funcdecl>0 && funcdecl != 10 && declid==(char *)NULL) { sprintf(lastid, "_p%d", nparms); declid = litlate(lastid); names[nparms++] = declid; missingArgumentName = TRUE; } if( declid != NULL) { /* otherwise just struct tag... */ sp = allocSYM(); sp->name = declid; sp->storage_class = al; sp->isConst = isConst; if (bit_width > 0 && bit_offset > 0) { // share the storage word with the previously defined field nbytes = old_nbytes - ilc; } old_nbytes = ilc + nbytes; if (al != sc_member) { // sp->isTypedef = isTypedef; if (isTypedef) sp->storage_class = sc_typedef; isTypedef = FALSE; } if ((ilc + nbytes) % roundAlignment(head)) { if (al==sc_thread) tseg(); else dseg(); } bcnt = 0; while( (ilc + nbytes) % roundAlignment(head)) { ++nbytes; bcnt++; } if( al != sc_member && al != sc_external && al != sc_auto) { if (bcnt > 0) genstorage(bcnt); } // Set the struct member storage offset. if( al == sc_static || al==sc_thread) { sp->value.i = nextlabel++; } else if( ztype == bt_union) sp->value.i = ilc; else if( al != sc_auto ) sp->value.i = ilc + nbytes; // Auto variables are referenced negative to the base pointer // Structs need to be aligned on the boundary of the largest // struct element. If a struct is all chars this will be 2. // If a struct contains a pointer this will be 8. It has to // be the worst case alignment. else { sp->value.i = -(ilc + nbytes + roundSize(head)); } if (bit_width == -1) sp->tp = head; else { sp->tp = allocTYP(); *(sp->tp) = *head; sp->tp->type = bt_bitfield; sp->tp->size = head->size;//tp_int.size; sp->tp->bit_width = bit_width; sp->tp->bit_offset = bit_offset; } if (isConst) sp->tp->isConst = TRUE; if((sp->tp->type == bt_func) && sp->storage_class == sc_global ) sp->storage_class = sc_external; // Increase the storage allocation by the type size. if(ztype == bt_union) nbytes = imax(nbytes,roundSize(sp->tp)); else if(al != sc_external) { // If a pointer to a function is defined in a struct. if (isStructDecl && (sp->tp->type==bt_func || sp->tp->type==bt_ifunc)) nbytes += 8; else nbytes += roundSize(sp->tp); } if (sp->tp->type == bt_ifunc && (sp1 = search(sp->name,table)) != 0 && sp1->tp->type == bt_func ) { sp1->tp = sp->tp; sp1->storage_class = sp->storage_class; sp1->value.i = sp->value.i; sp1->IsPrototype = sp->IsPrototype; sp = sp1; } else { sp2 = search(sp->name,table); if (sp2 == NULL) insert(sp,table); else { if (funcdecl==2) sp2->tp = sp->tp; //else if (!sp2->IsPrototype) // insert(sp,table); } } if (needParseFunction) { needParseFunction = FALSE; fn_doneinit = ParseFunction(sp); if (sp->tp->type != bt_pointer) return nbytes; } // if(sp->tp->type == bt_ifunc) { /* function body follows */ // ParseFunction(sp); // return nbytes; // } if( (al == sc_global || al == sc_static || al==sc_thread) && !fn_doneinit && sp->tp->type != bt_func && sp->tp->type != bt_ifunc && sp->storage_class!=sc_typedef) doinit(sp); } if (funcdecl>0) { if (lastst==comma || lastst==semicolon) break; if (lastst==closepa) goto xit1; } else if (catchdecl==TRUE) { if (lastst==closepa) goto xit1; } else if (lastst == semicolon) break; else if (lastst == assign) { tp1 = nameref(&ep1); op = en_assign; // NextToken(); tp2 = asnop(&ep2); if( tp2 == 0 || !IsLValue(ep1) ) error(ERR_LVALUE); else { tp1 = forcefit(&ep1,tp1,&ep2,tp2); ep1 = makenode(op,ep1,ep2); } sp->initexp = ep1; if (lastst==semicolon) break; } needpunc(comma); if(declbegin(lastst) == 0) break; head = dhead; } NextToken(); xit1: return nbytes; }
asCScriptNode *asCParser::ParseClass() { asCScriptNode *node = new asCScriptNode(snClass); sToken t; GetToken(&t); if( t.type != ttClass ) { Error(ExpectedToken("class").AddressOf(), &t); return node; } node->SetToken(&t); node->AddChildLast(ParseIdentifier()); GetToken(&t); // Optional list of interfaces that are being implemented and classes that are being inherited if( t.type == ttColon ) { node->AddChildLast(ParseIdentifier()); GetToken(&t); while( t.type == ttListSeparator ) { node->AddChildLast(ParseIdentifier()); GetToken(&t); } } if( t.type != ttStartStatementBlock ) { Error(ExpectedToken("{").AddressOf(), &t); return node; } // Parse properties GetToken(&t); RewindTo(&t); while( t.type != ttEndStatementBlock && t.type != ttEnd ) { // Is it a property or a method? if( IsFuncDecl(true) ) { // Parse the method node->AddChildLast(ParseFunction(true)); } else if( IsVarDecl() ) { // Parse a property declaration asCScriptNode *prop = new asCScriptNode(snDeclaration); node->AddChildLast(prop); prop->AddChildLast(ParseType(true)); if( isSyntaxError ) return node; prop->AddChildLast(ParseIdentifier()); if( isSyntaxError ) return node; GetToken(&t); if( t.type != ttEndStatement ) { Error(ExpectedToken(";").AddressOf(), &t); return node; } prop->UpdateSourcePos(t.pos, t.length); } else { Error(TXT_EXPECTED_METHOD_OR_PROPERTY, &t); return node; } GetToken(&t); RewindTo(&t); } GetToken(&t); if( t.type != ttEndStatementBlock ) { Error(ExpectedToken("}").AddressOf(), &t); return node; } node->UpdateSourcePos(t.pos, t.length); return node; }
static void FunctionParserInit(FunctionParser *self, Checker *checker, const char *infile, TupleDesc desc, bool multi_process, Oid collation) { int i; ParsedFunction function; int nargs; Oid funcid; HeapTuple ftup; Form_pg_proc pp; bool tupledesc_matched = false; if (pg_strcasecmp(infile, "stdin") == 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot load from STDIN in the case of \"TYPE = FUNCTION\""))); if (checker->encoding != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("does not support parameter \"ENCODING\" in \"TYPE = FUNCTION\""))); function = ParseFunction(infile, false); funcid = function.oid; fmgr_info(funcid, &self->flinfo); if (!self->flinfo.fn_retset) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function must return set"))); ftup = SearchSysCache(PROCOID, ObjectIdGetDatum(funcid), 0, 0, 0); pp = (Form_pg_proc) GETSTRUCT(ftup); /* Check data type of the function result value */ if (pp->prorettype == desc->tdtypeid && desc->tdtypeid != RECORDOID) tupledesc_matched = true; else if (pp->prorettype == RECORDOID) { TupleDesc resultDesc = NULL; /* Check for OUT parameters defining a RECORD result */ resultDesc = build_function_result_tupdesc_t(ftup); if (resultDesc) { tupledesc_match(desc, resultDesc); tupledesc_matched = true; FreeTupleDesc(resultDesc); } } else if (get_typtype(pp->prorettype) != TYPTYPE_COMPOSITE) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("function return data type and target table data type do not match"))); if (tupledesc_matched && checker->tchecker) checker->tchecker->status = NO_COERCION; /* * assign arguments */ nargs = function.nargs; for (i = 0; #if PG_VERSION_NUM >= 80400 i < nargs - function.nvargs; #else i < nargs; #endif ++i) { if (function.args[i] == NULL) { if (self->flinfo.fn_strict) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("function is strict, but argument %d is NULL", i))); self->fcinfo.argnull[i] = true; } else { Oid typinput; Oid typioparam; getTypeInputInfo(pp->proargtypes.values[i], &typinput, &typioparam); self->fcinfo.arg[i] = OidInputFunctionCall(typinput, (char *) function.args[i], typioparam, -1); self->fcinfo.argnull[i] = false; pfree(function.args[i]); } } /* * assign variadic arguments */ #if PG_VERSION_NUM >= 80400 if (function.nvargs > 0) { int nfixedarg; Oid func; Oid element_type; int16 elmlen; bool elmbyval; char elmalign; char elmdelim; Oid elmioparam; Datum *elems; bool *nulls; int dims[1]; int lbs[1]; ArrayType *arry; nfixedarg = i; element_type = pp->provariadic; /* * Get info about element type, including its input conversion proc */ get_type_io_data(element_type, IOFunc_input, &elmlen, &elmbyval, &elmalign, &elmdelim, &elmioparam, &func); elems = (Datum *) palloc(function.nvargs * sizeof(Datum)); nulls = (bool *) palloc0(function.nvargs * sizeof(bool)); for (i = 0; i < function.nvargs; i++) { if (function.args[nfixedarg + i] == NULL) nulls[i] = true; else { elems[i] = OidInputFunctionCall(func, (char *) function.args[nfixedarg + i], elmioparam, -1); pfree(function.args[nfixedarg + i]); } } dims[0] = function.nvargs; lbs[0] = 1; arry = construct_md_array(elems, nulls, 1, dims, lbs, element_type, elmlen, elmbyval, elmalign); self->fcinfo.arg[nfixedarg] = PointerGetDatum(arry); } /* * assign default arguments */ if (function.ndargs > 0) { Datum proargdefaults; bool isnull; char *str; List *defaults; int ndelete; ListCell *l; /* shouldn't happen, FuncnameGetCandidates messed up */ if (function.ndargs > pp->pronargdefaults) elog(ERROR, "not enough default arguments"); proargdefaults = SysCacheGetAttr(PROCOID, ftup, Anum_pg_proc_proargdefaults, &isnull); Assert(!isnull); str = TextDatumGetCString(proargdefaults); defaults = (List *) stringToNode(str); Assert(IsA(defaults, List)); pfree(str); /* Delete any unused defaults from the returned list */ ndelete = list_length(defaults) - function.ndargs; while (ndelete-- > 0) defaults = list_delete_first(defaults); self->arg_econtext = CreateStandaloneExprContext(); foreach(l, defaults) { Expr *expr = (Expr *) lfirst(l); ExprState *argstate; ExprDoneCond thisArgIsDone; /* probably shouldn't happen ... */ if (nargs >= FUNC_MAX_ARGS) ereport(ERROR, (errcode(ERRCODE_TOO_MANY_ARGUMENTS), errmsg("cannot pass more than %d arguments to a function", FUNC_MAX_ARGS))); argstate = ExecInitExpr(expr, NULL); self->fcinfo.arg[nargs] = ExecEvalExpr(argstate, self->arg_econtext, &self->fcinfo.argnull[nargs], &thisArgIsDone); if (thisArgIsDone != ExprSingleResult) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("functions and operators can take at most one set argument"))); nargs++; }
// Parse //------------------------------------------------------------------------------ bool BFFParser::Parse( BFFIterator & iter ) { for (;;) { iter.SkipWhiteSpace(); // is this a comment? if ( iter.IsAtComment() ) { iter.SkipComment(); continue; } const char c = *iter; switch ( c ) { case BFF_DECLARE_VAR_INTERNAL: case BFF_DECLARE_VAR_PARENT: { if ( ParseNamedVariableDeclaration( iter ) == false ) { return false; } continue; } case BFF_VARIABLE_CONCATENATION: case BFF_VARIABLE_SUBTRACTION: { // concatenation to last used variable if ( ParseUnnamedVariableModification( iter ) == false ) { return false; } continue; } case BFF_SCOPE_OPEN: { // start an unnamed scope if ( ParseUnnamedScope( iter ) == false ) { return false; } continue; } case BFF_PREPROCESSOR_START: { if ( ParsePreprocessorDirective( iter ) == false ) { return false; } continue; } default: { if ( iter.IsAtValidFunctionNameCharacter() ) { if ( ParseFunction( iter ) == false ) { return false; } continue; } } } iter.SkipWhiteSpace(); if ( iter.IsAtEnd() == false ) { Error::Error_1010_UnknownConstruct( iter ); return false; } break; // cleanly hit end of file } return true; }
asCScriptNode *asCParser::ParseScript() { asCScriptNode *node = new asCScriptNode(snScript); // Determine type of node sToken t1; for(;;) { while( !isSyntaxError ) { GetToken(&t1); RewindTo(&t1); if( t1.type == ttImport ) node->AddChildLast(ParseImport()); else if( t1.type == ttClass ) node->AddChildLast(ParseClass()); else if( t1.type == ttInterface ) node->AddChildLast(ParseInterface()); else if( t1.type == ttConst ) node->AddChildLast(ParseGlobalVar()); else if( IsDataType(t1.type) ) { if( IsVarDecl() ) node->AddChildLast(ParseGlobalVar()); else node->AddChildLast(ParseFunction()); } else if( t1.type == ttEndStatement ) { // Ignore a semicolon by itself GetToken(&t1); } else if( t1.type == ttEnd ) return node; else { asCString str; const char *t = asGetTokenDefinition(t1.type); if( t == 0 ) t = "<unknown token>"; str.Format(TXT_UNEXPECTED_TOKEN_s, t); Error(str.AddressOf(), &t1); } } if( isSyntaxError ) { // Search for either ';' or '{' or end GetToken(&t1); while( t1.type != ttEndStatement && t1.type != ttEnd && t1.type != ttStartStatementBlock ) GetToken(&t1); if( t1.type == ttStartStatementBlock ) { // Find the end of the block and skip nested blocks int level = 1; while( level > 0 ) { GetToken(&t1); if( t1.type == ttStartStatementBlock ) level++; if( t1.type == ttEndStatementBlock ) level--; if( t1.type == ttEnd ) break; } } isSyntaxError = false; } } return 0; }
MultilayerPerceptron* MultilayerPerceptron::FromJSON(std::istream& stream) { Reader r(stream); SetReader(r); SetErrorResult(nullptr); TryGetToken(Token::BeginObject); // ensure we're parsing an MLP TryGetNameValuePair("Type", Token::String); VerifyEqual(r.readString(), "MultilayerPerceptron"); TryGetNameValuePair("Layers", Token::BeginArray); // create our MLP auto_ptr<MLP> mlp(new MLP()); // read each layer for(Token_t t = r.next(); t == Token::BeginObject; t = r.next()) { TryGetNameValuePair("Inputs", Token::Number); uint64_t inputs = r.readUInt(); TryGetNameValuePair("Outputs", Token::Number); uint64_t outputs = r.readUInt(); TryGetNameValuePair("Function", Token::String); ActivationFunction_t function = ParseFunction(r.readString().c_str()); // validate these parameters if(inputs > (uint64_t)std::numeric_limits<uint32_t>::max() || inputs == 0 || outputs > (uint64_t)std::numeric_limits<uint32_t>::max() || outputs == 0 || function == ActivationFunction::Invalid) { return nullptr; } auto_ptr<Layer> layer(new Layer(inputs, outputs, function)); // set biases TryGetNameValuePair("Biases", Token::BeginArray); for(uint32_t j = 0; j < outputs; j++) { TryGetToken(Token::Number); layer->weights.biases()[j] = (float)r.readDouble(); } TryGetToken(Token::EndArray); // set weights TryGetNameValuePair("Weights", Token::BeginArray); for(uint32_t j = 0; j < outputs; j++) { TryGetToken(Token::BeginArray); for(uint32_t i = 0; i < inputs; i++) { TryGetToken(Token::Number); layer->weights.feature(j)[i] = (float)r.readDouble(); } TryGetToken(Token::EndArray); } TryGetToken(Token::EndArray); mlp->AddLayer(layer.release()); TryGetToken(Token::EndObject); } TryGetToken(Token::EndObject); return mlp.release(); }
CMyString CFunc::TypeName() const { CMyString base, type, descr; ParseFunction(base,type,descr); return type; }
CMyString CFunc::DescrName() const { CMyString base, type, descr; ParseFunction(base,type,descr); return descr; }
TrainingSchedule<BackPropagation>* TrainingSchedule<BackPropagation>::FromJSON(const std::string& json) { TrainingSchedule<BackPropagation>* result = nullptr; BackPropagation::ModelConfig model_config; uint32_t minibatch_size; int32_t seed = 1; std::vector<std::pair<BackPropagation::TrainingConfig, uint32_t>> schedule; cJSON* root = cJSON_Parse(json.c_str()); if(root) { cJSON* cj_type = cJSON_GetObjectItem(root, "Type"); if(!cj_type || (strcmp(cj_type->valuestring, "MLP") != 0 && strcmp(cj_type->valuestring, "MultilayerPerceptron") != 0)) { goto Error; } cJSON* cj_layers = cJSON_GetObjectItem(root, "Layers"); cJSON* cj_activation_functions = cJSON_GetObjectItem(root, "ActivationFunctions"); cJSON* cj_minibatch_size = cJSON_GetObjectItem(root, "MinibatchSize"); cJSON* cj_seed = cJSON_GetObjectItem(root, "Seed"); cJSON* cj_schedule = cJSON_GetObjectItem(root, "Schedule"); // make sure we have the mandatory bits if(cj_layers && cj_activation_functions && cj_minibatch_size && cj_schedule) { // verify we hae the right number of layer values and activation function values if(cJSON_GetArraySize(cj_layers) > 1 && cJSON_GetArraySize(cj_layers) == (cJSON_GetArraySize(cj_activation_functions) + 1)) { // get our array iterators and populate the model config cJSON* cj_layer_val; cJSON* cj_func_val; cj_layer_val = cJSON_GetArrayItem(cj_layers, 0); model_config.InputCount = cj_layer_val->valueint; // parse network structure/functions for(int k = 0; k < cJSON_GetArraySize(cj_activation_functions); k++) { cj_layer_val = cJSON_GetArrayItem(cj_layers, k + 1); cj_func_val = cJSON_GetArrayItem(cj_activation_functions, k); if(cj_layer_val && cj_func_val) { BackPropagation::LayerConfig layer_config; layer_config.OutputUnits = cj_layer_val->valueint; layer_config.Function = ParseFunction(cj_func_val->valuestring); if(cj_layer_val->valueint < 1) { goto Error; } if(layer_config.Function == ActivationFunction::Invalid) { goto Error; } model_config.LayerConfigs.push_back(layer_config); } else { goto Error; } } if(cj_seed != nullptr) { seed = cj_seed->valueint; } // minibatch size if(cj_minibatch_size->valueint < 1) { goto Error; } minibatch_size = cj_minibatch_size->valueint; // parse our schedules if(cJSON_GetArraySize(cj_schedule) == 0) { goto Error; } BackPropagation::TrainingConfig train_config; uint32_t layer_count = model_config.LayerConfigs.size(); for(uint32_t k = 0; k < layer_count; k++) { BackPropagation::LayerParameters layer_params;; train_config.Parameters.push_back(layer_params); } // now read each traing config in the schedule for(int k = 0; k < cJSON_GetArraySize(cj_schedule); k++) { cJSON* cj_train_config = cJSON_GetArrayItem(cj_schedule, k); // this function will read an object and if it's an array, populate each member of the array to the appropriate layer config // if it is a single value, all the values in the array are given that value auto read_params = [&] (uint32_t index, const char* param, float min, float max) -> bool { cJSON* cj_param = cJSON_GetObjectItem(cj_train_config, param); if(cj_param) { if(cj_param->type == cJSON_Array) { // ensure we have the right number of params if(cJSON_GetArraySize(cj_param) != layer_count) { return false; } for(uint32_t j = 0; j < layer_count; j++) { cJSON* cj_val = cJSON_GetArrayItem(cj_param, j); if(cj_val->type != cJSON_Number) { return false; } float val = float(cj_val->valuedouble); if(val < min || val > max) { return false; } train_config.Parameters[j].Data[index] = val; } } else if(cj_param->type == cJSON_Number) { for(uint32_t j = 0; j < layer_count; j++) { float val = float(cj_param->valuedouble); if(val < min || val > max) { return false; } train_config.Parameters[j].Data[index] = val; } } } return true; }; # define GET_INDEX(NAME) (((uint32_t)( &( (BackPropagation::LayerParameters*)(void*)0)->NAME) )/sizeof(float)) # define READ_PARAMS(NAME, MIN, MAX) if(read_params(GET_INDEX(NAME), #NAME, MIN, MAX) == false) goto Error; READ_PARAMS(LearningRate, 0.0f, FLT_MAX) READ_PARAMS(Momentum, 0.0f, 1.0f) READ_PARAMS(L1Regularization, 0.0f, FLT_MAX) READ_PARAMS(L2Regularization, 0.0f, FLT_MAX) READ_PARAMS(Dropout, 0.0f, 1.0f) READ_PARAMS(Noise, 0.0f, FLT_MAX) READ_PARAMS(AdadeltaDecay, 0.0f, 1.0f) //now get the number of epochs cJSON* cj_epochs = cJSON_GetObjectItem(cj_train_config, "Epochs"); if(cj_epochs == nullptr || cj_epochs->type != cJSON_Number || cj_epochs->valueint < 1) { goto Error; } uint32_t epochs = cj_epochs->valueint; schedule.push_back(std::pair<BackPropagation::TrainingConfig, uint32_t>(train_config, epochs)); } } else { goto Error; } } else { goto Error; } } else { goto Error; } // create result here result = new TrainingSchedule<BackPropagation>(model_config, minibatch_size, seed); for(uint32_t k = 0; k < schedule.size(); k++) { result->AddTrainingConfig(schedule[k].first, schedule[k].second); } Error: cJSON_Delete(root); return result; }
BOOL CFunc::Roi() const { CMyString base, type, descr; ParseFunction(base,type,descr); return descr.Find(_T("R")) != -1; }