/* StoreCode - store the function or method under construction */ void StoreCode(ParseContext *c) { int codeSize; /* check for unterminated blocks */ switch (CurrentBlockType(c)) { case BLOCK_IF: case BLOCK_ELSE: ParseError(c, "expecting END IF"); case BLOCK_FOR: ParseError(c, "expecting NEXT"); case BLOCK_DO: ParseError(c, "expecting LOOP"); case BLOCK_NONE: break; } /* fixup the RESERVE instruction at the start of the code */ if (c->codeType != CODE_TYPE_MAIN) { c->codeBuf[1] = c->localOffset; putcbyte(c, OP_RETURN); } /* make sure all referenced labels were defined */ CheckLabels(c); /* place string literals defined in this function */ PlaceStrings(c); /* determine the code size */ codeSize = (int)(c->cptr - c->codeBuf); #if 0 VM_printf("%s:\n", c->codeName); DecodeFunction((uint8_t *)c->image, (c->image->objectDataSize + GetObjSizeInWords(sizeof(VectorObjectHdr))) * sizeof(VMVALUE), c->codeBuf, codeSize); DumpSymbols(&c->arguments, "arguments"); DumpSymbols(&c->locals, "locals"); VM_printf("\n"); #endif /* store the vector object */ StoreBVectorData(c, c->code, PROTO_CODE, c->codeBuf, codeSize); /* empty the local heap */ c->nextLocal = c->sys->freeTop; InitSymbolTable(&c->arguments); InitSymbolTable(&c->locals); c->labels = NULL; /* reset to compile the next code */ c->codeType = CODE_TYPE_MAIN; c->cptr = c->codeBuf; }
DwUseQuery::DwUseQuery(DwUseOptions* options) { this->options = options; // create a database connection try { this->conn = new DbConnect( options->Username(), options->Password(), options->Database() ); } catch( SQLException ex ) { throw DwUseException( "Error connecting to the database with " + options->Username() +"/" + options->Password() + "@" + options->Database() +": \n" + ex.getMessage() ); } // create variable translator for column this->variableTranslator = new VariableTranslator(this->conn, this->options->Table()); // collect final list of variables // if there are none in the options, read all from the database // else read only the ones in the list string probeSql = "select "; // create a DwColumn for each column that we need (maybe leave out the technical cols) vector<string> cols = this->options->Variables(); if( cols.size() == 0 ) { probeSql += "* "; // we'll check what kind of columns we see. I don't know the schema, or whether table is a view or synonym } else { for(size_t i = 0; i < cols.size(); i++) { if( i > 0 ) probeSql += ", "; probeSql += cols[i]; } } probeSql += " from " + this->options->Table() + " where 1=2 "; // run the probe query and collect columns vector<DbColumnMetaData> colMeta; vector<string> colNames; try { colMeta = this->conn->Describe(probeSql); } catch( SQLException ex ) { string msg = ex.getMessage(); throw DwUseException( "Error reading column definitions with \n" + probeSql +": \n" + msg ); } // we'll need to know what to translate set<string> transVars = this->options->LabelVariables(); set<string> transVals = this->options->LabelValues(); bool isTransAllVars = this->options->IsLabelVariables() && transVars.size() == 0; bool isTransAllVals = this->options->IsLabelValues() && transVals.size() == 0; // create meta data holders for(size_t i=0; i<colMeta.size(); i++) { // get the column name so we can decide if it needs tranlation or not string colName = colMeta[i].name; // not qouted // translate or not? DwColumn* dwCol = new DwColumn( colMeta[i], i+1, // position in ResultSet this->options->VariableCasing(), (isTransAllVars || transVars.find(upperCase(colName)) != transVars.end()) ? this->variableTranslator : NULL, (isTransAllVals || transVals.find(upperCase(colName)) != transVals.end()) ? new ValueTranslator(this->conn, this->options->Table(), colName) : NULL ); this->columns.push_back( dwCol ); colNames.push_back( upperCase(colName) ); // to test translations } // check that all the variables selected for labeling are valid column names CheckLabels( transVars, colNames, "label_variable" ); CheckLabels( transVals, colNames, "label_values" ); };
/* StoreCode - store the function or method under construction */ VMVALUE StoreCode(ParseContext *c) { size_t codeSize; VMVALUE code; uint8_t *p; /* check for unterminated blocks */ switch (CurrentBlockType(c)) { case BLOCK_IF: case BLOCK_ELSE: ParseError(c, "expecting END IF"); case BLOCK_FOR: ParseError(c, "expecting NEXT"); case BLOCK_DO: ParseError(c, "expecting LOOP"); case BLOCK_NONE: break; } /* fixup the RESERVE instruction at the start of the code */ if (c->codeType != CODE_TYPE_MAIN) { c->codeBuf[1] = 2 + c->localOffset; putcbyte(c, OP_RETURN); } /* make sure all referenced labels were defined */ CheckLabels(c); /* allocate code space */ codeSize = (int)(c->codeFree - c->codeBuf); p = (uint8_t *)ImageTextAlloc(c, codeSize); memcpy(p, c->codeBuf, codeSize); /* get the address of the compiled code */ code = (VMVALUE)(p - (uint8_t *)c->image); #ifdef COMPILER_DEBUG { VM_printf("%s:\n", c->codeSymbol ? c->codeSymbol->name : "<main>"); DecodeFunction((uint8_t *)c->image, (uint8_t *)c->image + code, codeSize); DumpSymbols(&c->arguments, "arguments"); DumpSymbols(&c->locals, "locals"); VM_printf("\n"); } #endif /* prepare the buffer for the next function */ c->codeFree = c->codeBuf; /* empty the local heap */ c->localFree = c->heapBase; InitSymbolTable(&c->arguments); InitSymbolTable(&c->locals); c->labels = NULL; /* reset to compile the next code */ c->codeType = CODE_TYPE_MAIN; /* return the code vector */ return code; }