Ignore:
Timestamp:
Aug 9, 2010, 1:53:33 PM (14 years ago)
Author:
george
Message:

Added support of parameters for function call.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Produce/UProducerC.pas

    r47 r48  
    2323      LabelPrefix: string);
    2424    procedure GenerateProgram(ProgramBlock: TProgram);
    25     procedure GenerateMethods(Methods: TFunctionList);
     25    procedure GenerateFunctions(Functions: TFunctionList);
    2626    procedure GenerateBeginEnd(BeginEnd: TBeginEnd);
    2727    procedure GenerateCommand(Command: TCommand);
     
    2929    procedure GenerateIfThenElse(IfThenElse: TIfThenElse);
    3030    procedure GenerateAssignment(Assignment: TAssignment);
    31     procedure GenerateMethodCall(MethodCall: TFunctionCall);
     31    procedure GenerateFunctionCall(FunctionCall: TFunctionCall);
    3232    function GenerateExpression(Expression: TExpression): string;
    3333  public
     
    5858function TCProducer.TranslateType(Name: string): string;
    5959begin
    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';
    6367end;
    6468
     
    115119end;
    116120
    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
     121procedure TCProducer.GenerateFunctions(Functions: TFunctionList);
     122var
     123  I: Integer;
     124  J: Integer;
     125  Line: string;
     126begin
     127  for I := 0 to Functions.Count - 1 do
     128  with TFunction(Functions[I]) do
    123129  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);
    125141    GenerateBeginEnd(Code);
    126142    Emit('');
     
    158174  else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command))
    159175  else if Command is TAssignment then GenerateAssignment(TAssignment(Command))
    160   else if Command is TFunctionCall then GenerateMethodCall(TFunctionCall(Command));
     176  else if Command is TFunctionCall then GenerateFunctionCall(TFunctionCall(Command));
    161177end;
    162178
     
    182198end;
    183199
    184 procedure TCProducer.GenerateMethodCall(MethodCall: TFunctionCall);
    185 begin
    186   Emit(MethodCall.FunctionRef.Name + '();');
     200procedure TCProducer.GenerateFunctionCall(FunctionCall: TFunctionCall);
     201var
     202  Line: string;
     203begin
     204  Line := FunctionCall.FunctionRef.Name + '(';
     205  Line := Line + ');';
     206  Emit(Line);
    187207end;
    188208
     
    208228begin
    209229  with CommonBlock do begin
    210     GenerateMethods(Methods);
     230    GenerateFunctions(Functions);
    211231    Emit('void ' + Name + '()');
    212232    GenerateBeginEnd(Code);
Note: See TracChangeset for help on using the changeset viewer.