Changeset 48 for branches/DelphiToC/Produce/UProducerC.pas
- Timestamp:
- Aug 9, 2010, 1:53:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Produce/UProducerC.pas
r47 r48 23 23 LabelPrefix: string); 24 24 procedure GenerateProgram(ProgramBlock: TProgram); 25 procedure Generate Methods(Methods: TFunctionList);25 procedure GenerateFunctions(Functions: TFunctionList); 26 26 procedure GenerateBeginEnd(BeginEnd: TBeginEnd); 27 27 procedure GenerateCommand(Command: TCommand); … … 29 29 procedure GenerateIfThenElse(IfThenElse: TIfThenElse); 30 30 procedure GenerateAssignment(Assignment: TAssignment); 31 procedure Generate MethodCall(MethodCall: TFunctionCall);31 procedure GenerateFunctionCall(FunctionCall: TFunctionCall); 32 32 function GenerateExpression(Expression: TExpression): string; 33 33 public … … 58 58 function TCProducer.TranslateType(Name: string): string; 59 59 begin 60 if Name = 'Byte' then Result := 'uint8_t'; 61 if Name = 'Word' then Result := 'uint16_t'; 62 if Name = 'Void' then Result := 'void'; 60 if Name = 'Byte' then Result := 'uint8' 61 else if Name = 'ShortInt' then Result := 'int8' 62 else if Name = 'Word' then Result := 'int16' 63 else if Name = 'SmallInt' then Result := 'int16' 64 else if Name = 'Cardinal' then Result := 'uint32' 65 else if Name = 'Integer' then Result := 'int32' 66 else if Name = 'Void' then Result := 'void'; 63 67 end; 64 68 … … 115 119 end; 116 120 117 procedure TCProducer.GenerateMethods(Methods: TFunctionList); 118 var 119 I: Integer; 120 begin 121 for I := 0 to Methods.Count - 1 do 122 with TFunction(Methods[I]) do 121 procedure TCProducer.GenerateFunctions(Functions: TFunctionList); 122 var 123 I: Integer; 124 J: Integer; 125 Line: string; 126 begin 127 for I := 0 to Functions.Count - 1 do 128 with TFunction(Functions[I]) do 123 129 begin 124 Emit('void ' + Name + '()'); 130 if HaveResult then Line := TranslateType(ResultType.Name) + ' ' 131 else Line := 'void '; 132 Line := Line + Name + '('; 133 if Parameters.Count > 0 then 134 for J := 0 to Parameters.Count - 1 do begin 135 Line := Line + TranslateType(TParameter(Parameters[J]).ValueType.Name) + 136 ' ' + TParameter(Parameters[J]).Name; 137 if J < Parameters.Count - 1 then Line := Line + ', '; 138 end; 139 Line := Line + ')'; 140 Emit(Line); 125 141 GenerateBeginEnd(Code); 126 142 Emit(''); … … 158 174 else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command)) 159 175 else if Command is TAssignment then GenerateAssignment(TAssignment(Command)) 160 else if Command is TFunctionCall then Generate MethodCall(TFunctionCall(Command));176 else if Command is TFunctionCall then GenerateFunctionCall(TFunctionCall(Command)); 161 177 end; 162 178 … … 182 198 end; 183 199 184 procedure TCProducer.GenerateMethodCall(MethodCall: TFunctionCall); 185 begin 186 Emit(MethodCall.FunctionRef.Name + '();'); 200 procedure TCProducer.GenerateFunctionCall(FunctionCall: TFunctionCall); 201 var 202 Line: string; 203 begin 204 Line := FunctionCall.FunctionRef.Name + '('; 205 Line := Line + ');'; 206 Emit(Line); 187 207 end; 188 208 … … 208 228 begin 209 229 with CommonBlock do begin 210 Generate Methods(Methods);230 GenerateFunctions(Functions); 211 231 Emit('void ' + Name + '()'); 212 232 GenerateBeginEnd(Code);
Note:
See TracChangeset
for help on using the changeset viewer.