Changeset 47 for branches/DelphiToC/Produce/UProducerPascal.pas
- Timestamp:
- Aug 9, 2010, 12:48:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Produce/UProducerPascal.pas
r46 r47 7 7 uses 8 8 SysUtils, Variants, Classes, Graphics, Controls, Forms, 9 Dialogs, StdCtrls,UPascalSource, UCodeProducer, StrUtils;9 Dialogs, UPascalSource, UCodeProducer, StrUtils; 10 10 11 11 type … … 21 21 LabelPrefix: string); 22 22 procedure GenerateProgram(ProgramBlock: TProgram); 23 procedure Generate Methods(Methods: TFunctionList);23 procedure GenerateFunctions(Functions: TFunctionList); 24 24 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 25 25 procedure GenerateVariableList(Variables: TVariableList); … … 28 28 procedure GenerateIfThenElse(IfThenElse: TIfThenElse); 29 29 procedure GenerateAssignment(Assignment: TAssignment); 30 procedure GenerateMethodCall(MethodCall: T MethodCall);30 procedure GenerateMethodCall(MethodCall: TFunctionCall); 31 31 function GenerateExpression(Expression: TExpression): string; 32 32 public … … 97 97 end; 98 98 99 procedure TProducerPascal.GenerateMethods(Methods: TFunctionList); 100 var 101 I: Integer; 102 begin 103 for I := 0 to Methods.Count - 1 do 104 with TFunction(Methods[I]) do 99 procedure TProducerPascal.GenerateFunctions(Functions: TFunctionList); 100 var 101 I: Integer; 102 P: Integer; 103 Line: string; 104 begin 105 for I := 0 to Functions.Count - 1 do 106 with TFunction(Functions[I]) do 105 107 begin 106 Emit('procedure ' + Name + ''); 108 if HaveResult then 109 Line := 'function ' + Name 110 else Line := 'procedure ' + Name; 111 if Parameters.Count > 0 then begin 112 Line := Line + '('; 113 for P := 0 to Parameters.Count - 1 do begin 114 with TParameter(Parameters[P]) do 115 Line := Line + Name + ': ' + ValueType.Name; 116 if P < (Parameters.Count - 1) then Line := Line + '; '; 117 end; 118 Line := Line + ')'; 119 end; 120 if HaveResult then Line := Line + ': ' + ResultType.Name; 121 Emit(Line + ';'); 107 122 GenerateBeginEnd(Code); 108 123 Emit(''); … … 121 136 122 137 Dec(Indetation); 123 Emit('end ');138 Emit('end;'); 124 139 end; 125 140 … … 141 156 else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command)) 142 157 else if Command is TAssignment then GenerateAssignment(TAssignment(Command)) 143 else if Command is T MethodCall then GenerateMethodCall(TMethodCall(Command));158 else if Command is TFunctionCall then GenerateMethodCall(TFunctionCall(Command)); 144 159 end; 145 160 … … 154 169 Emit('if ' + GenerateExpression(IfThenElse.Condition) + ' then '); 155 170 GenerateCommand(IfThenElse.Command); 156 Emit('else '); 157 GenerateCommand(IfThenElse.ElseCommand); 171 if Assigned(IfThenElse.ElseCommand) then begin 172 Emit('else '); 173 GenerateCommand(IfThenElse.ElseCommand); 174 end; 158 175 end; 159 176 160 177 procedure TProducerPascal.GenerateAssignment(Assignment: TAssignment); 161 178 begin 162 Emit(Assignment.Target.Name + ' = ' + GenerateExpression(Assignment.Source) + ';');163 end; 164 165 procedure TProducerPascal.GenerateMethodCall(MethodCall: T MethodCall);166 begin 167 Emit(MethodCall. Method.Name + ';');179 Emit(Assignment.Target.Name + ' := ' + GenerateExpression(Assignment.Source) + ';'); 180 end; 181 182 procedure TProducerPascal.GenerateMethodCall(MethodCall: TFunctionCall); 183 begin 184 Emit(MethodCall.FunctionRef.Name + ';'); 168 185 end; 169 186 … … 189 206 begin 190 207 with CommonBlock do begin 191 Generate Methods(Methods);208 GenerateFunctions(Methods); 192 209 Emit('procedure ' + Name + ''); 193 210 GenerateBeginEnd(Code);
Note:
See TracChangeset
for help on using the changeset viewer.