Ignore:
Timestamp:
Aug 5, 2010, 3:13:03 PM (14 years ago)
Author:
george
Message:

Enhanced C code generation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Visual/USourceTree.pas

    r41 r42  
    1414  TSourceTree = class
    1515  private
     16    procedure AddNodeAssignment(Node: TTreeNode; Assignment: TAssignment);
    1617    procedure AddNodeBeginEnd(Node: TTreeNode; BeginEnd: TBeginEnd);
     18    procedure AddNodeIfThenElse(Node: TTreeNode; IfThenElse: TIfThenElse);
     19    procedure AddNodeMethodCall(Node: TTreeNode; Method: TMethodCall);
    1720    procedure AddNodeMethodList(Node: TTreeNode; Methods: TFunctionList);
    1821    procedure AddNodeTypeList(Node: TTreeNode; Types: TTypeList);
     
    6063end;
    6164
     65procedure TSourceTree.AddNodeIfThenElse(Node: TTreeNode; IfThenElse: TIfThenElse);
     66var
     67  NewNode: TTreeNode;
     68  NewNode2: TTreeNode;
     69  NewNode3: TTreeNode;
     70  I: Integer;
     71begin
     72  NewNode := TreeView.Items.AddChild(Node, 'if');
     73  NewNode2 := TreeView.Items.AddChild(NewNode, 'condition');
     74  AddNodeExpression(NewNode2, IfThenElse.Condition);
     75  NewNode2 := TreeView.Items.AddChild(NewNode, 'then');
     76  AddNodeCommand(NewNode2, IfThenElse.Command);
     77  if Assigned(IfThenElse.ElseCommand) then begin
     78    NewNode2 := TreeView.Items.AddChild(NewNode, 'else');
     79    AddNodeCommand(NewNode2, IfThenElse.ElseCommand);
     80  end;
     81end;
     82
     83procedure TSourceTree.AddNodeMethodCall(Node: TTreeNode; Method: TMethodCall);
     84var
     85  NewNode: TTreeNode;
     86begin
     87  NewNode := TreeView.Items.AddChild(Node, Method.Method.Name);
     88end;
     89
     90procedure TSourceTree.AddNodeAssignment(Node: TTreeNode; Assignment: TAssignment);
     91var
     92  NewNode: TTreeNode;
     93begin
     94  NewNode := TreeView.Items.AddChild(Node, Assignment.Target.Name + ' := ');
     95  AddNodeExpression(NewNode, Assignment.Source);
     96end;
     97
    6298procedure TSourceTree.AddNodeCommand(Node: TTreeNode; Command: TCommand);
    6399begin
     
    66102  if Command is TWhileDo then
    67103    AddNodeWhileDo(Node, TWhileDo(Command));
     104  if Command is TMethodCall then
     105    AddNodeMethodCall(Node, TMethodCall(Command));
     106  if Command is TIfThenElse then
     107    AddNodeIfThenElse(Node, TIfThenElse(Command));
     108  if Command is TAssignment then
     109    AddNodeAssignment(Node, TAssignment(Command));
    68110end;
    69111
    70112procedure TSourceTree.AddNodeExpression(Node: TTreeNode; Expression: TExpression
    71113  );
    72 begin
    73 
     114var
     115  NewNode: TTreeNode;
     116begin
     117  case Expression.NodeType of
     118    ntConstant: NewNode := TreeView.Items.AddChild(Node, Expression.Value);
     119    ntVariable: NewNode := TreeView.Items.AddChild(Node, Expression.Variable.Name);
     120    ntFunction: NewNode := TreeView.Items.AddChild(Node, Expression.Method.Name);
     121    ntOperator: begin
     122      NewNode := TreeView.Items.AddChild(Node, Expression.OperatorName);
     123      AddNodeExpression(NewNode, TExpression(Expression.SubItems.First));
     124      AddNodeExpression(NewNode, TExpression(Expression.SubItems.Last));
     125    end;
     126    ntNone: ;
     127  end;
    74128end;
    75129
Note: See TracChangeset for help on using the changeset viewer.