Ignore:
Timestamp:
Nov 5, 2010, 11:31:04 AM (14 years ago)
Author:
george
Message:
  • Added: Typecasting support.
  • Fixed: Function call in expressions.
  • Added: Producer module specify generated file name, extension and placing.
File:
1 edited

Legend:

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

    r5 r6  
    2727      Expressions: TListExpression): Boolean;
    2828    function ParseExpressionFunctionCall(SourceCode: TExpression;
    29       Expressions: TListExpression; var Func: TFunction): Boolean;
     29      Expressions: TListExpression; var Func: TFunctionCall): Boolean;
    3030    function ParseUses(SourceCode: TUsedModuleList; AExported: Boolean): Boolean;
    3131    function ParseModule(ProgramCode: TProgram): TModule;
     
    225225  UseConstant: TConstant;
    226226  UseFunction: TFunction;
     227  FunctionCall: TFunctionCall;
    227228  NewExpression: TExpression;
    228229  Identifier: string;
     
    236237    if Assigned(UseType) then begin
    237238      ReadToken;
     239      if NextToken = '(' then begin
     240        Expect('(');
     241        // Typecasting
     242        NewExpression := TExpression.Create;
     243        NewExpression.CommonBlock := SourceCode.CommonBlock;
     244        NewExpression.NodeType := ntTypecast;
     245        NewExpression.UseType := UseType;
     246        ParseExpression(NewExpression);
     247        Expect(')');
     248      end else
    238249      if (UseType is TTypeRecord) or (UseType is TTypeClass) then begin
    239         // type.variable or type.function
     250        // Type context
    240251        Expect('.');
    241252        Identifier := ReadToken;
    242253        UseVariable := TTypeRecord(UseType).CommonBlock.Variables.Search(Identifier);
    243254        if Assigned(UseVariable) then begin
     255          // Record or class variable
    244256          NewExpression := TExpression.Create;
    245257          NewExpression.CommonBlock := SourceCode.CommonBlock;
     
    250262          UseFunction := TTypeRecord(UseType).CommonBlock.Functions.Search(Identifier);
    251263          if Assigned(UseFunction) then begin
     264            // Record or class functions
     265            ParseExpressionFunctionCall(SourceCode, Expressions, FunctionCall);
    252266            NewExpression := TExpression.Create;
    253267            NewExpression.CommonBlock := SourceCode.CommonBlock;
    254268            NewExpression.NodeType := ntFunction;
    255             NewExpression.FunctionCall := UseFunction;
     269            NewExpression.FunctionCall := FunctionCall;
    256270          end;
    257271        end;
     
    273287    if not Assigned(NewExpression) then begin
    274288      // Function call
    275       ParseExpressionFunctionCall(SourceCode, Expressions, UseFunction);
    276       if Assigned(UseFunction) then begin
     289      ParseExpressionFunctionCall(SourceCode, Expressions, FunctionCall);
     290      if Assigned(FunctionCall) then begin
    277291        NewExpression := TExpression.Create;
    278292        NewExpression.CommonBlock := SourceCode.CommonBlock;
    279293        NewExpression.NodeType := ntFunction;
    280         NewExpression.FunctionCall := UseFunction;
     294        NewExpression.FunctionCall := FunctionCall;
    281295      end;
    282296    end;
     
    319333
    320334function TPascalParser.ParseExpressionFunctionCall(SourceCode: TExpression;
    321   Expressions: TListExpression; var Func: TFunction): Boolean;
     335  Expressions: TListExpression; var Func: TFunctionCall): Boolean;
    322336var
    323337  UseFunction: TFunction;
     338  NewExpression: TExpression;
     339  I: Integer;
    324340begin
    325341  Func := nil;
     
    328344    if Assigned(UseFunction) then begin
    329345      ReadToken;
    330       Func := UseFunction;
     346      Func := TFunctionCall.Create;
     347      Func.CommonBlock := SourceCode.CommonBlock;
     348      Func.FunctionRef := UseFunction;
    331349      if NextToken = '(' then begin
    332350        Expect('(');
    333         while NextToken = ',' do begin
    334           Expect(',');
    335           Expect(')');
    336         end;
     351        for I := 0 to Func.FunctionRef.Parameters.Count - 1 do begin
     352          if I > 0 then Expect(',');
     353          NewExpression := TExpression.Create;
     354          NewExpression.CommonBlock := SourceCode.CommonBlock;
     355          ParseExpression(NewExpression);
     356          Func.ParameterExpression.Add(NewExpression);
     357        end;
     358        Expect(')');
    337359      end;
    338360      Result := True;
Note: See TracChangeset for help on using the changeset viewer.