Changeset 63


Ignore:
Timestamp:
Jul 17, 2012, 10:54:18 AM (12 years ago)
Author:
chronos
Message:
  • Fixed: Procedure/function header and body not paired properly.
Location:
trunk/Compiler
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Analyze/UAnalyzerPascal.pas

    r62 r63  
    7676  SUnitNotFound = 'Unit "%s" not found.';
    7777  SFunctionNotDeclared = 'Function "%s" not declared.';
     78  SFunctionRedefinition = 'Function "%s" redefined.';
    7879  SUnknownProcName = 'Unknown proc name "%s".';
    7980  SUnknownModuleType = 'Unknown module name "%s".';
     
    703704      end;
    704705    end else begin
    705       // Create new function
    706       UseFunction := TFunction.Create;
    707       UseFunction.Parent := SourceCode.Parent;
    708       UseFunction.Name := UseName;
    709       UseFunction.FunctionType := FunctionType;
    710       UseFunction.Exported := Exported;
    711       Add(UseFunction);
    712       UseFunction.Parent.Order.Add(UseFunction);
    713       ValidParams := False;
     706      UseFunction := SourceCode.Search(UseName, True);
     707      if not Assigned(UseFunction) then begin
     708        // Create new function
     709        UseFunction := TFunction.Create;
     710        UseFunction.Parent := SourceCode.Parent;
     711        UseFunction.Name := UseName;
     712        UseFunction.FunctionType := FunctionType;
     713        UseFunction.Exported := Exported;
     714        Add(UseFunction);
     715        UseFunction.Parent.Order.Add(UseFunction);
     716        ValidParams := False;
     717      end else begin
     718        if not UseFunction.BodyLoaded then UseFunction.BodyLoaded := True
     719          else begin
     720            ErrorMessage(SFunctionRedefinition, [UseName]);
     721            Exit;
     722          end;
     723      end;
    714724    end;
    715725    with UseFunction do begin
  • trunk/Compiler/Target/Delphi/UProducerPascal.pas

    r61 r63  
    101101    Module.TargetFile := Module.Name + '.dpr';
    102102    EmitLn('program ' + Name + ';');
     103    EmitLn;
     104    EnitLn('{$APPTYPE Console}');
    103105    EmitLn;
    104106    GenerateUses(UsedModules);
     
    505507end;
    506508
    507 
    508 
    509509end.
  • trunk/Compiler/Target/XML/UTargetXML.pas

    r42 r63  
    66
    77uses
    8   Classes, SysUtils, UTarget;
     8  Classes, SysUtils, UTarget, UProducer, USourceCode;
    99
    1010type
     
    1616  end;
    1717
     18  { TProducerXML }
     19
     20  TProducerXML = class(TProducer)
     21  private
     22    procedure GenerateModule(Module: TModule);
     23    procedure GenerateUnit(Module: TModule);
     24    procedure GenerateLibrary(Module: TModule);
     25    procedure GeneratePackage(Module: TModule);
     26  public
     27    procedure AssignToStringList(Target: TStringList); override;
     28    procedure Produce(Module: TModule); override;
     29  end;
     30
     31
    1832implementation
     33
     34{ TProducerXML }
     35
     36procedure TProducerXML.GenerateModule(Module: TModule);
     37begin
     38  Module.TargetFile := Module.Name + '.xml';
     39  if Module is TModuleProgram then
     40  with TModuleProgram(Module) do begin
     41    EmitLn('<?xml version="1.0"?>');
     42    EmitLn('<program>');
     43    //GenerateUses(UsedModules);
     44    //GenerateCommonBlockImplementation(Body, '');
     45    EmitLn('</program>');
     46  end;
     47  if Module is TModuleUnit then GenerateUnit(Module)
     48  else if Module is TModuleLibrary then GenerateLibrary(Module)
     49  else if Module is TModulePackage then GeneratePackage(Module);
     50end;
     51
     52procedure TProducerXML.GenerateUnit(Module: TModule);
     53begin
     54  EmitLn('<?xml version="1.0"?>');
     55  EmitLn('<unit>');
     56  //GenerateUses(UsedModules);
     57  //GenerateCommonBlockImplementation(Body, '');
     58  EmitLn('</unit');
     59end;
     60
     61procedure TProducerXML.GenerateLibrary(Module: TModule);
     62begin
     63  EmitLn('<?xml version="1.0"?>');
     64  EmitLn('<library>');
     65  //GenerateUses(UsedModules);
     66  //GenerateCommonBlockImplementation(Body, '');
     67  EmitLn('</library>');
     68end;
     69
     70procedure TProducerXML.GeneratePackage(Module: TModule);
     71begin
     72  EmitLn('<?xml version="1.0"?>');
     73  EmitLn('<package>');
     74  //GenerateUses(UsedModules);
     75  //GenerateCommonBlockImplementation(Body, '');
     76  EmitLn('</package>');
     77end;
     78
     79procedure TProducerXML.Produce(Module: TModule);
     80begin
     81  GenerateModule(Module);
     82end;
     83
     84procedure TProducerXML.AssignToStringList(Target: TStringList);
     85begin
     86  Target.Assign(TextSource);
     87end;
    1988
    2089{ TTargetXML }
     
    2594  SysName := 'XML';
    2695  Name := 'XML';
     96  Producer := TProducerXML.Create;
    2797end;
    2898
  • trunk/Compiler/USourceCode.pas

    r56 r63  
    305305    ResultType: TType;
    306306    Exported: Boolean;
     307    BodyLoaded: Boolean;
    307308    constructor Create; override;
    308309    destructor Destroy; override;
Note: See TracChangeset for help on using the changeset viewer.