THRIFT-4554 uncompileable code with member names that are also types under specific conditions
Client: Delphi
Patch: Jens Geyer

This closes #1539
diff --git a/.gitignore b/.gitignore
index 9f1a629..be07a4e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -191,35 +191,12 @@
 /lib/dart/**/packages
 /lib/dart/**/.pub/
 /lib/dart/**/pubspec.lock
-/lib/delphi/src/*.dcu
-/lib/delphi/test/*.identcache
-/lib/delphi/test/*.local
-/lib/delphi/test/*.dcu
-/lib/delphi/test/*.2007
-/lib/delphi/test/*.dproj
-/lib/delphi/test/*.dproj
-/lib/delphi/test/codegen/*.bat
-/lib/delphi/test/skip/*.local
-/lib/delphi/test/skip/*.identcache
-/lib/delphi/test/skip/*.identcache
-/lib/delphi/test/skip/*.dproj
-/lib/delphi/test/skip/*.dproj
-/lib/delphi/test/skip/*.2007
-/lib/delphi/test/serializer/*.identcache
-/lib/delphi/test/serializer/*.dproj
-/lib/delphi/test/serializer/*.local
-/lib/delphi/test/serializer/*.2007
-/lib/delphi/test/serializer/*.dcu
-/lib/delphi/test/multiplexed/*.dproj
-/lib/delphi/test/multiplexed/*.2007
-/lib/delphi/test/multiplexed/*.local
-/lib/delphi/test/multiplexed/*.identcache
-/lib/delphi/test/multiplexed/*.dcu
-/lib/delphi/test/typeregistry/*.2007
-/lib/delphi/test/typeregistry/*.dproj
-/lib/delphi/test/typeregistry/*.identcache
-/lib/delphi/test/typeregistry/*.local
-/lib/delphi/test/typeregistry/*.dcu
+/lib/delphi/**/*.identcache
+/lib/delphi/**/*.local
+/lib/delphi/**/*.dcu
+/lib/delphi/**/*.2007
+/lib/delphi/**/*.dproj
+/lib/delphi/**/codegen/*.bat
 /lib/erl/.eunit
 /lib/erl/.generated
 /lib/erl/.rebar/
@@ -367,15 +344,12 @@
 /tutorial/dart/**/packages
 /tutorial/dart/**/.pub/
 /tutorial/dart/**/pubspec.lock
-/tutorial/delphi/*.dsk
-/tutorial/delphi/*.local
-/tutorial/delphi/*.tvsconfig
-/tutorial/delphi/DelphiClient/dcu
-/tutorial/delphi/DelphiServer/dcu
-/tutorial/delphi/DelphiClient/*.local
-/tutorial/delphi/DelphiClient/*.identcache
-/tutorial/delphi/DelphiServer/*.identcache
-/tutorial/delphi/DelphiServer/*.local
+/tutorial/delphi/**/*.dsk
+/tutorial/delphi/**/*.local
+/tutorial/delphi/**/*.tvsconfig
+/tutorial/delphi/**/dcu
+/tutorial/delphi/**/*.local
+/tutorial/delphi/**/*.identcache
 /tutorial/go/gopath
 /tutorial/go/go-tutorial
 /tutorial/go/calculator-remote
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 4db1cf7..c7f2f41 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -642,10 +642,21 @@
 
   // reserved/predefined variables and types (lowercase!)
   delphi_keywords["result"] = 1;
+  delphi_keywords["system"] = 1;
+  delphi_keywords["sysutils"] = 1;
+  delphi_keywords["thrift"] = 1;
   delphi_keywords["tbytes"] = 1;
   delphi_keywords["tobject"] = 1;
   delphi_keywords["tclass"] = 1;
   delphi_keywords["tinterfacedobject"] = 1;
+  delphi_keywords["ansistring"] = 1;
+  delphi_keywords["string"] = 1;
+  delphi_keywords["boolean"] = 1;
+  delphi_keywords["shortint"] = 1;
+  delphi_keywords["smallint"] = 1;
+  delphi_keywords["integer"] = 1;
+  delphi_keywords["int64"] = 1;
+  delphi_keywords["double"] = 1;
 
   delphi_reserved_method["create"] = 1;
   delphi_reserved_method["free"] = 1;
@@ -752,7 +763,7 @@
     unitname = includes[i]->get_name();
     nsname = includes[i]->get_namespace("delphi");
     if ("" != nsname) {
-      unitname = nsname;
+      unitname = normalize_name(nsname);
     }
     add_delphi_uses_list(unitname);
   }
@@ -772,6 +783,8 @@
     }
   }
 
+  unitname = normalize_name(unitname);
+  
   std::string f_name = get_out_dir() + "/" + unitname + ".pas";
   std::ofstream f_all;
 
@@ -1702,7 +1715,7 @@
       for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
         if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
           isset_name = "__isset_" + prop_name(*m_iter, is_exception);
-          indent(out) << "property " << isset_name << ": Boolean read Get" << isset_name << ";"
+          indent(out) << "property " << isset_name << ": System.Boolean read Get" << isset_name << ";"
                       << endl;
         }
       }
@@ -1751,7 +1764,7 @@
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
         isset_name = "F__isset_" + prop_name(*m_iter, is_exception);
-        indent(out) << isset_name << ": Boolean;" << endl;
+        indent(out) << isset_name << ": System.Boolean;" << endl;
       }
     }
   }
@@ -1774,7 +1787,7 @@
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
         isset_name = "__isset_" + prop_name(*m_iter, is_exception);
-        indent(out) << "function Get" << isset_name << ": Boolean;" << endl;
+        indent(out) << "function Get" << isset_name << ": System.Boolean;" << endl;
       }
     }
   }
@@ -1831,7 +1844,7 @@
     for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
       if ((*m_iter)->get_req() != t_field::T_REQUIRED) {
         isset_name = "__isset_" + prop_name(*m_iter, is_exception);
-        indent(out) << "property " << isset_name << ": Boolean read Get" << isset_name << ";"
+        indent(out) << "property " << isset_name << ": System.Boolean read Get" << isset_name << ";"
                     << endl;
       }
     }
@@ -1959,7 +1972,7 @@
     indent_up();
     indent(s_service) << "iprot_: IProtocol;" << endl;
     indent(s_service) << "oprot_: IProtocol;" << endl;
-    indent(s_service) << "seqid_: Integer;" << endl;
+    indent(s_service) << "seqid_: System.Integer;" << endl;
     indent_down();
 
     indent(s_service) << "public" << endl;
@@ -2020,7 +2033,7 @@
       if( for_async) {
         if (is_void(ttype)) {
            // Delphi forces us to specify a type with IFuture<T>, so we use Integer=0 for void methods
-          indent_impl(s_service_impl) << "result := TTask.Future<Integer>(function: Integer" << endl;
+          indent_impl(s_service_impl) << "result := TTask.Future<System.Integer>(function: System.Integer" << endl;
         } else {
           string rettype = type_name(ttype, false, true, false, true);
           indent_impl(s_service_impl) << "result := TTask.Future<" << rettype << ">(function: " << rettype << endl;
@@ -2262,7 +2275,7 @@
     indent_up();
     indent(s_service) << "type" << endl;
     indent_up();
-    indent(s_service) << "TProcessFunction = reference to procedure( seqid: Integer; const iprot: "
+    indent(s_service) << "TProcessFunction = reference to procedure( seqid: System.Integer; const iprot: "
                          "IProtocol; const oprot: IProtocol"
                       << (events_ ? "; const events : IRequestEvents" : "") << ");" << endl;
     indent_down();
@@ -2277,15 +2290,15 @@
   indent_up();
   if (extends.empty()) {
     indent(s_service) << "function Process( const iprot: IProtocol; const oprot: IProtocol; const "
-                         "events : IProcessorEvents): Boolean;" << endl;
+                         "events : IProcessorEvents): System.Boolean;" << endl;
   } else {
     indent(s_service) << "function Process( const iprot: IProtocol; const oprot: IProtocol; const "
-                         "events : IProcessorEvents): Boolean; reintroduce;" << endl;
+                         "events : IProcessorEvents): System.Boolean; reintroduce;" << endl;
   }
 
   indent_impl(s_service_impl) << "function " << full_cls << ".Process( const iprot: IProtocol; "
                                                             "const oprot: IProtocol; const events "
-                                                            ": IProcessorEvents): Boolean;" << endl;
+                                                            ": IProcessorEvents): System.Boolean;" << endl;
   ;
   indent_impl(s_service_impl) << "var" << endl;
   indent_up_impl();
@@ -2411,7 +2424,7 @@
   string result_intfnm = normalize_clsnm(org_resultname, "I");
 
   indent(s_service) << "procedure " << funcname
-                    << "_Process( seqid: Integer; const iprot: IProtocol; const oprot: IProtocol"
+                    << "_Process( seqid: System.Integer; const iprot: IProtocol; const oprot: IProtocol"
                     << (events_ ? "; const events : IRequestEvents" : "") << ");" << endl;
 
   if (tfunction->is_oneway()) {
@@ -2422,7 +2435,7 @@
 
   indent_impl(s_service_impl)
       << "procedure " << full_cls << "." << funcname
-      << "_Process( seqid: Integer; const iprot: IProtocol; const oprot: IProtocol"
+      << "_Process( seqid: System.Integer; const iprot: IProtocol; const oprot: IProtocol"
       << (events_ ? "; const events : IRequestEvents" : "") << ");" << endl;
   indent_impl(s_service_impl) << "var" << endl;
   indent_up_impl();
@@ -2682,7 +2695,7 @@
   }
   local_vars << "  " << local_var << endl;
   counter = tmp("_i");
-  local_var = counter + ": Integer;";
+  local_var = counter + ": System.Integer;";
   local_vars << "  " << local_var << endl;
 
   indent_impl(out) << name << " := " << type_name(ttype, true) << ".Create;" << endl;
@@ -2830,7 +2843,7 @@
         throw "compiler error: no Delphi name for base type " + t_base_type::t_base_name(tbase);
       }
     } else if (type->is_enum()) {
-      out << "WriteI32(Integer(" << name << "));";
+      out << "WriteI32(System.Integer(" << name << "));";
     }
     out << endl;
   } else {
@@ -3141,25 +3154,25 @@
   case t_base_type::TYPE_STRING:
     if (tbase->is_binary()) {
       if (ansistr_binary_) {
-        return "AnsiString";
+        return "System.AnsiString";
       } else {
-        return "TBytes";
+        return "SysUtils.TBytes";
       }
     } else {
-      return "string";
+      return "System.string";
     }
   case t_base_type::TYPE_BOOL:
-    return "Boolean";
+    return "System.Boolean";
   case t_base_type::TYPE_I8:
-    return "ShortInt";
+    return "System.ShortInt";
   case t_base_type::TYPE_I16:
-    return "SmallInt";
+    return "System.SmallInt";
   case t_base_type::TYPE_I32:
-    return "Integer";
+    return "System.Integer";
   case t_base_type::TYPE_I64:
-    return "Int64";
+    return "System.Int64";
   case t_base_type::TYPE_DOUBLE:
-    return "Double";
+    return "System.Double";
   default:
     throw "compiler error: no Delphi name for base type "
         + t_base_type::t_base_name(tbase->get_base());
@@ -3394,7 +3407,7 @@
 void t_delphi_generator::generate_delphi_isset_reader_definition(ostream& out,
                                                                  t_field* tfield,
                                                                  bool is_xception) {
-  indent(out) << "function Get__isset_" << prop_name(tfield, is_xception) << ": Boolean;" << endl;
+  indent(out) << "function Get__isset_" << prop_name(tfield, is_xception) << ": System.Boolean;" << endl;
 }
 
 void t_delphi_generator::generate_delphi_clear_union_value(ostream& out,
@@ -3500,7 +3513,7 @@
 
   string isset_name = "__isset_" + prop_name(tfield, is_xception);
   indent_impl(out) << "function " << cls_prefix << name << "."
-                   << "Get" << isset_name << ": Boolean;" << endl;
+                   << "Get" << isset_name << ": System.Boolean;" << endl;
   indent_impl(out) << "begin" << endl;
   indent_up_impl();
   indent_impl(out) << "Result := " << fieldPrefix << isset_name << ";" << endl;
@@ -3572,7 +3585,7 @@
   // local bools for required fields
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
-      indent_impl(local_vars) << "_req_isset_" << prop_name(*f_iter, is_exception) << " : Boolean;"
+      indent_impl(local_vars) << "_req_isset_" << prop_name(*f_iter, is_exception) << " : System.Boolean;"
                               << endl;
       indent_impl(code_block) << "_req_isset_" << prop_name(*f_iter, is_exception) << " := FALSE;"
                               << endl;
@@ -3870,7 +3883,7 @@
   for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
     bool is_optional = ((*f_iter)->get_req() != t_field::T_REQUIRED);
     if (is_optional) {
-      indent_impl(out) << tmp_first << " : Boolean;" << endl;
+      indent_impl(out) << tmp_first << " : System.Boolean;" << endl;
       useFirstFlag = true;
     }
     break;
@@ -3929,7 +3942,7 @@
                        << ".Append('<null>') else " << tmp_sb << ".Append( Self."
                        << prop_name((*f_iter), is_exception) << ".ToString());" << endl;
     } else if (ttype->is_enum()) {
-      indent_impl(out) << tmp_sb << ".Append(Integer( Self." << prop_name((*f_iter), is_exception)
+      indent_impl(out) << tmp_sb << ".Append(System.Integer( Self." << prop_name((*f_iter), is_exception)
                        << "));" << endl;
     } else {
       indent_impl(out) << tmp_sb << ".Append( Self." << prop_name((*f_iter), is_exception) << ");"
diff --git a/lib/delphi/DelphiThrift.groupproj b/lib/delphi/DelphiThrift.groupproj
new file mode 100644
index 0000000..a172e49
--- /dev/null
+++ b/lib/delphi/DelphiThrift.groupproj
@@ -0,0 +1,156 @@
+	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+		<PropertyGroup>
+			<ProjectGuid>{6BD327A5-7688-4263-B6A8-B15207CF4EC5}</ProjectGuid>
+		</PropertyGroup>
+		<ItemGroup>
+			<Projects Include="test\client.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\server.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\multiplexed\Multiplex.Test.Client.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\multiplexed\Multiplex.Test.Server.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\serializer\TestSerializer.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\skip\skiptest_version1.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\skip\skiptest_version2.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\typeregistry\TestTypeRegistry.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="..\..\tutorial\delphi\DelphiServer\DelphiServer.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="..\..\tutorial\delphi\DelphiClient\DelphiClient.dproj">
+				<Dependencies/>
+			</Projects>
+			<Projects Include="test\keywords\ReservedKeywords.dproj">
+				<Dependencies/>
+			</Projects>
+		</ItemGroup>
+		<ProjectExtensions>
+			<Borland.Personality>Default.Personality.12</Borland.Personality>
+			<Borland.ProjectType/>
+			<BorlandProject>
+				<Default.Personality/>
+			</BorlandProject>
+		</ProjectExtensions>
+		<Target Name="client">
+			<MSBuild Projects="test\client.dproj"/>
+		</Target>
+		<Target Name="client:Clean">
+			<MSBuild Projects="test\client.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="client:Make">
+			<MSBuild Projects="test\client.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="server">
+			<MSBuild Projects="test\server.dproj"/>
+		</Target>
+		<Target Name="server:Clean">
+			<MSBuild Projects="test\server.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="server:Make">
+			<MSBuild Projects="test\server.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="Multiplex_Test_Client">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Client.dproj"/>
+		</Target>
+		<Target Name="Multiplex_Test_Client:Clean">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Client.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="Multiplex_Test_Client:Make">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Client.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="Multiplex_Test_Server">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Server.dproj"/>
+		</Target>
+		<Target Name="Multiplex_Test_Server:Clean">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Server.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="Multiplex_Test_Server:Make">
+			<MSBuild Projects="test\multiplexed\Multiplex.Test.Server.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="TestSerializer">
+			<MSBuild Projects="test\serializer\TestSerializer.dproj"/>
+		</Target>
+		<Target Name="TestSerializer:Clean">
+			<MSBuild Projects="test\serializer\TestSerializer.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="TestSerializer:Make">
+			<MSBuild Projects="test\serializer\TestSerializer.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="skiptest_version1">
+			<MSBuild Projects="test\skip\skiptest_version1.dproj"/>
+		</Target>
+		<Target Name="skiptest_version1:Clean">
+			<MSBuild Projects="test\skip\skiptest_version1.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="skiptest_version1:Make">
+			<MSBuild Projects="test\skip\skiptest_version1.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="skiptest_version2">
+			<MSBuild Projects="test\skip\skiptest_version2.dproj"/>
+		</Target>
+		<Target Name="skiptest_version2:Clean">
+			<MSBuild Projects="test\skip\skiptest_version2.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="skiptest_version2:Make">
+			<MSBuild Projects="test\skip\skiptest_version2.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="TestTypeRegistry">
+			<MSBuild Projects="test\typeregistry\TestTypeRegistry.dproj"/>
+		</Target>
+		<Target Name="TestTypeRegistry:Clean">
+			<MSBuild Projects="test\typeregistry\TestTypeRegistry.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="TestTypeRegistry:Make">
+			<MSBuild Projects="test\typeregistry\TestTypeRegistry.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="DelphiServer">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiServer\DelphiServer.dproj"/>
+		</Target>
+		<Target Name="DelphiServer:Clean">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiServer\DelphiServer.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="DelphiServer:Make">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiServer\DelphiServer.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="DelphiClient">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiClient\DelphiClient.dproj"/>
+		</Target>
+		<Target Name="DelphiClient:Clean">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiClient\DelphiClient.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="DelphiClient:Make">
+			<MSBuild Projects="..\..\tutorial\delphi\DelphiClient\DelphiClient.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="ReservedKeywords">
+			<MSBuild Projects="test\keywords\ReservedKeywords.dproj"/>
+		</Target>
+		<Target Name="ReservedKeywords:Clean">
+			<MSBuild Projects="test\keywords\ReservedKeywords.dproj" Targets="Clean"/>
+		</Target>
+		<Target Name="ReservedKeywords:Make">
+			<MSBuild Projects="test\keywords\ReservedKeywords.dproj" Targets="Make"/>
+		</Target>
+		<Target Name="Build">
+			<CallTarget Targets="client;server;Multiplex_Test_Client;Multiplex_Test_Server;TestSerializer;skiptest_version1;skiptest_version2;TestTypeRegistry;DelphiServer;DelphiClient;ReservedKeywords"/>
+		</Target>
+		<Target Name="Clean">
+			<CallTarget Targets="client:Clean;server:Clean;Multiplex_Test_Client:Clean;Multiplex_Test_Server:Clean;TestSerializer:Clean;skiptest_version1:Clean;skiptest_version2:Clean;TestTypeRegistry:Clean;DelphiServer:Clean;DelphiClient:Clean;ReservedKeywords:Clean"/>
+		</Target>
+		<Target Name="Make">
+			<CallTarget Targets="client:Make;server:Make;Multiplex_Test_Client:Make;Multiplex_Test_Server:Make;TestSerializer:Make;skiptest_version1:Make;skiptest_version2:Make;TestTypeRegistry:Make;DelphiServer:Make;DelphiClient:Make;ReservedKeywords:Make"/>
+		</Target>
+		<Import Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')" Project="$(BDS)\Bin\CodeGear.Group.Targets"/>
+	</Project>
diff --git a/lib/delphi/test/keywords/ReservedIncluded.thrift b/lib/delphi/test/keywords/ReservedIncluded.thrift
new file mode 100644
index 0000000..8b47a50
--- /dev/null
+++ b/lib/delphi/test/keywords/ReservedIncluded.thrift
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// make sure generated code does not produce name collisions with predefined keywords
+namespace delphi SysUtils
+
+const i32 integer = 42
+
+// EOF
diff --git a/lib/delphi/test/keywords/ReservedKeywords.dpr b/lib/delphi/test/keywords/ReservedKeywords.dpr
new file mode 100644
index 0000000..1fbc8c1
--- /dev/null
+++ b/lib/delphi/test/keywords/ReservedKeywords.dpr
@@ -0,0 +1,15 @@
+program ReservedKeywords;
+
+{$APPTYPE CONSOLE}
+
+uses
+  SysUtils, System_;
+
+begin
+  try
+    { TODO -oUser -cConsole Main : Code hier einfügen }
+  except
+    on E: Exception do
+      Writeln(E.ClassName, ': ', E.Message);
+  end;
+end.
diff --git a/lib/delphi/test/keywords/ReservedKeywords.dproj b/lib/delphi/test/keywords/ReservedKeywords.dproj
new file mode 100644
index 0000000..6bd9544
--- /dev/null
+++ b/lib/delphi/test/keywords/ReservedKeywords.dproj
@@ -0,0 +1,112 @@
+	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+		<PropertyGroup>
+			<ProjectGuid>{F2E9B6FC-A931-4271-8E30-5A4E402481B4}</ProjectGuid>
+			<MainSource>ReservedKeywords.dpr</MainSource>
+			<ProjectVersion>12.3</ProjectVersion>
+			<Basis>True</Basis>
+			<Config Condition="'$(Config)'==''">Debug</Config>
+			<Platform>Win32</Platform>
+			<AppType>Console</AppType>
+			<FrameworkType>None</FrameworkType>
+			<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''">
+			<Base>true</Base>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
+			<Cfg_1>true</Cfg_1>
+			<CfgParent>Base</CfgParent>
+			<Base>true</Base>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
+			<Cfg_2>true</Cfg_2>
+			<CfgParent>Base</CfgParent>
+			<Base>true</Base>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Base)'!=''">
+			<DCC_ImageBase>00400000</DCC_ImageBase>
+			<DCC_DcuOutput>.\$(Config)\$(Platform)</DCC_DcuOutput>
+			<DCC_UnitSearchPath>gen-delphi;..\..\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
+			<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias>
+			<DCC_ExeOutput>.\$(Config)\$(Platform)</DCC_ExeOutput>
+			<DCC_N>false</DCC_N>
+			<DCC_S>false</DCC_S>
+			<DCC_K>false</DCC_K>
+			<DCC_E>false</DCC_E>
+			<DCC_F>false</DCC_F>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Cfg_1)'!=''">
+			<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
+			<DCC_Optimize>false</DCC_Optimize>
+			<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
+		</PropertyGroup>
+		<PropertyGroup Condition="'$(Cfg_2)'!=''">
+			<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
+			<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
+			<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
+			<DCC_DebugInformation>false</DCC_DebugInformation>
+		</PropertyGroup>
+		<ItemGroup>
+			<DelphiCompile Include="ReservedKeywords.dpr">
+				<MainSource>MainSource</MainSource>
+			</DelphiCompile>
+			<BuildConfiguration Include="Release">
+				<Key>Cfg_2</Key>
+				<CfgParent>Base</CfgParent>
+			</BuildConfiguration>
+			<BuildConfiguration Include="Basis">
+				<Key>Base</Key>
+			</BuildConfiguration>
+			<BuildConfiguration Include="Debug">
+				<Key>Cfg_1</Key>
+				<CfgParent>Base</CfgParent>
+			</BuildConfiguration>
+		</ItemGroup>
+		<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
+		<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
+		<PropertyGroup>
+			<PreBuildEvent><![CDATA[thrift -r  -gen delphi ReservedKeywords.thrift]]></PreBuildEvent>
+		</PropertyGroup>
+		<ProjectExtensions>
+			<Borland.Personality>Delphi.Personality.12</Borland.Personality>
+			<Borland.ProjectType/>
+			<BorlandProject>
+				<Delphi.Personality>
+					<VersionInfo>
+						<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
+						<VersionInfo Name="AutoIncBuild">False</VersionInfo>
+						<VersionInfo Name="MajorVer">1</VersionInfo>
+						<VersionInfo Name="MinorVer">0</VersionInfo>
+						<VersionInfo Name="Release">0</VersionInfo>
+						<VersionInfo Name="Build">0</VersionInfo>
+						<VersionInfo Name="Debug">False</VersionInfo>
+						<VersionInfo Name="PreRelease">False</VersionInfo>
+						<VersionInfo Name="Special">False</VersionInfo>
+						<VersionInfo Name="Private">False</VersionInfo>
+						<VersionInfo Name="DLL">False</VersionInfo>
+						<VersionInfo Name="Locale">1031</VersionInfo>
+						<VersionInfo Name="CodePage">1252</VersionInfo>
+					</VersionInfo>
+					<VersionInfoKeys>
+						<VersionInfoKeys Name="CompanyName"/>
+						<VersionInfoKeys Name="FileDescription"/>
+						<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
+						<VersionInfoKeys Name="InternalName"/>
+						<VersionInfoKeys Name="LegalCopyright"/>
+						<VersionInfoKeys Name="LegalTrademarks"/>
+						<VersionInfoKeys Name="OriginalFilename"/>
+						<VersionInfoKeys Name="ProductName"/>
+						<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
+						<VersionInfoKeys Name="Comments"/>
+					</VersionInfoKeys>
+					<Source>
+						<Source Name="MainSource">ReservedKeywords.dpr</Source>
+					</Source>
+				</Delphi.Personality>
+				<Platforms>
+					<Platform value="Win32">True</Platform>
+				</Platforms>
+			</BorlandProject>
+			<ProjectFileVersion>12</ProjectFileVersion>
+		</ProjectExtensions>
+	</Project>
diff --git a/lib/delphi/test/codegen/ReservedKeywords.thrift b/lib/delphi/test/keywords/ReservedKeywords.thrift
similarity index 75%
rename from lib/delphi/test/codegen/ReservedKeywords.thrift
rename to lib/delphi/test/keywords/ReservedKeywords.thrift
index 8db3ea5..2f49d74 100644
--- a/lib/delphi/test/codegen/ReservedKeywords.thrift
+++ b/lib/delphi/test/keywords/ReservedKeywords.thrift
@@ -18,7 +18,9 @@
  */
 
 // make sure generated code does not produce name collisions with predefined keywords
+namespace delphi System
 
+include "ReservedIncluded.thrift"
 
 
 typedef i32 Cardinal
@@ -98,3 +100,39 @@
 }
 
 
+typedef i32 IProtocol 
+typedef i32 ITransport
+typedef i32 IFace
+typedef i32 IAsync
+typedef i32 System
+typedef i32 SysUtils
+typedef i32 Generics
+typedef i32 Thrift
+
+struct Struct_Thrift_Names {
+  1: IProtocol   IProtocol
+  2: ITransport  ITransport
+  3: IFace       IFace
+  4: IAsync      IAsync
+  5: System      System
+  6: SysUtils    SysUtils
+  7: Generics    Generics
+  8: Thrift      Thrift
+}
+
+
+enum Thrift4554_Enum {
+  Foo = 0,
+  Bar = 1,
+  Baz = 2,
+}
+
+struct Thrift4554_Struct {
+  1 : optional double MinValue
+  2 : optional double MaxValue
+  3 : optional bool Integer  // causes issue
+  4 : optional Thrift4554_Enum Foo
+}
+
+
+// EOF