Skip to content

Commit

Permalink
umbau exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens-G committed Nov 22, 2024
1 parent e823e7f commit f4246ea
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 120 deletions.
93 changes: 6 additions & 87 deletions compiler/cpp/src/thrift/generate/t_delphi_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1714,14 +1714,6 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream& out,
generate_delphi_property_writer_definition(out, *m_iter, false);
}

/*
if (is_x_factory) {
out << '\n';
indent(out) << "// Create Exception Object" << '\n';
indent(out) << "function CreateException: " << type_name(tstruct, true, true) << ";" << '\n';
}
*/

if (members.size() > 0) {
out << '\n';
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
Expand Down Expand Up @@ -1858,40 +1850,9 @@ void t_delphi_generator::generate_delphi_exception_definition(ostream& out,
}
out << "class(TException, IInterface, IBase, ISupportsToString)" << '\n';

/*
indent(out) << "public" << '\n';
indent_up();
indent(out) << "type" << '\n';
indent_up();
generate_delphi_struct_definition(out, tstruct, is_exception, is_result, true);
indent_down();
indent_down();
*/

indent(out) << "private" << '\n';
indent_up();
indent(out) << "FData : " << struct_intf_name << ';' << '\n';

// weg
indent(out) << "{" << '\n';

for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
indent(out) << declare_field(*m_iter, false, "F", true) << '\n';
}

if (members.size() > 0) {
indent(out) << '\n';
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
isset_name = prop_name(*m_iter, true, "F__isset_");
indent(out) << isset_name << ": System.Boolean;" << '\n';
}
}
}

// weg
indent(out) << "}" << '\n';

indent(out) << '\n';

for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
Expand Down Expand Up @@ -1935,19 +1896,14 @@ void t_delphi_generator::generate_delphi_exception_definition(ostream& out,
indent(out) << "destructor Destroy; override;" << '\n';

out << '\n';
indent(out) << "property ExceptionData : " << struct_intf_name << " read FData;" << '\n';
indent(out) << "function ToString: string; override;" << '\n';

out << '\n';
indent(out) << "// IBase" << '\n';
indent(out) << "procedure Read( const iprot: IProtocol);" << '\n';
indent(out) << "procedure Write( const oprot: IProtocol);" << '\n';

/*
out << '\n';
indent(out) << "// Create Exception Object" << '\n';
indent(out) << "function CreateException: " << type_name(tstruct, true, true) << ";" << '\n';
*/

if (members.size() > 0) {
out << '\n';
indent(out) << "// Properties" << '\n';
Expand Down Expand Up @@ -2641,7 +2597,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi
indent_up_impl();
if (!tfunction->is_oneway()) {
string factory_name = normalize_clsnm((*x_iter)->get_type()->get_name(), "", true) + "Factory";
indent_impl(s_service_impl) << "ret." << prop_name(*x_iter) << " := E." << factory_name << ";"
indent_impl(s_service_impl) << "ret." << prop_name(*x_iter) << " := E.ExceptionData;"
<< '\n';
}
indent_down_impl();
Expand Down Expand Up @@ -3563,8 +3519,7 @@ void t_delphi_generator::generate_delphi_clear_union_value(ostream& out,
t_type* ftype = tfield->get_type();
bool is_xception = ftype->is_xception();

indent_impl(out) << "if " << prop_name(tfield, is_xception_class,"F__isset_") << " then begin"
<< '\n';
indent_impl(out) << "if " << prop_name(tfield, is_xception_class,"F__isset_") << " then begin" << '\n';
indent_up_impl();
indent_impl(out) << prop_name(tfield, is_xception_class,"F__isset_") << " := False;" << '\n';
indent_impl(out) << prop_name(tfield, is_xception_class,fieldPrefix) << " := "
Expand All @@ -3591,7 +3546,7 @@ void t_delphi_generator::generate_delphi_property_writer_impl(ostream& out,

indent_impl(out) << "procedure " << cls_prefix << name << "."
<< prop_name(tfield, is_xception_class,"Set")
<< "( const Value: " << type_name(ftype, false, true, is_xception, true) << ");"
<< "( const Value: " << type_name(ftype, false, true, false, false) << ");"
<< '\n';
indent_impl(out) << "begin" << '\n';
indent_up_impl();
Expand Down Expand Up @@ -3625,7 +3580,7 @@ void t_delphi_generator::generate_delphi_property_reader_impl(ostream& out,

indent_impl(out) << "function " << cls_prefix << name << "."
<< prop_name(tfield, is_xception_class,"Get") << ": "
<< type_name(ftype, false, true, is_xception, true) << ";" << '\n';
<< type_name(ftype, false, true, false, false) << ";" << '\n';
indent_impl(out) << "begin" << '\n';
indent_up_impl();
if(is_xception_class) {
Expand Down Expand Up @@ -3681,41 +3636,6 @@ void t_delphi_generator::generate_delphi_create_exception_impl(ostream& out,

string exception_cls_nm = type_name(tstruct, true, true);
string cls_nm = type_name(tstruct, true, false, is_exception, is_exception);

/*
indent_impl(out) << "function " << cls_nm << ".CreateException: " << exception_cls_nm << ";"
<< '\n';
indent_impl(out) << "begin" << '\n';
indent_up_impl();
indent_impl(out) << "Result := " << exception_cls_nm << ".Create;" << '\n';
string factory_name = normalize_clsnm(tstruct->get_name(), "", true) + "Factory";
indent_impl(out) << "Result.F" << factory_name << " := Self;" << '\n';
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
string propname;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
propname = prop_name(*f_iter, is_exception);
if ((*f_iter)->get_req() != t_field::T_REQUIRED) {
indent_impl(out) << "if " << prop_name(*f_iter, is_exception,"__isset_") << " then begin" << '\n';
indent_up_impl();
}
indent_impl(out) << "Result." << propname << " := " << propname << ";" << '\n';
if ((*f_iter)->get_req() != t_field::T_REQUIRED) {
indent_down_impl();
indent_impl(out) << "end;" << '\n';
}
}
indent_impl(out) << "Result.UpdateMessageProperty;" << '\n';
indent_down_impl();
indent_impl(out) << "end;" << '\n' << '\n';
*/
}

void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out,
Expand Down Expand Up @@ -3853,8 +3773,7 @@ void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out,

cls_nm = type_name(tstruct, true, is_exception && (!is_x_factory), is_x_factory, is_x_factory);

indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( const iprot: IProtocol);"
<< '\n';
indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( const iprot: IProtocol);" << '\n';
indent_impl(out) << "var" << '\n';
indent_up_impl();
indent_impl(out) << "field_ : TThriftField;" << '\n';
Expand Down
4 changes: 2 additions & 2 deletions lib/delphi/test/serializer/SerializerData.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ uses
Thrift.Stream in '..\..\src\Thrift.Stream.pas',
Thrift.WinHTTP in '..\..\src\Thrift.WinHTTP.pas',
Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
Exceptions in 'gen-delphi\Exceptions.pas',
System_ in 'gen-delphi\System_.pas',
SysUtils_ in 'gen-delphi\SysUtils_.pas',
test.ExceptionStruct in 'gen-delphi\test.ExceptionStruct.pas',
test.SimpleException in 'gen-delphi\test.SimpleException.pas',
DebugProtoTest in 'gen-delphi\DebugProtoTest.pas',
TestSerializer.Data in 'TestSerializer.Data.pas';

Expand Down Expand Up @@ -88,7 +88,7 @@ exports
CreateNesting,
CreateHolyMoley,
CreateCompactProtoTestStruct,
CreateBatchGetResponse;
CreateBatchGetResponse,
CreateSimpleException;


Expand Down
7 changes: 5 additions & 2 deletions lib/delphi/test/serializer/SerializerData.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
<DCCReference Include="..\..\src\Thrift.Stream.pas"/>
<DCCReference Include="..\..\src\Thrift.WinHTTP.pas"/>
<DCCReference Include="..\..\src\Thrift.TypeRegistry.pas"/>
<DCCReference Include="gen-delphi\Exceptions.pas"/>
<DCCReference Include="gen-delphi\System_.pas"/>
<DCCReference Include="gen-delphi\SysUtils_.pas"/>
<DCCReference Include="gen-delphi\test.ExceptionStruct.pas"/>
<DCCReference Include="gen-delphi\test.SimpleException.pas"/>
<DCCReference Include="gen-delphi\DebugProtoTest.pas"/>
<DCCReference Include="TestSerializer.Data.pas"/>
<BuildConfiguration Include="Release">
Expand All @@ -89,7 +89,7 @@
<PreBuildEvent><![CDATA[thrift.exe -r -gen delphi:com_types,rtti ..\keywords\ReservedKeywords.thrift
thrift.exe -r -gen delphi:com_types ..\..\..\..\test\DebugProtoTest.thrift
thrift.exe -r -gen delphi:com_types ..\..\..\..\test\ExceptionStruct.thrift
thrift.exe -r -gen delphi:com_types Exceptions.thrift]]></PreBuildEvent>
thrift.exe -r -gen delphi:com_types SimpleException.thrift]]></PreBuildEvent>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
Expand Down Expand Up @@ -126,6 +126,9 @@ thrift.exe -r -gen delphi:com_types Exceptions.thrift]]></PreBuildEvent>
<Source>
<Source Name="MainSource">SerializerData.dpr</Source>
</Source>
<Parameters>
<Parameters Name="HostApplication">bin\Debug\Win32\TestSerializer.exe</Parameters>
</Parameters>
</Delphi.Personality>
<Platforms>
<Platform value="Win32">True</Platform>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

namespace * test.SimpleException

exception Error {
1: i32 ErrorCode
2: Error InnerException
Expand Down
6 changes: 3 additions & 3 deletions lib/delphi/test/serializer/TestSerializer.Data.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface
Thrift.Protocol,
Thrift.Collections,
test.ExceptionStruct,
Exceptions,
test.SimpleException,
DebugProtoTest;


Expand Down Expand Up @@ -374,7 +374,7 @@ class function Fixtures.CreateBatchGetResponse : IBatchGetResponse;
data.Id := REQUEST_ID;
data.Data := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8));

error := TSomeException.Create;
error := TSomeExceptionImpl.Create;
error.Error := TErrorCode.GenericError;

result := TBatchGetResponseImpl.Create;
Expand All @@ -394,7 +394,7 @@ class function Fixtures.CreateSimpleException : IError;
inner := result;
result := TErrorImpl.Create;
result.ErrorCode := i;
result.InnerException_ := inner;
result.InnerException := inner;
end;
end;

Expand Down
35 changes: 12 additions & 23 deletions lib/delphi/test/serializer/TestSerializer.Tests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface
Thrift.TypeRegistry,
System_,
test.ExceptionStruct,
Exceptions,
test.SimpleException,
DebugProtoTest;

{$TYPEINFO ON}
Expand Down Expand Up @@ -346,7 +346,7 @@ procedure TTestSerializer.Test_SimpleException( const method : TMethod; const fa
end;

// init + read
correct := TBatchGetResponseImpl.Create;
correct := TErrorImpl.Create;
case method of
mt_Bytes: Deserialize( bytes, tested, factory);
mt_Stream: begin
Expand All @@ -358,27 +358,15 @@ procedure TTestSerializer.Test_SimpleException( const method : TMethod; const fa
end;

// check
correct := CreateBatchGetResponse;

// rewrite the following test if not
ASSERT( tested.Responses.Count = 1);
ASSERT( correct.Responses.Count = tested.Responses.Count);
for corrDP in correct.Responses do begin
for testDP in tested.Responses do begin
ASSERT( corrDP.Key = testDP.Key);
ASSERT( corrDP.Value.Id = testDP.Value.Id);
ASSERT( corrDP.Value.Data.Count = testDP.Value.Data.Count);
end;
end;

// rewrite the following test if not
ASSERT( tested.Errors.Count = 1);
ASSERT( correct.Errors.Count = tested.Errors.Count);
for corrEP in correct.Errors do begin
for testEP in tested.Errors do begin
ASSERT( corrEP.Key = testEP.Key);
ASSERT( corrEP.Value.Error = testEP.Value.Error);
end;
correct := CreateSimpleException;
while correct <> nil do begin
// validate
ASSERT( correct.ErrorCode = tested.ErrorCode);

// iterate
correct := correct.InnerException;
tested := tested.InnerException;
ASSERT( (tested <> nil) xor (correct = nil)); // both or none
end;
end;

Expand All @@ -399,6 +387,7 @@ procedure TTestSerializer.Test_Serializer_Deserializer;
Test_OneOfEach( method, factory, stream);
Test_CompactStruct( method, factory, stream);
Test_ExceptionStruct( method, factory, stream);
Test_SimpleException( method, factory, stream);
end;

Writeln;
Expand Down
2 changes: 1 addition & 1 deletion lib/delphi/test/serializer/TestSerializer.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ uses
System_ in 'gen-delphi\System_.pas',
SysUtils_ in 'gen-delphi\SysUtils_.pas',
DebugProtoTest in 'gen-delphi\DebugProtoTest.pas',
Exceptions in 'gen-delphi\Exceptions.pas',
test.ExceptionStruct in 'gen-delphi\test.ExceptionStruct.pas',
test.SimpleException in 'gen-delphi\test.SimpleException.pas',
TestSerializer.Tests in 'TestSerializer.Tests.pas';


Expand Down
4 changes: 2 additions & 2 deletions lib/delphi/test/serializer/TestSerializer.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
<DCCReference Include="gen-delphi\System_.pas"/>
<DCCReference Include="gen-delphi\SysUtils_.pas"/>
<DCCReference Include="gen-delphi\DebugProtoTest.pas"/>
<DCCReference Include="gen-delphi\Exceptions.pas"/>
<DCCReference Include="gen-delphi\test.ExceptionStruct.pas"/>
<DCCReference Include="gen-delphi\test.SimpleException.pas"/>
<DCCReference Include="TestSerializer.Tests.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
Expand All @@ -88,7 +88,7 @@
<PreBuildEvent><![CDATA[thrift.exe -r -gen delphi:com_types,rtti ..\keywords\ReservedKeywords.thrift
thrift.exe -r -gen delphi:com_types ..\..\..\..\test\DebugProtoTest.thrift
thrift.exe -r -gen delphi:com_types ..\..\..\..\test\ExceptionStruct.thrift
thrift.exe -r -gen delphi:com_types Exceptions.thrift]]></PreBuildEvent>
thrift.exe -r -gen delphi:com_types SimpleException.thrift]]></PreBuildEvent>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
Expand Down

0 comments on commit f4246ea

Please sign in to comment.