From: <asf...@us...> - 2010-06-17 01:18:47
|
Revision: 51259 http://firebird.svn.sourceforge.net/firebird/?rev=51259&view=rev Author: asfernandes Date: 2010-06-17 01:18:40 +0000 (Thu, 17 Jun 2010) Log Message: ----------- Created class BlrWriter and reorganization (move BLR generation from statement to scratch) Modified Paths: -------------- firebird/trunk/builds/posix/make.shared.variables firebird/trunk/builds/win32/msvc9/dsql_server.vcproj firebird/trunk/builds/win32/msvc9/dsql_server_classic.vcproj firebird/trunk/src/dsql/AggNodes.cpp firebird/trunk/src/dsql/DdlNodes.epp firebird/trunk/src/dsql/ExprNodes.cpp firebird/trunk/src/dsql/Nodes.h firebird/trunk/src/dsql/StmtNodes.cpp firebird/trunk/src/dsql/ddl.cpp firebird/trunk/src/dsql/dsql.cpp firebird/trunk/src/dsql/dsql.h firebird/trunk/src/dsql/gen.cpp firebird/trunk/src/dsql/gen_proto.h firebird/trunk/src/dsql/pass1.cpp Added Paths: ----------- firebird/trunk/src/dsql/BlrWriter.cpp firebird/trunk/src/dsql/BlrWriter.h Modified: firebird/trunk/builds/posix/make.shared.variables =================================================================== --- firebird/trunk/builds/posix/make.shared.variables 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/builds/posix/make.shared.variables 2010-06-17 01:18:40 UTC (rev 51259) @@ -81,7 +81,7 @@ DSQL_ServerFiles= metd.epp DSqlDataTypeUtil.cpp \ ddl.cpp dsql.cpp errd.cpp gen.cpp hsh.cpp make.cpp \ movd.cpp parse.cpp Parser.cpp pass1.cpp misc_func.cpp \ - DdlNodes.epp PackageNodes.epp AggNodes.cpp ExprNodes.cpp StmtNodes.cpp WinNodes.cpp + DdlNodes.epp PackageNodes.epp AggNodes.cpp BlrWriter.cpp ExprNodes.cpp StmtNodes.cpp WinNodes.cpp DSQL_Files = $(DSQL_ClientFiles) $(DSQL_ServerFiles) Modified: firebird/trunk/builds/win32/msvc9/dsql_server.vcproj =================================================================== --- firebird/trunk/builds/win32/msvc9/dsql_server.vcproj 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/builds/win32/msvc9/dsql_server.vcproj 2010-06-17 01:18:40 UTC (rev 51259) @@ -271,6 +271,10 @@ > </File> <File + RelativePath="..\..\..\src\dsql\BlrWriter.cpp" + > + </File> + <File RelativePath="..\..\..\src\dsql\ddl.cpp" > </File> @@ -422,6 +426,10 @@ > </File> <File + RelativePath="..\..\..\src\dsql\BlrWriter.h" + > + </File> + <File RelativePath="..\..\..\src\dsql\chars.h" > </File> Modified: firebird/trunk/builds/win32/msvc9/dsql_server_classic.vcproj =================================================================== --- firebird/trunk/builds/win32/msvc9/dsql_server_classic.vcproj 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/builds/win32/msvc9/dsql_server_classic.vcproj 2010-06-17 01:18:40 UTC (rev 51259) @@ -271,6 +271,10 @@ > </File> <File + RelativePath="..\..\..\src\dsql\BlrWriter.cpp" + > + </File> + <File RelativePath="..\..\..\src\dsql\ddl.cpp" > </File> @@ -422,6 +426,10 @@ > </File> <File + RelativePath="..\..\..\src\dsql\BlrWriter.h" + > + </File> + <File RelativePath="..\..\..\src\dsql\chars.h" > </File> Modified: firebird/trunk/src/dsql/AggNodes.cpp =================================================================== --- firebird/trunk/src/dsql/AggNodes.cpp 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/AggNodes.cpp 2010-06-17 01:18:40 UTC (rev 51259) @@ -277,11 +277,11 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); if (aggInfo.blr) // Is this a standard aggregate function? - stuff(statement, (distinct ? aggInfo.distinctBlr : aggInfo.blr)); + dsqlScratch->appendUChar((distinct ? aggInfo.distinctBlr : aggInfo.blr)); else // This is a new window function. { - stuff(statement, blr_agg_function); - stuff_cstring(statement, aggInfo.name); + dsqlScratch->appendUChar(blr_agg_function); + dsqlScratch->appendNullString(aggInfo.name); unsigned count = 0; for (dsql_nod*** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) @@ -290,7 +290,7 @@ ++count; } - stuff(statement, UCHAR(count)); + dsqlScratch->appendUChar(UCHAR(count)); } for (dsql_nod*** i = dsqlChildNodes.begin(); i != dsqlChildNodes.end(); ++i) @@ -795,7 +795,7 @@ if (dsqlArg) AggNode::genBlr(); else - dsqlScratch->getStatement()->append_uchar(blr_agg_count); + dsqlScratch->appendUChar(blr_agg_count); } void CountAggNode::getDesc(thread_db* tdbb, CompilerScratch* /*csb*/, dsc* desc) Added: firebird/trunk/src/dsql/BlrWriter.cpp =================================================================== --- firebird/trunk/src/dsql/BlrWriter.cpp (rev 0) +++ firebird/trunk/src/dsql/BlrWriter.cpp 2010-06-17 01:18:40 UTC (rev 51259) @@ -0,0 +1,207 @@ +/* + * The contents of this file are subject to the Interbase Public + * License Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy + * of the License at http://www.Inprise.com/IPL.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 was created by Inprise Corporation + * and its predecessors. Portions created by Inprise Corporation are + * Copyright (C) Inprise Corporation. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + * Adriano dos Santos Fernandes - refactored from others modules. + */ + +#include "firebird.h" +#include "consts_pub.h" +#include "dyn_consts.h" +#include "gen/iberror.h" +#include "../dsql/BlrWriter.h" +#include "../jrd/common.h" +#include "../jrd/blr.h" +#include "../dsql/errd_proto.h" + +using namespace Firebird; + +namespace Jrd { + + +// Write out a string valued attribute. +void BlrWriter::appendString(UCHAR verb, const char* string, USHORT length) +{ + // TMN: Doesn't this look pretty awkward? If we are given + // a verb, the length is a ushort, else it's uchar. + if (verb) + { + appendUChar(verb); + appendUShort(length); + } + else + { + fb_assert(length <= MAX_UCHAR); + appendUChar(length); + } + + if (string) + appendBytes(reinterpret_cast<const UCHAR*>(string), length); +} + +// Input +// blr_ptr: current position of blr being generated +// verb: blr byte of which number is an argument +// number: value to be written to blr +// Function +// Write out a numeric valued attribute. +void BlrWriter::appendNumber(UCHAR verb, SSHORT number) +{ + if (verb) + appendUChar(verb); + + appendUShortWithLength(number); +} + +void BlrWriter::appendUShortWithLength(USHORT val) +{ + // append an USHORT value, prepended with the USHORT length of an USHORT + appendUShort(2); + appendUShort(val); +} + +void BlrWriter::appendULongWithLength(ULONG val) +{ + // append an ULONG value, prepended with the USHORT length of an ULONG + appendUShort(4); + appendULong(val); +} + +void BlrWriter::appendFileLength(ULONG length) +{ + appendUChar(isc_dyn_file_length); + appendULongWithLength(length); +} + +void BlrWriter::appendFileStart(ULONG start) +{ + appendUChar(isc_dyn_file_start); + appendULongWithLength(start); +} + +// Write out a string of blr as part of a ddl string, as in a view or computed field definition. +void BlrWriter::beginBlr(UCHAR verb) +{ + if (verb) + appendUChar(verb); + + baseOffset = blrData.getCount(); + + // put in a place marker for the size of the blr, since it is unknown + appendUShort(0); + appendUChar(isVersion4() ? blr_version4 : blr_version5); +} + +// Complete the stuffing of a piece of blr by going back and inserting the length. +void BlrWriter::endBlr() +{ + appendUChar(blr_eoc); + + // go back and stuff in the proper length + + UCHAR* blr_base = &blrData[baseOffset]; + const ULONG length = (blrData.getCount() - baseOffset) - 2; + + if (length > 0xFFFF) + ERRD_post(Arg::Gds(isc_too_big_blr) << Arg::Num(length) << Arg::Num(0xFFFF)); + + *blr_base++ = (UCHAR) length; + *blr_base = (UCHAR) (length >> 8); +} + +void BlrWriter::beginDebug() +{ + fb_assert(debugData.isEmpty()); + + debugData.add(fb_dbg_version); + debugData.add(1); +} + +void BlrWriter::endDebug() +{ + debugData.add(fb_dbg_end); +} + +void BlrWriter::putDebugSrcInfo(USHORT line, USHORT col) +{ + debugData.add(fb_dbg_map_src2blr); + + debugData.add(line); + debugData.add(line >> 8); + + debugData.add(col); + debugData.add(col >> 8); + + ULONG offset = (blrData.getCount() - baseOffset); + + // for DDL statements we store BLR's length at the first 2 bytes + if (isDdlDyn()) + offset -= 2; + + debugData.add(offset); + debugData.add(offset >> 8); +} + +void BlrWriter::putDebugVariable(USHORT number, const TEXT* name) +{ + fb_assert(name); + + debugData.add(fb_dbg_map_varname); + + debugData.add(number); + debugData.add(number >> 8); + + USHORT len = strlen(name); + if (len > MAX_UCHAR) + len = MAX_UCHAR; + debugData.add(len); + + debugData.add(reinterpret_cast<const UCHAR*>(name), len); +} + +void BlrWriter::putDebugArgument(UCHAR type, USHORT number, const TEXT* name) +{ + fb_assert(name); + + debugData.add(fb_dbg_map_argument); + + debugData.add(type); + debugData.add(number); + debugData.add(number >> 8); + + USHORT len = strlen(name); + if (len > MAX_UCHAR) + len = MAX_UCHAR; + debugData.add(len); + + debugData.add(reinterpret_cast<const UCHAR*>(name), len); +} + +void BlrWriter::appendDebugInfo() +{ + endDebug(); + + const size_t len = blrData.getCount() + debugData.getCount(); + if (len + 4 < MAX_USHORT) + { + appendUChar(isc_dyn_debug_info); + appendUShort(debugData.getCount()); + appendBytes(debugData.begin(), debugData.getCount()); + } +} + + +} // namespace Jrd Property changes on: firebird/trunk/src/dsql/BlrWriter.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: firebird/trunk/src/dsql/BlrWriter.h =================================================================== --- firebird/trunk/src/dsql/BlrWriter.h (rev 0) +++ firebird/trunk/src/dsql/BlrWriter.h 2010-06-17 01:18:40 UTC (rev 51259) @@ -0,0 +1,148 @@ +/* + * The contents of this file are subject to the Interbase Public + * License Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy + * of the License at http://www.Inprise.com/IPL.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 was created by Inprise Corporation + * and its predecessors. Portions created by Inprise Corporation are + * Copyright (C) Inprise Corporation. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + * Adriano dos Santos Fernandes - refactored from others modules. + */ + +#ifndef DSQL_BLR_WRITER_H +#define DSQL_BLR_WRITER_H + +#include "../jrd/common.h" +#include "../common/classes/alloc.h" +#include "../common/classes/array.h" +#include "../common/classes/fb_string.h" +#include "../common/classes/MetaName.h" + +namespace Jrd { + +class dsql_nod; + + +// BLR/DYN writer. +class BlrWriter : public Firebird::PermanentStorage +{ +public: + explicit BlrWriter(MemoryPool& p) + : PermanentStorage(p), + blrData(p), + debugData(p), + baseOffset(0) + { + } + + void appendUChar(const UCHAR byte) + { + blrData.add(byte); + } + + // Cram a word into the blr buffer. + void appendUShort(USHORT word) + { + appendUChar(word); + appendUChar(word >> 8); + } + + void appendULong(ULONG val) + { + appendUShort(val); + appendUShort(val >> 16); + } + + void appendUCharRepeated(UCHAR byte, int count) + { + for (int i = 0; i < count; ++i) + appendUChar(byte); + } + + void appendBytes(const UCHAR* string, USHORT len) + { + blrData.add(string, len); + } + + // Write out a string with one byte of length. + void appendNullString(const char* string) + { + size_t len = strlen(string); + + // CVC: Maybe the Release version should truncate "len" to 255? + fb_assert(len >= 0 && len <= 255); + + appendUChar(len); + appendBytes(reinterpret_cast<const UCHAR*>(string), len); + } + + // Write out a string valued attribute. + void appendNullString(UCHAR verb, const char* string) + { + const USHORT length = string ? strlen(string) : 0; + appendString(verb, string, length); + } + + // Write out a string in metadata charset with one byte of length. + void appendMetaString(const char* string) + { + appendString(0, string, strlen(string)); + } + + void appendString(UCHAR verb, const char* string, USHORT len); + + void appendString(UCHAR verb, const Firebird::MetaName& name) + { + appendString(verb, name.c_str(), name.length()); + } + + void appendString(UCHAR verb, const Firebird::string& name) + { + appendString(verb, name.c_str(), name.length()); + } + + void appendNumber(UCHAR verb, SSHORT number); + void appendUShortWithLength(USHORT val); + void appendULongWithLength(ULONG val); + void appendFileLength(ULONG length); + void appendFileStart(ULONG start); + + void beginBlr(UCHAR verb); + void endBlr(); + + void beginDebug(); + void endDebug(); + void putDebugSrcInfo(USHORT, USHORT); + void putDebugVariable(USHORT, const TEXT*); + void putDebugArgument(UCHAR, USHORT, const TEXT*); + void appendDebugInfo(); + + Firebird::HalfStaticArray<UCHAR, 1024>& getBlrData() { return blrData; } + Firebird::HalfStaticArray<UCHAR, 128>& getDebugData() { return debugData; } + + ULONG getBaseOffset() const { return baseOffset; } + void setBaseOffset(ULONG value) { baseOffset = value; } + +protected: + virtual bool isVersion4() = 0; + virtual bool isDdlDyn() = 0; + +private: + Firebird::HalfStaticArray<UCHAR, 1024> blrData; + Firebird::HalfStaticArray<UCHAR, 128> debugData; + ULONG baseOffset; // place to go back and stuff in blr length +}; + + +} // namespace + +#endif // DSQL_BLR_WRITER_H Property changes on: firebird/trunk/src/dsql/BlrWriter.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: firebird/trunk/src/dsql/DdlNodes.epp =================================================================== --- firebird/trunk/src/dsql/DdlNodes.epp 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/DdlNodes.epp 2010-06-17 01:18:40 UTC (rev 51259) @@ -132,7 +132,7 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); if (type.notNull) - statement->append_uchar(blr_not_nullable); + dsqlScratch->appendUChar(blr_not_nullable); if (type.typeOfName.hasData()) { @@ -140,34 +140,34 @@ { if (type.collateSpecified) { - statement->append_uchar(blr_column_name2); - statement->append_uchar(type.fullDomain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(type.typeOfTable.c_str()); - statement->append_meta_string(type.typeOfName.c_str()); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_column_name2); + dsqlScratch->appendUChar(type.fullDomain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(type.typeOfTable.c_str()); + dsqlScratch->appendMetaString(type.typeOfName.c_str()); + dsqlScratch->appendUShort(type.textType); } else { - statement->append_uchar(blr_column_name); - statement->append_uchar(type.fullDomain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(type.typeOfTable.c_str()); - statement->append_meta_string(type.typeOfName.c_str()); + dsqlScratch->appendUChar(blr_column_name); + dsqlScratch->appendUChar(type.fullDomain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(type.typeOfTable.c_str()); + dsqlScratch->appendMetaString(type.typeOfName.c_str()); } } else { if (type.collateSpecified) { - statement->append_uchar(blr_domain_name2); - statement->append_uchar(type.fullDomain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(type.typeOfName.c_str()); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_domain_name2); + dsqlScratch->appendUChar(type.fullDomain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(type.typeOfName.c_str()); + dsqlScratch->appendUShort(type.textType); } else { - statement->append_uchar(blr_domain_name); - statement->append_uchar(type.fullDomain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(type.typeOfName.c_str()); + dsqlScratch->appendUChar(blr_domain_name); + dsqlScratch->appendUChar(type.fullDomain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(type.typeOfName.c_str()); } } @@ -181,39 +181,39 @@ case dtype_varying: case dtype_blob: if (!useSubType) - statement->append_uchar(blr_dtypes[type.type]); + dsqlScratch->appendUChar(blr_dtypes[type.type]); else if (type.type == dtype_varying) { - statement->append_uchar(blr_varying2); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_varying2); + dsqlScratch->appendUShort(type.textType); } else if (type.type == dtype_cstring) { - statement->append_uchar(blr_cstring2); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_cstring2); + dsqlScratch->appendUShort(type.textType); } else if (type.type == dtype_blob) { - statement->append_uchar(blr_blob2); - statement->append_ushort(type.subType); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_blob2); + dsqlScratch->appendUShort(type.subType); + dsqlScratch->appendUShort(type.textType); } else { - statement->append_uchar(blr_text2); - statement->append_ushort(type.textType); + dsqlScratch->appendUChar(blr_text2); + dsqlScratch->appendUShort(type.textType); } if (type.type == dtype_varying) - statement->append_ushort(type.length - sizeof(USHORT)); + dsqlScratch->appendUShort(type.length - sizeof(USHORT)); else if (type.type != dtype_blob) - statement->append_ushort(type.length); + dsqlScratch->appendUShort(type.length); break; default: - statement->append_uchar(blr_dtypes[type.type]); + dsqlScratch->appendUChar(blr_dtypes[type.type]); if (DTYPE_IS_EXACT(type.type) || dtype_quad == type.type) - statement->append_uchar(type.scale); + dsqlScratch->appendUChar(type.scale); break; } } @@ -959,13 +959,13 @@ { FUN.RDB$FUNCTION_BLR.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &FUN.RDB$FUNCTION_BLR, - statement->getBlrData().begin(), - statement->getBlrData().getCount()); + dsqlScratch->getBlrData().begin(), + dsqlScratch->getBlrData().getCount()); FUN.RDB$DEBUG_INFO.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &FUN.RDB$DEBUG_INFO, - statement->getDebugData().begin(), - statement->getDebugData().getCount()); + dsqlScratch->getDebugData().begin(), + dsqlScratch->getDebugData().getCount()); } } @@ -1110,20 +1110,20 @@ string defaultSource = string(defaultString->str_data, defaultString->str_length); attachment->storeMetaDataBlob(tdbb, transaction, &ARG.RDB$DEFAULT_SOURCE, defaultSource); - statement->getBlrData().clear(); + dsqlScratch->getBlrData().clear(); if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) - statement->append_uchar(blr_version4); + dsqlScratch->appendUChar(blr_version4); else - statement->append_uchar(blr_version5); + dsqlScratch->appendUChar(blr_version5); GEN_expr(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); - statement->append_uchar(blr_eoc); + dsqlScratch->appendUChar(blr_eoc); attachment->storeBinaryBlob(tdbb, transaction, &ARG.RDB$DEFAULT_VALUE, - statement->getBlrData().begin(), - statement->getBlrData().getCount()); + dsqlScratch->getBlrData().begin(), + dsqlScratch->getBlrData().getCount()); } } END_STORE @@ -1145,49 +1145,49 @@ if (body) { - statement->beginDebug(); - statement->getBlrData().clear(); + dsqlScratch->beginDebug(); + dsqlScratch->getBlrData().clear(); if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) - statement->append_uchar(blr_version4); + dsqlScratch->appendUChar(blr_version4); else - statement->append_uchar(blr_version5); + dsqlScratch->appendUChar(blr_version5); - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); if (parameters.getCount() != 0) { fb_assert(parameters.getCount() < size_t(MAX_USHORT / 2)); - statement->append_uchar(blr_message); - statement->append_uchar(0); - statement->append_ushort(2 * parameters.getCount()); + dsqlScratch->appendUChar(blr_message); + dsqlScratch->appendUChar(0); + dsqlScratch->appendUShort(2 * parameters.getCount()); for (unsigned i = 0; i < parameters.getCount(); ++i) { ParameterClause& parameter = parameters[i]; - statement->put_debug_argument(fb_dbg_arg_input, i, + dsqlScratch->putDebugArgument(fb_dbg_arg_input, i, parameter.name.c_str()); putType(parameter, true); // add slot for null flag (parameter2) - statement->append_uchar(blr_short); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); variables.add(MAKE_variable(parameter.legacyField, parameter.name.c_str(), VAR_input, 0, (USHORT) (2 * i), 0)); } } - statement->append_uchar(blr_message); - statement->append_uchar(1); - statement->append_ushort(2); + dsqlScratch->appendUChar(blr_message); + dsqlScratch->appendUChar(1); + dsqlScratch->appendUShort(2); - statement->put_debug_argument(fb_dbg_arg_output, 0, ""); + dsqlScratch->putDebugArgument(fb_dbg_arg_output, 0, ""); putType(returnType, true); // add slot for null flag (parameter2) - statement->append_uchar(blr_short); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); dsql_nod* const var = MAKE_variable(returnType.legacyField, "", VAR_output, 1, 0, 0); variables.add(var); @@ -1195,11 +1195,11 @@ if (parameters.getCount() != 0) { - statement->append_uchar(blr_receive); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_receive); + dsqlScratch->appendUChar(0); } - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); for (unsigned i = 0; i < parameters.getCount(); ++i) { @@ -1209,12 +1209,12 @@ { // ASF: To validate input parameters we need only to read its value. // Assigning it to null is an easy way to do this. - statement->append_uchar(blr_assignment); - statement->append_uchar(blr_parameter2); - statement->append_uchar(0); // input - statement->append_ushort(i * 2); - statement->append_ushort(i * 2 + 1); - statement->append_uchar(blr_null); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_parameter2); + dsqlScratch->appendUChar(0); // input + dsqlScratch->appendUShort(i * 2); + dsqlScratch->appendUShort(i * 2 + 1); + dsqlScratch->appendUChar(blr_null); } } @@ -1227,24 +1227,24 @@ putLocalVariables(dsqlScratch, localDeclList, 1); - statement->append_uchar(blr_stall); + dsqlScratch->appendUChar(blr_stall); // put a label before body of procedure, // so that any EXIT statement can get out - statement->append_uchar(blr_label); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_label); + dsqlScratch->appendUChar(0); dsqlScratch->loopLevel = 0; dsqlScratch->cursorNumber = 0; GEN_statement(dsqlScratch, PASS1_statement(dsqlScratch, body)); statement->setType(DsqlCompiledStatement::TYPE_DDL); - statement->append_uchar(blr_end); - genReturn(statement, false); + dsqlScratch->appendUChar(blr_end); + genReturn(dsqlScratch, false); - statement->append_uchar(blr_end); - statement->append_uchar(blr_eoc); + dsqlScratch->appendUChar(blr_end); + dsqlScratch->appendUChar(blr_eoc); - statement->endDebug(); + dsqlScratch->endDebug(); } invalid = false; @@ -1761,13 +1761,13 @@ { P.RDB$PROCEDURE_BLR.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &P.RDB$PROCEDURE_BLR, - statement->getBlrData().begin(), - statement->getBlrData().getCount()); + dsqlScratch->getBlrData().begin(), + dsqlScratch->getBlrData().getCount()); P.RDB$DEBUG_INFO.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &P.RDB$DEBUG_INFO, - statement->getDebugData().begin(), - statement->getDebugData().getCount()); + dsqlScratch->getDebugData().begin(), + dsqlScratch->getDebugData().getCount()); P.RDB$PROCEDURE_TYPE.NULL = FALSE; P.RDB$PROCEDURE_TYPE = (USHORT) @@ -1914,20 +1914,20 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - statement->getBlrData().clear(); + dsqlScratch->getBlrData().clear(); if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) - statement->append_uchar(blr_version4); + dsqlScratch->appendUChar(blr_version4); else - statement->append_uchar(blr_version5); + dsqlScratch->appendUChar(blr_version5); GEN_expr(dsqlScratch, parameter.legacyDefault->nod_arg[e_dft_default]); - statement->append_uchar(blr_eoc); + dsqlScratch->appendUChar(blr_eoc); attachment->storeBinaryBlob(tdbb, transaction, &PRM.RDB$DEFAULT_VALUE, - statement->getBlrData().begin(), - statement->getBlrData().getCount()); + dsqlScratch->getBlrData().begin(), + dsqlScratch->getBlrData().getCount()); } } END_STORE @@ -1951,32 +1951,32 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - statement->beginDebug(); - statement->getBlrData().clear(); + dsqlScratch->beginDebug(); + dsqlScratch->getBlrData().clear(); if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) - statement->append_uchar(blr_version4); + dsqlScratch->appendUChar(blr_version4); else - statement->append_uchar(blr_version5); + dsqlScratch->appendUChar(blr_version5); - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); if (parameters.getCount() != 0) { fb_assert(parameters.getCount() < MAX_USHORT / 2); - statement->append_uchar(blr_message); - statement->append_uchar(0); - statement->append_ushort(2 * parameters.getCount()); + dsqlScratch->appendUChar(blr_message); + dsqlScratch->appendUChar(0); + dsqlScratch->appendUShort(2 * parameters.getCount()); for (unsigned i = 0; i < parameters.getCount(); ++i) { ParameterClause& parameter = parameters[i]; - statement->put_debug_argument(fb_dbg_arg_input, i, parameter.name.c_str()); + dsqlScratch->putDebugArgument(fb_dbg_arg_input, i, parameter.name.c_str()); putType(parameter, true); // add slot for null flag (parameter2) - statement->append_uchar(blr_short); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); variables.add(MAKE_variable(parameter.legacyField, parameter.name.c_str(), VAR_input, 0, (USHORT) (2 * i), 0)); @@ -1984,21 +1984,21 @@ } fb_assert(returns.getCount() < MAX_USHORT / 2); - statement->append_uchar(blr_message); - statement->append_uchar(1); - statement->append_ushort(2 * returns.getCount() + 1); + dsqlScratch->appendUChar(blr_message); + dsqlScratch->appendUChar(1); + dsqlScratch->appendUShort(2 * returns.getCount() + 1); if (returns.getCount() != 0) { for (unsigned i = 0; i < returns.getCount(); ++i) { ParameterClause& parameter = returns[i]; - statement->put_debug_argument(fb_dbg_arg_output, i, parameter.name.c_str()); + dsqlScratch->putDebugArgument(fb_dbg_arg_output, i, parameter.name.c_str()); putType(parameter, true); // add slot for null flag (parameter2) - statement->append_uchar(blr_short); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); dsql_nod* const var = MAKE_variable(parameter.legacyField, parameter.name.c_str(), VAR_output, 1, (USHORT) (2 * i), i); @@ -2009,16 +2009,16 @@ } // add slot for EOS - statement->append_uchar(blr_short); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); if (parameters.getCount() != 0) { - statement->append_uchar(blr_receive); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_receive); + dsqlScratch->appendUChar(0); } - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); for (unsigned i = 0; i < parameters.getCount(); ++i) { @@ -2028,12 +2028,12 @@ { // ASF: To validate an input parameter we need only to read its value. // Assigning it to null is an easy way to do this. - statement->append_uchar(blr_assignment); - statement->append_uchar(blr_parameter2); - statement->append_uchar(0); // input - statement->append_ushort(i * 2); - statement->append_ushort(i * 2 + 1); - statement->append_uchar(blr_null); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_parameter2); + dsqlScratch->appendUChar(0); // input + dsqlScratch->appendUShort(i * 2); + dsqlScratch->appendUShort(i * 2 + 1); + dsqlScratch->appendUChar(blr_null); } } @@ -2050,24 +2050,24 @@ putLocalVariables(dsqlScratch, localDeclList, returns.getCount()); - statement->append_uchar(blr_stall); + dsqlScratch->appendUChar(blr_stall); // put a label before body of procedure, // so that any EXIT statement can get out - statement->append_uchar(blr_label); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_label); + dsqlScratch->appendUChar(0); dsqlScratch->loopLevel = 0; dsqlScratch->cursorNumber = 0; GEN_statement(dsqlScratch, PASS1_statement(dsqlScratch, body)); statement->setType(DsqlCompiledStatement::TYPE_DDL); - statement->append_uchar(blr_end); - genReturn(statement, true); + dsqlScratch->appendUChar(blr_end); + genReturn(dsqlScratch, true); - statement->append_uchar(blr_end); - statement->append_uchar(blr_eoc); + dsqlScratch->appendUChar(blr_end); + dsqlScratch->appendUChar(blr_eoc); - statement->endDebug(); + dsqlScratch->endDebug(); invalid = false; } @@ -2466,13 +2466,13 @@ TRG.RDB$TRIGGER_BLR.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &TRG.RDB$TRIGGER_BLR, - statement->getBlrData().begin(), - statement->getBlrData().getCount()); + dsqlScratch->getBlrData().begin(), + dsqlScratch->getBlrData().getCount()); TRG.RDB$DEBUG_INFO.NULL = FALSE; attachment->storeBinaryBlob(tdbb, transaction, &TRG.RDB$DEBUG_INFO, - statement->getDebugData().begin(), - statement->getDebugData().getCount()); + dsqlScratch->getDebugData().begin(), + dsqlScratch->getDebugData().getCount()); } if (source.hasData()) @@ -2515,8 +2515,8 @@ { DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - statement->beginDebug(); - statement->getBlrData().clear(); + dsqlScratch->beginDebug(); + dsqlScratch->getBlrData().clear(); // Create the "OLD" and "NEW" contexts for the trigger -- // the new one could be a dummy place holder to avoid resolving @@ -2559,11 +2559,11 @@ // generate the trigger blr if (statement->getFlags() & DsqlCompiledStatement::FLAG_BLR_VERSION4) - statement->append_uchar(blr_version4); + dsqlScratch->appendUChar(blr_version4); else - statement->append_uchar(blr_version5); + dsqlScratch->appendUChar(blr_version5); - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); dsqlScratch->setPsql(true); @@ -2577,16 +2577,16 @@ // although the fact that they use the same BLR code // is still a potential danger and must be fixed. // Hopefully, system triggers are never recompiled. - statement->append_uchar(blr_label); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_label); + dsqlScratch->appendUChar(0); dsqlScratch->loopLevel = 0; dsqlScratch->cursorNumber = 0; GEN_statement(dsqlScratch, PASS1_statement(dsqlScratch, body)); dsqlScratch->scopeLevel--; - statement->append_uchar(blr_end); - statement->append_uchar(blr_eoc); + dsqlScratch->appendUChar(blr_end); + dsqlScratch->appendUChar(blr_eoc); - statement->endDebug(); + dsqlScratch->endDebug(); // The statement type may have been set incorrectly when parsing // the trigger actions, so reset it to reflect the fact that this Modified: firebird/trunk/src/dsql/ExprNodes.cpp =================================================================== --- firebird/trunk/src/dsql/ExprNodes.cpp 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/ExprNodes.cpp 2010-06-17 01:18:40 UTC (rev 51259) @@ -189,7 +189,7 @@ void ConcatenateNode::genBlr() { - stuff(dsqlScratch->getStatement(), blr_concatenate); + dsqlScratch->appendUChar(blr_concatenate); GEN_expr(dsqlScratch, dsqlArg1); GEN_expr(dsqlScratch, dsqlArg2); } @@ -677,7 +677,7 @@ void SubstringSimilarNode::genBlr() { - stuff(dsqlScratch->getStatement(), blr_substring_similar); + dsqlScratch->appendUChar(blr_substring_similar); GEN_expr(dsqlScratch, dsqlExpr); GEN_expr(dsqlScratch, dsqlPattern); GEN_expr(dsqlScratch, dsqlEscape); @@ -928,9 +928,9 @@ { DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - stuff(statement, blr_sys_function); - statement->append_meta_string(function->name.c_str()); - stuff(statement, dsqlArgs->nod_count); + dsqlScratch->appendUChar(blr_sys_function); + dsqlScratch->appendMetaString(function->name.c_str()); + dsqlScratch->appendUChar(dsqlArgs->nod_count); dsql_nod* const* ptr = dsqlArgs->nod_arg; for (const dsql_nod* const* const end = ptr + dsqlArgs->nod_count; ptr < end; ptr++) @@ -1161,15 +1161,15 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); if (dsqlFunction->udf_name.package.isEmpty()) - stuff(statement, blr_function); + dsqlScratch->appendUChar(blr_function); else { - stuff(statement, blr_function2); - statement->append_meta_string(dsqlFunction->udf_name.package.c_str()); + dsqlScratch->appendUChar(blr_function2); + dsqlScratch->appendMetaString(dsqlFunction->udf_name.package.c_str()); } - statement->append_meta_string(dsqlFunction->udf_name.identifier.c_str()); - stuff(statement, dsqlArgs->nod_count); + dsqlScratch->appendMetaString(dsqlFunction->udf_name.identifier.c_str()); + dsqlScratch->appendUChar(dsqlArgs->nod_count); dsql_nod* const* ptr = dsqlArgs->nod_arg; for (const dsql_nod* const* const end = ptr + dsqlArgs->nod_count; ptr < end; ptr++) Modified: firebird/trunk/src/dsql/Nodes.h =================================================================== --- firebird/trunk/src/dsql/Nodes.h 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/Nodes.h 2010-06-17 01:18:40 UTC (rev 51259) @@ -592,7 +592,7 @@ void putLocalVariable(DsqlCompilerScratch* dsqlScratch, dsql_var* variable, dsql_nod* hostParam, const dsql_str* collationName); dsql_nod* resolveVariable(const dsql_str* varName); - void genReturn(DsqlCompiledStatement* statement, bool eosFlag = false); + void genReturn(DsqlCompilerScratch* dsqlScratch, bool eosFlag = false); private: bool hasEos; Modified: firebird/trunk/src/dsql/StmtNodes.cpp =================================================================== --- firebird/trunk/src/dsql/StmtNodes.cpp 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/StmtNodes.cpp 2010-06-17 01:18:40 UTC (rev 51259) @@ -70,7 +70,7 @@ DsqlCompiledStatement* statement = dsqlScratch->getStatement(); if (field->fld_not_nullable) - statement->append_uchar(blr_not_nullable); + dsqlScratch->appendUChar(blr_not_nullable); if (field->fld_type_of_name.hasData()) { @@ -78,34 +78,34 @@ { if (field->fld_explicit_collation) { - statement->append_uchar(blr_column_name2); - statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(field->fld_type_of_table->str_data); - statement->append_meta_string(field->fld_type_of_name.c_str()); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_column_name2); + dsqlScratch->appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(field->fld_type_of_table->str_data); + dsqlScratch->appendMetaString(field->fld_type_of_name.c_str()); + dsqlScratch->appendUShort(field->fld_ttype); } else { - statement->append_uchar(blr_column_name); - statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(field->fld_type_of_table->str_data); - statement->append_meta_string(field->fld_type_of_name.c_str()); + dsqlScratch->appendUChar(blr_column_name); + dsqlScratch->appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(field->fld_type_of_table->str_data); + dsqlScratch->appendMetaString(field->fld_type_of_name.c_str()); } } else { if (field->fld_explicit_collation) { - statement->append_uchar(blr_domain_name2); - statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(field->fld_type_of_name.c_str()); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_domain_name2); + dsqlScratch->appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(field->fld_type_of_name.c_str()); + dsqlScratch->appendUShort(field->fld_ttype); } else { - statement->append_uchar(blr_domain_name); - statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - statement->append_meta_string(field->fld_type_of_name.c_str()); + dsqlScratch->appendUChar(blr_domain_name); + dsqlScratch->appendUChar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + dsqlScratch->appendMetaString(field->fld_type_of_name.c_str()); } } @@ -119,39 +119,39 @@ case dtype_varying: case dtype_blob: if (!useSubType) - statement->append_uchar(blr_dtypes[field->fld_dtype]); + dsqlScratch->appendUChar(blr_dtypes[field->fld_dtype]); else if (field->fld_dtype == dtype_varying) { - statement->append_uchar(blr_varying2); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_varying2); + dsqlScratch->appendUShort(field->fld_ttype); } else if (field->fld_dtype == dtype_cstring) { - statement->append_uchar(blr_cstring2); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_cstring2); + dsqlScratch->appendUShort(field->fld_ttype); } else if (field->fld_dtype == dtype_blob) { - statement->append_uchar(blr_blob2); - statement->append_ushort(field->fld_sub_type); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_blob2); + dsqlScratch->appendUShort(field->fld_sub_type); + dsqlScratch->appendUShort(field->fld_ttype); } else { - statement->append_uchar(blr_text2); - statement->append_ushort(field->fld_ttype); + dsqlScratch->appendUChar(blr_text2); + dsqlScratch->appendUShort(field->fld_ttype); } if (field->fld_dtype == dtype_varying) - statement->append_ushort(field->fld_length - sizeof(USHORT)); + dsqlScratch->appendUShort(field->fld_length - sizeof(USHORT)); else if (field->fld_dtype != dtype_blob) - statement->append_ushort(field->fld_length); + dsqlScratch->appendUShort(field->fld_length); break; default: - statement->append_uchar(blr_dtypes[field->fld_dtype]); + dsqlScratch->appendUChar(blr_dtypes[field->fld_dtype]); if (DTYPE_IS_EXACT(field->fld_dtype) || (dtype_quad == field->fld_dtype)) - statement->append_uchar(field->fld_scale); + dsqlScratch->appendUChar(field->fld_scale); break; } } @@ -160,8 +160,6 @@ void BlockNode::putLocalVariables(DsqlCompilerScratch* dsqlScratch, const dsql_nod* parameters, SSHORT locals) { - using namespace Dsql; // nod_*, e_* - if (!parameters) return; @@ -170,17 +168,17 @@ { dsql_nod* parameter = *ptr; - dsqlScratch->getStatement()->put_debug_src_info(parameter->nod_line, parameter->nod_column); + dsqlScratch->putDebugSrcInfo(parameter->nod_line, parameter->nod_column); - if (parameter->nod_type == nod_def_field) + if (parameter->nod_type == Dsql::nod_def_field) { - dsql_fld* field = (dsql_fld*) parameter->nod_arg[e_dfl_field]; + dsql_fld* field = (dsql_fld*) parameter->nod_arg[Dsql::e_dfl_field]; const dsql_nod* const* rest = ptr; while (++rest != end) { - if ((*rest)->nod_type == nod_def_field) + if ((*rest)->nod_type == Dsql::nod_def_field) { - const dsql_fld* rest_field = (dsql_fld*) (*rest)->nod_arg[e_dfl_field]; + const dsql_fld* rest_field = (dsql_fld*) (*rest)->nod_arg[Dsql::e_dfl_field]; if (field->fld_name == rest_field->fld_name) { ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-637) << @@ -194,7 +192,7 @@ dsql_var* variable = (dsql_var*) var_node->nod_arg[Dsql::e_var_variable]; putLocalVariable(dsqlScratch, variable, parameter, - reinterpret_cast<const dsql_str*>(parameter->nod_arg[e_dfl_collate])); + reinterpret_cast<const dsql_str*>(parameter->nod_arg[Dsql::e_dfl_collate])); // Some field attributes are calculated inside // putLocalVariable(), so we reinitialize the @@ -203,7 +201,7 @@ locals++; } - else if (parameter->nod_type == nod_cursor) + else if (parameter->nod_type == Dsql::nod_cursor) { PASS1_statement(dsqlScratch, parameter); GEN_statement(dsqlScratch, parameter); @@ -215,13 +213,11 @@ void BlockNode::putLocalVariable(DsqlCompilerScratch* dsqlScratch, dsql_var* variable, dsql_nod* hostParam, const dsql_str* collationName) { - using namespace Dsql; // nod_*, e_* - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); dsql_fld* field = variable->var_field; - statement->append_uchar(blr_dcl_variable); - statement->append_ushort(variable->var_variable_number); + dsqlScratch->appendUChar(blr_dcl_variable); + dsqlScratch->appendUShort(variable->var_variable_number); DDL_resolve_intl_type(dsqlScratch, field, collationName); //const USHORT dtype = field->fld_dtype; @@ -230,33 +226,33 @@ //field->fld_dtype = dtype; // Check for a default value, borrowed from define_domain - dsql_nod* node = hostParam ? hostParam->nod_arg[e_dfl_default] : NULL; + dsql_nod* node = hostParam ? hostParam->nod_arg[Dsql::e_dfl_default] : NULL; if (node || (!field->fld_full_domain && !field->fld_not_nullable)) { - statement->append_uchar(blr_assignment); + dsqlScratch->appendUChar(blr_assignment); if (node) { - fb_assert(node->nod_type == nod_def_default); + fb_assert(node->nod_type == Dsql::nod_def_default); PsqlChanger psqlChanger(dsqlScratch, false); - node = PASS1_node(dsqlScratch, node->nod_arg[e_dft_default]); + node = PASS1_node(dsqlScratch, node->nod_arg[Dsql::e_dft_default]); GEN_expr(dsqlScratch, node); } else - statement->append_uchar(blr_null); // Initialize variable to NULL + dsqlScratch->appendUChar(blr_null); // Initialize variable to NULL - statement->append_uchar(blr_variable); - statement->append_ushort(variable->var_variable_number); + dsqlScratch->appendUChar(blr_variable); + dsqlScratch->appendUShort(variable->var_variable_number); } else { - statement->append_uchar(blr_init_variable); - statement->append_ushort(variable->var_variable_number); + dsqlScratch->appendUChar(blr_init_variable); + dsqlScratch->appendUShort(variable->var_variable_number); } if (variable->var_name[0]) // Not a function return value - statement->put_debug_variable(variable->var_variable_number, variable->var_name); + dsqlScratch->putDebugVariable(variable->var_variable_number, variable->var_name); ++dsqlScratch->hiddenVarsNumber; } @@ -283,46 +279,46 @@ } // Generate BLR for a return. -void BlockNode::genReturn(DsqlCompiledStatement* statement, bool eosFlag) +void BlockNode::genReturn(DsqlCompilerScratch* dsqlScratch, bool eosFlag) { if (hasEos && !eosFlag) - stuff(statement, blr_begin); + dsqlScratch->appendUChar(blr_begin); - stuff(statement, blr_send); - stuff(statement, 1); - stuff(statement, blr_begin); + dsqlScratch->appendUChar(blr_send); + dsqlScratch->appendUChar(1); + dsqlScratch->appendUChar(blr_begin); for (Array<dsql_nod*>::const_iterator i = outputVariables.begin(); i != outputVariables.end(); ++i) { const dsql_nod* parameter = *i; const dsql_var* variable = (dsql_var*) parameter->nod_arg[Dsql::e_var_variable]; - stuff(statement, blr_assignment); - stuff(statement, blr_variable); - stuff_word(statement, variable->var_variable_number); - stuff(statement, blr_parameter2); - stuff(statement, variable->var_msg_number); - stuff_word(statement, variable->var_msg_item); - stuff_word(statement, variable->var_msg_item + 1); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_variable); + dsqlScratch->appendUShort(variable->var_variable_number); + dsqlScratch->appendUChar(blr_parameter2); + dsqlScratch->appendUChar(variable->var_msg_number); + dsqlScratch->appendUShort(variable->var_msg_item); + dsqlScratch->appendUShort(variable->var_msg_item + 1); } if (hasEos) { - stuff(statement, blr_assignment); - stuff(statement, blr_literal); - stuff(statement, blr_short); - stuff(statement, 0); - stuff_word(statement, (eosFlag ? 0 : 1)); - stuff(statement, blr_parameter); - stuff(statement, 1); - stuff_word(statement, USHORT(2 * outputVariables.getCount())); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_literal); + dsqlScratch->appendUChar(blr_short); + dsqlScratch->appendUChar(0); + dsqlScratch->appendUShort((eosFlag ? 0 : 1)); + dsqlScratch->appendUChar(blr_parameter); + dsqlScratch->appendUChar(1); + dsqlScratch->appendUShort(USHORT(2 * outputVariables.getCount())); } - stuff(statement, blr_end); + dsqlScratch->appendUChar(blr_end); if (hasEos && !eosFlag) { - stuff(statement, blr_stall); - stuff(statement, blr_end); + dsqlScratch->appendUChar(blr_stall); + dsqlScratch->appendUChar(blr_end); } } @@ -371,11 +367,11 @@ { DsqlCompiledStatement* const statement = dsqlScratch->getStatement(); - statement->append_uchar(blr_begin); - statement->append_uchar(blr_start_savepoint); + dsqlScratch->appendUChar(blr_begin); + dsqlScratch->appendUChar(blr_start_savepoint); stmt->genBlr(); - statement->append_uchar(blr_end_savepoint); - statement->append_uchar(blr_end); + dsqlScratch->appendUChar(blr_end_savepoint); + dsqlScratch->appendUChar(blr_end); } @@ -402,12 +398,10 @@ IfNode* IfNode::internalDsqlPass() { - IfNode* node = FB_NEW(getPool()) IfNode(getPool()); - node->dsqlScratch = dsqlScratch; + IfNode* node = FB_NEW(getPool()) IfNode(getPool(), dsqlScratch); node->dsqlCondition = PASS1_node(dsqlScratch, dsqlCondition); node->dsqlTrueAction = PASS1_statement(dsqlScratch, dsqlTrueAction); node->dsqlFalseAction = PASS1_statement(dsqlScratch, dsqlFalseAction); - return node; } @@ -424,15 +418,13 @@ void IfNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - - stuff(statement, blr_if); + dsqlScratch->appendUChar(blr_if); GEN_expr(dsqlScratch, dsqlCondition); GEN_statement(dsqlScratch, dsqlTrueAction); if (dsqlFalseAction) GEN_statement(dsqlScratch, dsqlFalseAction); else - stuff(statement, blr_end); + dsqlScratch->appendUChar(blr_end); } @@ -522,10 +514,8 @@ void InAutonomousTransactionNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - - stuff(statement, blr_auto_trans); - stuff(statement, 0); // to extend syntax in the future + dsqlScratch->appendUChar(blr_auto_trans); + dsqlScratch->appendUChar(0); // to extend syntax in the future GEN_statement(dsqlScratch, dsqlAction); } @@ -758,7 +748,7 @@ const size_t count = node->parameters.getCount() + node->returns.getCount() + (node->localDeclList ? node->localDeclList->nod_count : 0); - if (count) + if (count != 0) { StrArray names(*getDefaultMemoryPool(), count); @@ -815,22 +805,17 @@ // Update blockNode, because we have a reference to the original unprocessed node. statement->setBlockNode(this); - statement->beginDebug(); + dsqlScratch->beginDebug(); - USHORT inputs = 0, outputs = 0, locals = 0; - // now do the input parameters for (size_t i = 0; i < parameters.getCount(); ++i) { ParameterClause& parameter = parameters[i]; dsql_nod* var = MAKE_variable(parameter.legacyField, - parameter.name.c_str(), VAR_input, 0, (USHORT) (2 * inputs), locals); + parameter.name.c_str(), VAR_input, 0, (USHORT) (2 * i), 0); variables.add(var); - - // ASF: do not increment locals here - CORE-2341 - inputs++; } const unsigned returnsPos = variables.getCount(); @@ -841,17 +826,15 @@ ParameterClause& parameter = returns[i]; dsql_nod* var = MAKE_variable(parameter.legacyField, - parameter.name.c_str(), VAR_output, 1, (USHORT) (2 * outputs), locals++); + parameter.name.c_str(), VAR_output, 1, (USHORT) (2 * i), i); variables.add(var); outputVariables.add(var); - - ++outputs; } - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); - if (inputs) + if (parameters.hasData()) { revertParametersOrder(statement->getSendMsg()->msg_parameters); GEN_port(dsqlScratch, statement->getSendMsg()); @@ -878,13 +861,13 @@ revertParametersOrder(statement->getReceiveMsg()->msg_parameters); GEN_port(dsqlScratch, statement->getReceiveMsg()); - if (inputs) + if (parameters.hasData()) { - statement->append_uchar(blr_receive); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_receive); + dsqlScratch->appendUChar(0); } - statement->append_uchar(blr_begin); + dsqlScratch->appendUChar(blr_begin); for (unsigned i = 0; i < returnsPos; ++i) { @@ -897,14 +880,14 @@ // ASF: Validation of execute block input parameters is different than procedure // parameters, because we can't generate messages using the domains due to the // connection charset influence. So to validate, we cast them and assign to null. - statement->append_uchar(blr_assignment); - statement->append_uchar(blr_cast); + dsqlScratch->appendUChar(blr_assignment); + dsqlScratch->appendUChar(blr_cast); BlockNode::putDtype(dsqlScratch, field, true); - statement->append_uchar(blr_parameter2); - statement->append_uchar(0); - statement->append_ushort(variable->var_msg_item); - statement->append_ushort(variable->var_msg_item + 1); - statement->append_uchar(blr_null); + dsqlScratch->appendUChar(blr_parameter2); + dsqlScratch->appendUChar(0); + dsqlScratch->appendUShort(variable->var_msg_item); + dsqlScratch->appendUShort(variable->var_msg_item + 1); + dsqlScratch->appendUChar(blr_null); } } @@ -917,29 +900,29 @@ dsqlScratch->setPsql(true); - putLocalVariables(dsqlScratch, localDeclList, locals); + putLocalVariables(dsqlScratch, localDeclList, USHORT(returns.getCount())); dsqlScratch->loopLevel = 0; dsql_nod* stmtNode = PASS1_statement(dsqlScratch, body); GEN_hidden_variables(dsqlScratch, false); - statement->append_uchar(blr_stall); + dsqlScratch->appendUChar(blr_stall); // Put a label before body of procedure, so that // any exit statement can get out - statement->append_uchar(blr_label); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_label); + dsqlScratch->appendUChar(0); GEN_statement(dsqlScratch, stmtNode); - if (outputs) + if (returns.hasData()) statement->setType(DsqlCompiledStatement::TYPE_SELECT_BLOCK); else statement->setType(DsqlCompiledStatement::TYPE_EXEC_BLOCK); - statement->append_uchar(blr_end); - genReturn(statement, true); - statement->append_uchar(blr_end); + dsqlScratch->appendUChar(blr_end); + genReturn(dsqlScratch, true); + dsqlScratch->appendUChar(blr_end); - statement->endDebug(); + dsqlScratch->endDebug(); } @@ -1063,33 +1046,31 @@ void ExceptionNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); + dsqlScratch->appendUChar(blr_abort); - stuff(statement, blr_abort); - // If exception name is undefined, it means we have re-initiate semantics here, // so blr_raise verb should be generated. if (name.isEmpty()) { - stuff(statement, blr_raise); + dsqlScratch->appendUChar(blr_raise); return; } // If exception value is defined, it means we have user-defined exception message // here, so blr_exception_msg verb should be generated. if (dsqlParameters) - stuff(statement, blr_exception_params); + dsqlScratch->appendUChar(blr_exception_params); else if (dsqlMessageExpr) - stuff(statement, blr_exception_msg); + dsqlScratch->appendUChar(blr_exception_msg); else // Otherwise go usual way, i.e. generate blr_exception. - stuff(statement, blr_exception); + dsqlScratch->appendUChar(blr_exception); - stuff_cstring(statement, name.c_str()); + dsqlScratch->appendNullString(name.c_str()); // If exception parameters or value is defined, generate appropriate BLR verbs. if (dsqlParameters) { - stuff_word(statement, dsqlParameters->nod_count); + dsqlScratch->appendUShort(dsqlParameters->nod_count); dsql_nod** ptr = dsqlParameters->nod_arg; const dsql_nod* const* end = ptr + dsqlParameters->nod_count; @@ -1298,9 +1279,8 @@ void ExitNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - stuff(statement, blr_leave); - stuff(statement, 0); + dsqlScratch->appendUChar(blr_leave); + dsqlScratch->appendUChar(0); } @@ -1393,25 +1373,23 @@ void ForNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - // CVC: Only put a label if this is not singular; otherwise, // what loop is the user trying to abandon? if (dsqlAction) { - stuff(statement, blr_label); - stuff(statement, (int) (IPTR) dsqlLabel->nod_arg[Dsql::e_label_number]); + dsqlScratch->appendUChar(blr_label); + dsqlScratch->appendUChar((int) (IPTR) dsqlLabel->nod_arg[Dsql::e_label_number]); } // Generate FOR loop - stuff(statement, blr_for); + dsqlScratch->appendUChar(blr_for); if (!dsqlAction || dsqlForceSingular) - stuff(statement, blr_singular); + dsqlScratch->appendUChar(blr_singular); GEN_rse(dsqlScratch, dsqlSelect); - stuff(statement, blr_begin); + dsqlScratch->appendUChar(blr_begin); // Build body of FOR loop @@ -1430,7 +1408,7 @@ for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++, ptr_to++) { - stuff(statement, blr_assignment); + dsqlScratch->appendUChar(blr_assignment); GEN_expr(dsqlScratch, *ptr); GEN_expr(dsqlScratch, *ptr_to); } @@ -1439,7 +1417,7 @@ if (dsqlAction) GEN_statement(dsqlScratch, dsqlAction); - stuff(statement, blr_end); + dsqlScratch->appendUChar(blr_end); } StmtNode* ForNode::pass1(thread_db* tdbb, CompilerScratch* csb) @@ -1549,17 +1527,15 @@ void PostEventNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - if (dsqlArgument) { - stuff(statement, blr_post_arg); + dsqlScratch->appendUChar(blr_post_arg); GEN_expr(dsqlScratch, dsqlEvent); GEN_expr(dsqlScratch, dsqlArgument); } else { - stuff(statement, blr_post); + dsqlScratch->appendUChar(blr_post); GEN_expr(dsqlScratch, dsqlEvent); } } @@ -1668,10 +1644,9 @@ void SavepointNode::genBlr() { - DsqlCompiledStatement* statement = dsqlScratch->getStatement(); - stuff(statement, blr_user_savepoint); - stuff(statement, (UCHAR) command); - stuff_cstring(statement, name.c_str()); + dsqlScratch->appendUChar(blr_user_savepoint); + dsqlScratch->appendUChar((UCHAR) command); + dsqlScratch->appendNullString(name.c_str()); } @@ -1847,7 +1822,7 @@ void SuspendNode::genBlr() { if (blockNode) - blockNode->genReturn(dsqlScratch->getStatement()); + blockNode->genReturn(dsqlScratch); } @@ -1930,15 +1905,15 @@ { DsqlCompiledStatement* const statement = dsqlScratch->getStatement(); - statement->append_uchar(blr_assignment); + dsqlScratch->appendUChar(blr_assignment); GEN_expr(dsqlScratch, value); - statement->append_uchar(blr_variable); - statement->append_ushort(0); + dsqlScratch->appendUChar(blr_variable); + dsqlScratch->appendUShort(0); - blockNode->genReturn(statement); + blockNode->genReturn(dsqlScratch); - statement->append_uchar(blr_leave); - statement->append_uchar(0); + dsqlScratch->appendUChar(blr_leave); + dsqlScratch->appendUChar(0); } Modified: firebird/trunk/src/dsql/ddl.cpp =================================================================== --- firebird/trunk/src/dsql/ddl.cpp 2010-06-16 16:28:09 UTC (rev 51258) +++ firebird/trunk/src/dsql/ddl.cpp 2010-06-17 01:18:40 UTC (rev 51259) @@ -155,6 +155,9 @@ static void fix_default_source(dsql_str* string); static void foreign_key(DsqlCompilerScratch*, dsql_nod*, const char* index_name); static void generate_dyn(DsqlCompilerScratch*, dsql_nod*); +static void generateUnnamedTriggerBeginning(BlrWriter* blrWriter, bool onUpdateTrigger, + const char* primRelName, const dsql_nod* primColumns, + const char* forRelName, const dsql_nod* forColumns); static void grant_revoke(DsqlCompilerScratch*); static void make_index(DsqlCompilerScratch*, const dsql_nod*, const dsql_nod*, const char*); static void make_index_trg_ref_int(DsqlCompilerScratch*, dsql_nod*, dsql_nod*, dsql_nod*, @@ -181,8 +184,8 @@ static void save_relation(DsqlCompilerScratch*, const dsql_str*); static void set_statistics(DsqlCompilerScratch*); static void stuff_default_blr(DsqlCompilerScratch*, const UCHAR*, USHORT); -static void stuff_matching_blr(DsqlCompiledStatement*, const dsql_nod*, const dsql_nod*); -static void stuff_trg_firing_cond(DsqlCompiledStatement*, const dsql_nod*); +static void stuff_matching_blr(BlrWriter*, const dsql_nod*, const dsql_nod*); +static void stuff_trg_firing_cond(BlrWriter*, const dsql_nod*); static void set_nod_value_attributes(dsql_nod*, const dsql_fld*); static void clearPermanentField (dsql_rel*, bool); static void define_user(DsqlCompilerScratch*, UCHAR); @@ -214,34 +217,6 @@ }; -void DsqlCompiledStatement::append_raw_string(const char* string, USHORT len) -{ - blrData.add(reinterpret_cast<const UCHAR*>(string), len); -} - -void DsqlCompiledStatement::append_raw_string(const UCHAR* string, USHORT len) -{ - blrData.add(string, len); -} - -// -// Write out a string valued attribute. (Overload 2.) -// -void DsqlCompiledStatement::append_string(UCHAR verb, const MetaName& name) -{ - append_string(verb, name.c_str(), name.length()); -} - - -// -// Write out a string valued attribute. (Overload 3.) -// -void DsqlCompiledStatement::append_string(UCHAR verb, const string& name) -{ - append_string(verb, name.c_str(), name.length()); -} - - void DDL_execute(dsql_req* request) { /************************************** @@ -264,7 +239,7 @@ if (DSQL_debug & 4) { dsql_trace("Output DYN string for DDL:"); - PRETTY_print_dyn(statement->getBlrData().begin(), gds__trace_printer, NULL, 0); + PRETTY_print_dyn(statement->getDdlData().begin(), gds__trace_printer, NULL, 0); } #endif @@ -327,9 +302,9 @@ } else { - fb_assert(statement->getBlrData().getCount() <= MAX_ULONG); + fb_assert(statement->getDdlData().getCount() <= MAX_ULONG); DYN_ddl(request->req_transaction, - statement->getBlrData().getCount(), statement->getBlrData().begin(), + statement->getDdlData().getCount(), statement->getDdlData().begin(), *statement->getSqlText()); } @@ -359,12 +334,17 @@ } if (node->nod_type != nod_class_stmtnode) - dsqlScratch->getStatement()->append_uchar(isc_dyn_version_1); + dsqlScratch->appendUChar(isc_dyn_ver... [truncated message content] |