Changeset 47


Ignore:
Timestamp:
Aug 9, 2010, 12:48:14 PM (14 years ago)
Author:
george
Message:

Support for function definition with result type.

Location:
branches/DelphiToC
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Analyze/UPascalParser.pas

    r46 r47  
    424424      end;
    425425    end;
    426     Assign(TExpression(TExpression(Expressions.First).SubItems[1]));
     426    if Assigned(TExpression(Expressions.First).SubItems[1]) then
     427      Assign(TExpression(TExpression(Expressions.First).SubItems[1]));
    427428    TExpression(Expressions.First).SubItems[1] := nil;
    428429    //ShowMessage(IntToStr(Expressions.Count));
    429     TExpression(Expressions[1]).SubItems[0] := nil;
     430    if Expressions.Count > 1 then
     431      TExpression(Expressions[1]).SubItems[0] := nil;
    430432    Expressions.Destroy;
    431433  end;
     
    473475      end else
    474476      if Assigned(SourceCode.Methods.Search(FNextToken)) then begin
    475         Result := TMethodCall.Create;
    476         TMethodCall(Result).CommonBlock := SourceCode;
    477         TMethodCall(Result).Method := SourceCode.Methods.Search(FNextToken);
     477        Result := TFunctionCall.Create;
     478        TFunctionCall(Result).CommonBlock := SourceCode;
     479        TFunctionCall(Result).FunctionRef := SourceCode.Methods.Search(FNextToken);
    478480        ReadCode;
    479   //      ParseMetVariable(TMethodCall(Result).Target);
     481  //      ParseMetVariable(TFunctionCall(Result).Target);
    480482      end else begin
    481483        Result := nil;
     
    560562      else if FNextToken = 'procedure' then
    561563        ParseFunctionList(Methods)
     564      else if FNextToken = 'function' then
     565        ParseFunctionList(Methods)
    562566      else begin
    563567        ParseBeginEnd(Code);
     
    604608    with TFunction(Items[Add(TFunction.Create)]) do begin
    605609      Parent := SourceCode.Parent;
    606       Expect('procedure');
     610      if FNextToken = 'procedure' then begin
     611        Expect('procedure');
     612        HaveResult := False;
     613      end else begin
     614        Expect('function');
     615        HaveResult := True;
     616      end;
    607617      Name := ReadCode;
     618
    608619      if FNextToken = '(' then begin
    609620        Expect('(');
     
    632643        end;
    633644        Expect(')');
     645
     646        // Parse function result type
     647        if HaveResult then begin
     648          Expect(':');
     649          TypeName := ReadCode;
     650          NewValueType := Parent.Types.Search(TypeName);
     651          if not Assigned(NewValueType) then ErrorMessage(STypeNotDefined, [TypeName])
     652            else begin
     653              ResultType := NewValueType;
     654              with TVariable(Parent.Variables.Items[Parent.Variables.Add(TVariable.Create)]) do begin
     655                Name := 'Result';
     656                ValueType := NewValueType;
     657              end;
     658            end;
     659        end;
    634660      end;
    635661    end;
    636662    Expect(';');
    637     ParseCommonBlock(TFunction(Items[Count - 1]));
     663    ParseCommonBlock(TFunction(Last));
    638664  end;
    639665  Identifiers.Destroy;
  • branches/DelphiToC/DelphiToC.lpi

    r46 r47  
    4747        <WindowIndex Value="0"/>
    4848        <TopLine Value="4"/>
    49         <CursorPos X="42" Y="15"/>
    50         <UsageCount Value="104"/>
     49        <CursorPos X="1" Y="29"/>
     50        <UsageCount Value="107"/>
    5151        <Loaded Value="True"/>
    5252      </Unit0>
     
    6262        <TopLine Value="56"/>
    6363        <CursorPos X="1" Y="79"/>
    64         <UsageCount Value="104"/>
     64        <UsageCount Value="107"/>
    6565        <Loaded Value="True"/>
    6666        <LoadedDesigner Value="True"/>
     
    7373        <TopLine Value="1"/>
    7474        <CursorPos X="1" Y="1"/>
    75         <UsageCount Value="104"/>
     75        <UsageCount Value="107"/>
    7676      </Unit2>
    7777      <Unit3>
     
    8181        <EditorIndex Value="5"/>
    8282        <WindowIndex Value="0"/>
    83         <TopLine Value="119"/>
    84         <CursorPos X="3" Y="132"/>
    85         <UsageCount Value="104"/>
     83        <TopLine Value="221"/>
     84        <CursorPos X="25" Y="240"/>
     85        <UsageCount Value="107"/>
    8686        <Loaded Value="True"/>
    8787      </Unit3>
     
    9494        <TopLine Value="36"/>
    9595        <CursorPos X="1" Y="41"/>
    96         <UsageCount Value="104"/>
     96        <UsageCount Value="107"/>
    9797        <Loaded Value="True"/>
    9898      </Unit4>
     
    105105        <TopLine Value="112"/>
    106106        <CursorPos X="48" Y="128"/>
    107         <UsageCount Value="104"/>
     107        <UsageCount Value="107"/>
    108108        <Loaded Value="True"/>
    109109      </Unit5>
     
    116116        <TopLine Value="1"/>
    117117        <CursorPos X="15" Y="13"/>
    118         <UsageCount Value="104"/>
     118        <UsageCount Value="107"/>
    119119        <Loaded Value="True"/>
    120120      </Unit6>
     
    125125        <EditorIndex Value="10"/>
    126126        <WindowIndex Value="0"/>
    127         <TopLine Value="130"/>
    128         <CursorPos X="48" Y="144"/>
    129         <UsageCount Value="104"/>
     127        <TopLine Value="171"/>
     128        <CursorPos X="45" Y="175"/>
     129        <UsageCount Value="107"/>
    130130        <Loaded Value="True"/>
    131131      </Unit7>
     
    134134        <IsPartOfProject Value="True"/>
    135135        <UnitName Value="UPascalParser"/>
     136        <IsVisibleTab Value="True"/>
    136137        <EditorIndex Value="0"/>
    137138        <WindowIndex Value="0"/>
    138         <TopLine Value="137"/>
    139         <CursorPos X="26" Y="555"/>
    140         <UsageCount Value="104"/>
     139        <TopLine Value="641"/>
     140        <CursorPos X="45" Y="653"/>
     141        <UsageCount Value="107"/>
    141142        <Loaded Value="True"/>
    142143      </Unit8>
     
    154155        <EditorIndex Value="6"/>
    155156        <WindowIndex Value="0"/>
    156         <TopLine Value="68"/>
    157         <CursorPos X="14" Y="90"/>
    158         <UsageCount Value="53"/>
     157        <TopLine Value="78"/>
     158        <CursorPos X="14" Y="91"/>
     159        <UsageCount Value="54"/>
    159160        <Loaded Value="True"/>
    160161      </Unit10>
     
    173174        <TopLine Value="61"/>
    174175        <CursorPos X="7" Y="68"/>
    175         <UsageCount Value="36"/>
     176        <UsageCount Value="37"/>
    176177        <Loaded Value="True"/>
    177178      </Unit12>
     
    182183        <TopLine Value="139"/>
    183184        <CursorPos X="16" Y="146"/>
    184         <UsageCount Value="36"/>
     185        <UsageCount Value="37"/>
    185186        <Loaded Value="True"/>
    186187      </Unit13>
     
    205206        <TopLine Value="153"/>
    206207        <CursorPos X="8" Y="166"/>
    207         <UsageCount Value="10"/>
     208        <UsageCount Value="12"/>
    208209        <Loaded Value="True"/>
    209210      </Unit16>
     
    214215        <EditorIndex Value="2"/>
    215216        <WindowIndex Value="0"/>
    216         <TopLine Value="189"/>
    217         <CursorPos X="1" Y="202"/>
    218         <UsageCount Value="66"/>
     217        <TopLine Value="178"/>
     218        <CursorPos X="67" Y="190"/>
     219        <UsageCount Value="69"/>
    219220        <Loaded Value="True"/>
    220221      </Unit17>
     
    233234        <TopLine Value="263"/>
    234235        <CursorPos X="14" Y="276"/>
    235         <UsageCount Value="10"/>
     236        <UsageCount Value="12"/>
    236237        <Loaded Value="True"/>
    237238      </Unit19>
     
    240241        <IsPartOfProject Value="True"/>
    241242        <UnitName Value="UProducerPascal"/>
    242         <IsVisibleTab Value="True"/>
    243243        <EditorIndex Value="8"/>
    244244        <WindowIndex Value="0"/>
    245         <TopLine Value="173"/>
    246         <CursorPos X="33" Y="192"/>
    247         <UsageCount Value="21"/>
     245        <TopLine Value="103"/>
     246        <CursorPos X="21" Y="116"/>
     247        <UsageCount Value="23"/>
    248248        <Loaded Value="True"/>
    249249      </Unit20>
    250250    </Units>
    251     <JumpHistory Count="27" HistoryIndex="26">
     251    <JumpHistory Count="29" HistoryIndex="28">
    252252      <Position1>
    253253        <Filename Value="UPascalSource.pas"/>
    254         <Caret Line="241" Column="27" TopLine="236"/>
     254        <Caret Line="441" Column="20" TopLine="429"/>
    255255      </Position1>
    256256      <Position2>
    257         <Filename Value="DelphiToC.lpr"/>
    258         <Caret Line="27" Column="1" TopLine="4"/>
     257        <Filename Value="UPascalSource.pas"/>
     258        <Caret Line="448" Column="49" TopLine="432"/>
    259259      </Position2>
    260260      <Position3>
    261         <Filename Value="UMainForm.pas"/>
    262         <Caret Line="49" Column="40" TopLine="34"/>
     261        <Filename Value="Analyze\UPascalParser.pas"/>
     262        <Caret Line="329" Column="1" TopLine="316"/>
    263263      </Position3>
    264264      <Position4>
    265         <Filename Value="UMainForm.pas"/>
    266         <Caret Line="48" Column="40" TopLine="33"/>
     265        <Filename Value="UPascalSource.pas"/>
     266        <Caret Line="435" Column="1" TopLine="430"/>
    267267      </Position4>
    268268      <Position5>
    269         <Filename Value="UMainForm.pas"/>
    270         <Caret Line="52" Column="40" TopLine="37"/>
     269        <Filename Value="UPascalSource.pas"/>
     270        <Caret Line="436" Column="1" TopLine="430"/>
    271271      </Position5>
    272272      <Position6>
    273         <Filename Value="UMainForm.pas"/>
    274         <Caret Line="51" Column="44" TopLine="38"/>
     273        <Filename Value="UPascalSource.pas"/>
     274        <Caret Line="437" Column="1" TopLine="430"/>
    275275      </Position6>
    276276      <Position7>
    277         <Filename Value="UMainForm.pas"/>
    278         <Caret Line="75" Column="11" TopLine="62"/>
     277        <Filename Value="UPascalSource.pas"/>
     278        <Caret Line="438" Column="1" TopLine="430"/>
    279279      </Position7>
    280280      <Position8>
    281         <Filename Value="UMainForm.pas"/>
    282         <Caret Line="91" Column="26" TopLine="73"/>
     281        <Filename Value="UPascalSource.pas"/>
     282        <Caret Line="440" Column="1" TopLine="430"/>
    283283      </Position8>
    284284      <Position9>
    285         <Filename Value="UMainForm.pas"/>
    286         <Caret Line="89" Column="21" TopLine="74"/>
     285        <Filename Value="UPascalSource.pas"/>
     286        <Caret Line="441" Column="1" TopLine="430"/>
    287287      </Position9>
    288288      <Position10>
    289         <Filename Value="UMainForm.pas"/>
    290         <Caret Line="91" Column="21" TopLine="76"/>
     289        <Filename Value="UPascalSource.pas"/>
     290        <Caret Line="442" Column="1" TopLine="430"/>
    291291      </Position10>
    292292      <Position11>
    293         <Filename Value="Produce\UProducerPascal.pas"/>
    294         <Caret Line="15" Column="10" TopLine="5"/>
     293        <Filename Value="UPascalSource.pas"/>
     294        <Caret Line="446" Column="1" TopLine="430"/>
    295295      </Position11>
    296296      <Position12>
    297         <Filename Value="Produce\UProducerPascal.pas"/>
    298         <Caret Line="27" Column="62" TopLine="13"/>
     297        <Filename Value="UPascalSource.pas"/>
     298        <Caret Line="447" Column="1" TopLine="430"/>
    299299      </Position12>
    300300      <Position13>
    301         <Filename Value="Produce\UProducerPascal.pas"/>
    302         <Caret Line="66" Column="1" TopLine="86"/>
     301        <Filename Value="UPascalSource.pas"/>
     302        <Caret Line="448" Column="1" TopLine="430"/>
    303303      </Position13>
    304304      <Position14>
    305         <Filename Value="Produce\UProducerPascal.pas"/>
    306         <Caret Line="59" Column="1" TopLine="50"/>
     305        <Filename Value="UPascalSource.pas"/>
     306        <Caret Line="452" Column="1" TopLine="431"/>
    307307      </Position14>
    308308      <Position15>
    309         <Filename Value="Produce\UProducerPascal.pas"/>
    310         <Caret Line="138" Column="1" TopLine="128"/>
     309        <Filename Value="UPascalSource.pas"/>
     310        <Caret Line="453" Column="1" TopLine="432"/>
    311311      </Position15>
    312312      <Position16>
    313         <Filename Value="Produce\UProducerPascal.pas"/>
    314         <Caret Line="72" Column="16" TopLine="59"/>
     313        <Filename Value="UPascalSource.pas"/>
     314        <Caret Line="455" Column="1" TopLine="434"/>
    315315      </Position16>
    316316      <Position17>
    317         <Filename Value="Produce\UProducerPascal.pas"/>
    318         <Caret Line="134" Column="1" TopLine="119"/>
     317        <Filename Value="Analyze\UPascalParser.pas"/>
     318        <Caret Line="329" Column="1" TopLine="316"/>
    319319      </Position17>
    320320      <Position18>
    321         <Filename Value="Produce\UProducerPascal.pas"/>
    322         <Caret Line="130" Column="14" TopLine="118"/>
     321        <Filename Value="UPascalSource.pas"/>
     322        <Caret Line="448" Column="1" TopLine="436"/>
    323323      </Position18>
    324324      <Position19>
    325         <Filename Value="Produce\UProducerPascal.pas"/>
    326         <Caret Line="17" Column="1" TopLine="4"/>
     325        <Filename Value="UPascalSource.pas"/>
     326        <Caret Line="544" Column="1" TopLine="531"/>
    327327      </Position19>
    328328      <Position20>
    329         <Filename Value="Produce\UProducerPascal.pas"/>
    330         <Caret Line="133" Column="38" TopLine="120"/>
     329        <Filename Value="UPascalSource.pas"/>
     330        <Caret Line="545" Column="1" TopLine="531"/>
    331331      </Position20>
    332332      <Position21>
    333         <Filename Value="UMainForm.pas"/>
    334         <Caret Line="11" Column="18" TopLine="1"/>
     333        <Filename Value="UPascalSource.pas"/>
     334        <Caret Line="546" Column="62" TopLine="532"/>
    335335      </Position21>
    336336      <Position22>
    337         <Filename Value="UMainForm.pas"/>
    338         <Caret Line="60" Column="3" TopLine="50"/>
     337        <Filename Value="Produce\UProducerPascal.pas"/>
     338        <Caret Line="154" Column="51" TopLine="139"/>
    339339      </Position22>
    340340      <Position23>
    341         <Filename Value="UMainForm.pas"/>
    342         <Caret Line="55" Column="9" TopLine="50"/>
     341        <Filename Value="DelphiToC.lpr"/>
     342        <Caret Line="15" Column="42" TopLine="4"/>
    343343      </Position23>
    344344      <Position24>
    345         <Filename Value="UMainForm.pas"/>
    346         <Caret Line="69" Column="8" TopLine="56"/>
     345        <Filename Value="UPascalSource.pas"/>
     346        <Caret Line="241" Column="20" TopLine="221"/>
    347347      </Position24>
    348348      <Position25>
    349         <Filename Value="UMainForm.pas"/>
    350         <Caret Line="81" Column="18" TopLine="61"/>
     349        <Filename Value="Analyze\UPascalParser.pas"/>
     350        <Caret Line="565" Column="22" TopLine="552"/>
    351351      </Position25>
    352352      <Position26>
    353         <Filename Value="UPascalCompiler.pas"/>
    354         <Caret Line="41" Column="15" TopLine="36"/>
     353        <Filename Value="Visual\USourceTree.pas"/>
     354        <Caret Line="194" Column="57" TopLine="186"/>
    355355      </Position26>
    356356      <Position27>
    357         <Filename Value="UMainForm.pas"/>
    358         <Caret Line="79" Column="1" TopLine="56"/>
     357        <Filename Value="Produce\UProducerPascal.pas"/>
     358        <Caret Line="120" Column="1" TopLine="99"/>
    359359      </Position27>
     360      <Position28>
     361        <Filename Value="Analyze\UPascalParser.pas"/>
     362        <Caret Line="653" Column="28" TopLine="632"/>
     363      </Position28>
     364      <Position29>
     365        <Filename Value="Analyze\UPascalParser.pas"/>
     366        <Caret Line="654" Column="40" TopLine="632"/>
     367      </Position29>
    360368    </JumpHistory>
    361369  </ProjectOptions>
  • branches/DelphiToC/Example.pas

    r46 r47  
    33uses System, Crt;
    44
    5 procedure Pokus(A: Byte);
     5function Max(A, B: Byte): Byte;
    66var
    77  S: Byte;
    88begin
    9   WriteLn;
    10   WriteLn;
     9  if A > B then Result := A
     10  else Result := B;
    1111end;
    1212
  • branches/DelphiToC/Produce/UProducerC.pas

    r46 r47  
    2929    procedure GenerateIfThenElse(IfThenElse: TIfThenElse);
    3030    procedure GenerateAssignment(Assignment: TAssignment);
    31     procedure GenerateMethodCall(MethodCall: TMethodCall);
     31    procedure GenerateMethodCall(MethodCall: TFunctionCall);
    3232    function GenerateExpression(Expression: TExpression): string;
    3333  public
     
    158158  else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command))
    159159  else if Command is TAssignment then GenerateAssignment(TAssignment(Command))
    160   else if Command is TMethodCall then GenerateMethodCall(TMethodCall(Command));
     160  else if Command is TFunctionCall then GenerateMethodCall(TFunctionCall(Command));
    161161end;
    162162
     
    171171  Emit('if(' + GenerateExpression(IfThenElse.Condition) + ')');
    172172  GenerateCommand(IfThenElse.Command);
    173   Emit('else ');
    174   GenerateCommand(IfThenElse.ElseCommand);
     173  if Assigned(IfThenElse.ElseCommand) then begin
     174    Emit('else ');
     175    GenerateCommand(IfThenElse.ElseCommand);
     176  end;
    175177end;
    176178
     
    180182end;
    181183
    182 procedure TCProducer.GenerateMethodCall(MethodCall: TMethodCall);
    183 begin
    184   Emit(MethodCall.Method.Name + '();');
     184procedure TCProducer.GenerateMethodCall(MethodCall: TFunctionCall);
     185begin
     186  Emit(MethodCall.FunctionRef.Name + '();');
    185187end;
    186188
  • branches/DelphiToC/Produce/UProducerPascal.pas

    r46 r47  
    77uses
    88  SysUtils, Variants, Classes, Graphics, Controls, Forms,
    9   Dialogs, StdCtrls, UPascalSource, UCodeProducer, StrUtils;
     9  Dialogs, UPascalSource, UCodeProducer, StrUtils;
    1010
    1111type
     
    2121      LabelPrefix: string);
    2222    procedure GenerateProgram(ProgramBlock: TProgram);
    23     procedure GenerateMethods(Methods: TFunctionList);
     23    procedure GenerateFunctions(Functions: TFunctionList);
    2424    procedure GenerateBeginEnd(BeginEnd: TBeginEnd);
    2525    procedure GenerateVariableList(Variables: TVariableList);
     
    2828    procedure GenerateIfThenElse(IfThenElse: TIfThenElse);
    2929    procedure GenerateAssignment(Assignment: TAssignment);
    30     procedure GenerateMethodCall(MethodCall: TMethodCall);
     30    procedure GenerateMethodCall(MethodCall: TFunctionCall);
    3131    function GenerateExpression(Expression: TExpression): string;
    3232  public
     
    9797end;
    9898
    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
     99procedure TProducerPascal.GenerateFunctions(Functions: TFunctionList);
     100var
     101  I: Integer;
     102  P: Integer;
     103  Line: string;
     104begin
     105  for I := 0 to Functions.Count - 1 do
     106  with TFunction(Functions[I]) do
    105107  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 + ';');
    107122    GenerateBeginEnd(Code);
    108123    Emit('');
     
    121136
    122137  Dec(Indetation);
    123   Emit('end');
     138  Emit('end;');
    124139end;
    125140
     
    141156  else if Command is TIfThenElse then GenerateIfThenElse(TIfThenElse(Command))
    142157  else if Command is TAssignment then GenerateAssignment(TAssignment(Command))
    143   else if Command is TMethodCall then GenerateMethodCall(TMethodCall(Command));
     158  else if Command is TFunctionCall then GenerateMethodCall(TFunctionCall(Command));
    144159end;
    145160
     
    154169  Emit('if ' + GenerateExpression(IfThenElse.Condition) + ' then ');
    155170  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;
    158175end;
    159176
    160177procedure TProducerPascal.GenerateAssignment(Assignment: TAssignment);
    161178begin
    162   Emit(Assignment.Target.Name + ' = ' + GenerateExpression(Assignment.Source) + ';');
    163 end;
    164 
    165 procedure TProducerPascal.GenerateMethodCall(MethodCall: TMethodCall);
    166 begin
    167   Emit(MethodCall.Method.Name + ';');
     179  Emit(Assignment.Target.Name + ' := ' + GenerateExpression(Assignment.Source) + ';');
     180end;
     181
     182procedure TProducerPascal.GenerateMethodCall(MethodCall: TFunctionCall);
     183begin
     184  Emit(MethodCall.FunctionRef.Name + ';');
    168185end;
    169186
     
    189206begin
    190207  with CommonBlock do begin
    191     GenerateMethods(Methods);
     208    GenerateFunctions(Methods);
    192209    Emit('procedure ' + Name + '');
    193210    GenerateBeginEnd(Code);
  • branches/DelphiToC/UPascalSource.pas

    r45 r47  
    5757  end;
    5858
    59   TMethodCall = class(TCommand)
    60     Method: TFunction;
     59  TFunctionCall = class(TCommand)
     60    FunctionRef: TFunction;
    6161  end;
    6262
     
    185185    Name: string;
    186186    ValueType: TType;
    187     Value: TValue;
     187    DefaultValue: TValue;
    188188  end;
    189189
     
    194194  end;
    195195
    196   TParameter = class
    197     Name: string;
    198     ValueType: TType;
    199     DafaultValue: TValue;
     196  TParameter = class(TVariable)
    200197  end;
    201198
     
    241238  TFunction = class(TCommonBlock)
    242239  public
     240    HaveResult: Boolean;
    243241    Parameters: TParameterList;
    244242    ResultType: TType;
     
    439437  I := 0;
    440438  while (I < Count) and (LowerCase(TVariable(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    441   if I < Count then Result := TVariable(Items[I]) else begin
     439  if I < Count then Result := TVariable(Items[I]) else Result := nil;
     440
     441  if not Assigned(Result) then begin
    442442    if Assigned(Parent.Parent) then
    443443      Result := Parent.Parent.Variables.Search(Name)
     444      else Result := nil;
     445  end;
     446
     447  if not Assigned(Result) then begin
     448    if Assigned(Parent) and (Parent is TFunction) then
     449      Result := TFunction(Parent).Parameters.Search(Name)
     450      else Result := nil;
     451  end;
     452
     453  if not Assigned(Result) then begin
     454    if Assigned(Parent.Parent) and (Parent.Parent is TFunction) then
     455      Result := TFunction(Parent.Parent).Parameters.Search(Name)
    444456      else Result := nil;
    445457  end;
     
    533545begin
    534546  I := 0;
    535   while (I < Count) and (TParameter(Items[I]).Name <> LowerCase(Name)) do Inc(I);
     547  while (I < Count) and (LowerCase(TParameter(Items[I]).Name) <> LowerCase(Name)) do Inc(I);
    536548  if I < Count then Result := TParameter(Items[I])
    537549    else Result := nil;
  • branches/DelphiToC/Visual/USourceTree.pas

    r44 r47  
    1717    procedure AddNodeBeginEnd(Node: TTreeNode; BeginEnd: TBeginEnd);
    1818    procedure AddNodeIfThenElse(Node: TTreeNode; IfThenElse: TIfThenElse);
    19     procedure AddNodeMethodCall(Node: TTreeNode; Method: TMethodCall);
     19    procedure AddNodeMethodCall(Node: TTreeNode; Method: TFunctionCall);
    2020    procedure AddNodeMethodList(Node: TTreeNode; Methods: TFunctionList);
     21    procedure AddNodeParameterList(Node: TTreeNode; Parameters: TParameterList);
    2122    procedure AddNodeTypeList(Node: TTreeNode; Types: TTypeList);
    2223    procedure AddNodeVariableList(Node: TTreeNode; Variables: TVariableList);
     
    8283end;
    8384
    84 procedure TSourceTree.AddNodeMethodCall(Node: TTreeNode; Method: TMethodCall);
    85 var
    86   NewNode: TTreeNode;
    87 begin
    88   NewNode := TreeView.Items.AddChild(Node, Method.Method.Name);
     85procedure TSourceTree.AddNodeMethodCall(Node: TTreeNode; Method: TFunctionCall);
     86var
     87  NewNode: TTreeNode;
     88begin
     89  NewNode := TreeView.Items.AddChild(Node, Method.FunctionRef.Name);
    8990end;
    9091
     
    103104  if Command is TWhileDo then
    104105    AddNodeWhileDo(Node, TWhileDo(Command));
    105   if Command is TMethodCall then
    106     AddNodeMethodCall(Node, TMethodCall(Command));
     106  if Command is TFunctionCall then
     107    AddNodeMethodCall(Node, TFunctionCall(Command));
    107108  if Command is TIfThenElse then
    108109    AddNodeIfThenElse(Node, TIfThenElse(Command));
     
    186187  for I := 0 to Methods.Count - 1 do
    187188  with TFunction(Methods[I]) do begin
    188     NewNode := TreeView.Items.AddChild(Node, 'procedure ' + Name);
     189    if HaveResult then
     190      NewNode := TreeView.Items.AddChild(Node, 'function ' + Name)
     191      else NewNode := TreeView.Items.AddChild(Node, 'procedure ' + Name);
     192    AddNodeParameterList(NewNode, Parameters);
    189193    AddNodeMethodList(NewNode, Methods);
    190194    AddNodeConstantList(NewNode, Constants);
     
    192196    AddNodeTypeList(NewNode, Types);
    193197    AddNodeBeginEnd(NewNode, Code);
     198  end;
     199end;
     200
     201procedure TSourceTree.AddNodeParameterList(Node: TTreeNode;
     202  Parameters: TParameterList);
     203var
     204  I: Integer;
     205  NewNode: TTreeNode;
     206begin
     207  if Parameters.Count > 0 then begin
     208    NewNode := TreeView.Items.AddChild(Node, 'parametery');
     209    for I := 0 to Parameters.Count - 1 do
     210    with TParameter(Parameters[I]) do begin
     211      TreeView.Items.AddChild(NewNode, Name + ': ' + ValueType.Name);
     212    end;
    194213  end;
    195214end;
Note: See TracChangeset for help on using the changeset viewer.