diff --git a/packages/fcl-passrc/src/pastree.pp b/packages/fcl-passrc/src/pastree.pp index 81a0ce7962..199e1047cb 100644 --- a/packages/fcl-passrc/src/pastree.pp +++ b/packages/fcl-passrc/src/pastree.pp @@ -105,6 +105,7 @@ type TPasElement = class(TPasElementBase) private FData: TObject; + FDocComment: String; FRefCount: LongWord; FName: string; FParent: TPasElement; @@ -133,6 +134,7 @@ type Property Hints : TPasMemberHints Read FHints Write FHints; Property CustomData : TObject Read FData Write FData; Property HintMessage : String Read FHintMessage Write FHintMessage; + Property DocComment : String Read FDocComment Write FDocComment; end; TPasExprKind = (pekIdent, pekNumber, pekString, pekSet, pekNil, pekBoolConst, pekRange, @@ -1306,7 +1308,7 @@ end; function TPasElement.ElementTypeName: string; begin Result := SPasTreeElement end; -function TPasElement.HintsString: String; +Function TPasElement.HintsString: String; Var H : TPasmemberHint; @@ -1567,7 +1569,7 @@ begin end; end; -function TPasElement.GetDeclaration (full : boolean): string; +function TPasElement.GetDeclaration(full: Boolean): string; begin if Full then diff --git a/packages/fcl-passrc/src/pparser.pp b/packages/fcl-passrc/src/pparser.pp index bf861e95c7..d801bc2748 100644 --- a/packages/fcl-passrc/src/pparser.pp +++ b/packages/fcl-passrc/src/pparser.pp @@ -68,11 +68,14 @@ type TPasParserLogHandler = Procedure (Sender : TObject; Const Msg : String) of object; TPParserLogEvent = (pleInterface,pleImplementation); TPParserLogEvents = set of TPParserLogEvent; + TPasParser = Class; { TPasTreeContainer } TPasTreeContainer = class private + FCurrentParser: TPasParser; + FNeedComments: Boolean; FOnLog: TPasParserLogHandler; FPParserLogEvents: TPParserLogEvents; FScannerLogEvents: TPScannerLogEvents; @@ -97,6 +100,8 @@ type Property ScannerLogEvents : TPScannerLogEvents Read FScannerLogEvents Write FScannerLogEvents; Property ParserLogEvents : TPParserLogEvents Read FPParserLogEvents Write FPParserLogEvents; Property OnLog : TPasParserLogHandler Read FOnLog Write FOnLog; + Property CurrentParser : TPasParser Read FCurrentParser; + Property NeedComments : Boolean Read FNeedComments Write FNeedComments; end; EParserError = class(Exception) @@ -131,9 +136,12 @@ type FEngine: TPasTreeContainer; FCurToken: TToken; FCurTokenString: String; + FCurComments : TStrings; + FSavedComments : String; // UngetToken support: FTokenBuffer: array[0..1] of TToken; FTokenStringBuffer: array[0..1] of String; + FCommentsBuffer: array[0..1] of TStrings; FTokenBufferIndex: Integer; // current index in FTokenBuffer FTokenBufferSize: Integer; // maximum valid index in FTokenBuffer FDumpIndent : String; @@ -146,6 +154,8 @@ type procedure ParseClassLocalTypes(AType: TPasClassType; AVisibility: TPasMemberVisibility); procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean); protected + Function SaveComments : String; + Function SaveComments(Const AValue : String) : String; function LogEvent(E : TPParserLogEvent) : Boolean; inline; Procedure DoLog(Const Msg : String; SkipSourceInfo : Boolean = False);overload; Procedure DoLog(Const Fmt : String; Args : Array of const;SkipSourceInfo : Boolean = False);overload; @@ -182,9 +192,12 @@ type function CheckIfOverloaded(AParent: TPasElement; const AName: String): TPasElement; public constructor Create(AScanner: TPascalScanner; AFileResolver: TBaseFileResolver; AEngine: TPasTreeContainer); + Destructor Destroy; override; // General parsing routines function CurTokenName: String; function CurTokenText: String; + Function CurComments : TStrings; + Function SavedComments : String; procedure NextToken; // read next non whitespace, non space procedure UngetToken; procedure CheckToken(tk: TToken); @@ -539,6 +552,23 @@ begin FScanner := AScanner; FFileResolver := AFileResolver; FEngine := AEngine; + FCommentsBuffer[0]:=TStringList.Create; + FCommentsBuffer[1]:=TStringList.Create; + if Assigned(FEngine) then + begin + FEngine.FCurrentParser:=Self; + If FEngine.NeedComments then + FScanner.SkipComments:=Not FEngine.NeedComments; + end; +end; + +Destructor TPasParser.Destroy; +begin + FreeAndNil(FCommentsBuffer[0]); + FreeAndNil(FCommentsBuffer[1]); + if Assigned(FEngine) then + FEngine.FCurrentParser:=Nil; + inherited Destroy; end; function TPasParser.CurTokenName: String; @@ -559,13 +589,27 @@ begin end; end; +Function TPasParser.CurComments: TStrings; +begin + Result:=FCurComments; +end; + +Function TPasParser.SavedComments: String; +begin + Result:=FSavedComments; +end; + procedure TPasParser.NextToken; + +Var + T : TStrings; begin if FTokenBufferIndex < FTokenBufferSize then begin // Get token from buffer FCurToken := FTokenBuffer[FTokenBufferIndex]; FCurTokenString := FTokenStringBuffer[FTokenBufferIndex]; + FCurComments:=FCommentsBuffer[FTokenBufferIndex]; Inc(FTokenBufferIndex); //writeln('TPasParser.NextToken From Buf ',CurTokenText,' id=',FTokenBufferIndex); end else @@ -573,16 +617,22 @@ begin { We have to fetch a new token. But first check, wether there is space left in the token buffer.} if FTokenBufferSize = 2 then - begin + begin FTokenBuffer[0] := FTokenBuffer[1]; FTokenStringBuffer[0] := FTokenStringBuffer[1]; + T:=FCommentsBuffer[0]; + FCommentsBuffer[0]:=FCommentsBuffer[1]; + FCommentsBuffer[1]:=T; Dec(FTokenBufferSize); Dec(FTokenBufferIndex); - end; + end; // Fetch new token try + FCommentsBuffer[FTokenBufferSize].Clear; repeat FCurToken := Scanner.FetchToken; + if FCurToken=tkComment then + FCommentsBuffer[FTokenBufferSize].Add(Scanner.CurTokenString); until not (FCurToken in WhitespaceTokensToIgnore); except on e: EScannerError do @@ -592,9 +642,10 @@ begin FCurTokenString := Scanner.CurTokenString; FTokenBuffer[FTokenBufferSize] := FCurToken; FTokenStringBuffer[FTokenBufferSize] := FCurTokenString; + FCurComments:=FCommentsBuffer[FTokenBufferSize]; Inc(FTokenBufferSize); Inc(FTokenBufferIndex); - //writeln('TPasParser.NextToken New ',CurTokenText,' id=',FTokenBufferIndex); + // writeln('TPasParser.NextToken New ',CurTokenText,' id=',FTokenBufferIndex,' comments = ',FCurComments.text); end; end; @@ -609,9 +660,11 @@ begin begin FCurToken := FTokenBuffer[FTokenBufferIndex-1]; FCurTokenString := FTokenStringBuffer[FTokenBufferIndex-1]; + FCurComments:=FCommentsBuffer[FTokenBufferIndex-1]; end else begin FCurToken := tkWhitespace; FCurTokenString := ''; + FCurComments.Clear; end; //writeln('TPasParser.UngetToken ',CurTokenText,' id=',FTokenBufferIndex); end; @@ -636,7 +689,7 @@ begin Result := CurTokenString; end; -function TPasParser.CurTokenIsIdentifier(Const S: String): Boolean; +Function TPasParser.CurTokenIsIdentifier(Const S: String): Boolean; begin Result:=(Curtoken=tkidentifier) and (CompareText(S,CurtokenText)=0); end; @@ -658,13 +711,14 @@ begin Result:=IsCurTokenHint(dummy); end; -function TPasParser.TokenIsCallingConvention(S: String; - out CC: TCallingConvention): Boolean; +Function TPasParser.TokenIsCallingConvention(S: String; out + CC: TCallingConvention): Boolean; begin Result:=IsCallingConvention(S,CC); end; -function TPasParser.TokenIsProcedureModifier(Parent : TPasElement; S: String; out Pm: TProcedureModifier): Boolean; +Function TPasParser.TokenIsProcedureModifier(Parent: TPasElement; S: String; + Out Pm: TProcedureModifier): Boolean; begin Result:=IsModifier(S,PM); if result and (pm in [pmPublic,pmForward]) then @@ -707,7 +761,7 @@ begin ExpectToken(tkSemiColon); end; -Function TPasParser.CheckPackMode : TPackMode; +function TPasParser.CheckPackMode: TPackMode; begin NextToken; @@ -750,7 +804,8 @@ begin AName:=SimpleTypeCaseNames[I]; end; -function TPasParser.ParseStringType(Parent : TPasElement; Const TypeName : String) : TPasAliasType; +function TPasParser.ParseStringType(Parent: TPasElement; const TypeName: String + ): TPasAliasType; Var S : String; @@ -878,17 +933,20 @@ begin end; end; -function TPasParser.ParseEnumType(Parent : TPasElement; Const TypeName : String) : TPasEnumType; +function TPasParser.ParseEnumType(Parent: TPasElement; const TypeName: String + ): TPasEnumType; Var EnumValue: TPasEnumValue; begin + Writeln('Current comments : ',SavedComments); Result := TPasEnumType(CreateElement(TPasEnumType, TypeName, Parent)); try while True do begin NextToken; + SaveComments; EnumValue := TPasEnumValue(CreateElement(TPasEnumValue, CurTokenString, Result)); Result.Values.Add(EnumValue); NextToken; @@ -913,7 +971,8 @@ begin end; end; -function TPasParser.ParseSetType(Parent: TPasElement; Const TypeName : String): TPasSetType; +function TPasParser.ParseSetType(Parent: TPasElement; const TypeName: String + ): TPasSetType; begin Result := TPasSetType(CreateElement(TPasSetType, TypeName, Parent)); @@ -1558,7 +1617,8 @@ begin end; end; -Function TPasParser.CheckOverloadList(AList : TFPList; AName : String; Out OldMember : TPasElement) : TPasOverloadedProc; +function TPasParser.CheckOverloadList(AList: TFPList; AName: String; out + OldMember: TPasElement): TPasOverloadedProc; Var I : Integer; @@ -1578,6 +1638,8 @@ begin Result:=TPasOverloadedProc.Create(AName, OldMember.Parent); Result.Visibility:=OldMember.Visibility; Result.Overloads.Add(OldMember); + Result.SourceFilename:=OldMember.SourceFilename; + Result.SourceLinenumber:=OldMember.SourceLinenumber; AList[i] := Result; end; end; @@ -1638,6 +1700,7 @@ procedure TPasParser.ParseMain(var Module: TPasModule); begin Module:=nil; NextToken; + SaveComments; case CurToken of tkUnit: ParseUnit(Module); @@ -1836,7 +1899,8 @@ begin UngetToken; end; -Function TPasParser.GetProcTypeFromToken(tk : TToken; IsClass : Boolean = False) : TProcType; +function TPasParser.GetProcTypeFromToken(tk: TToken; IsClass: Boolean + ): TProcType; begin Case tk of @@ -1942,12 +2006,14 @@ begin CurBlock := declProperty; tkProcedure, tkFunction, tkConstructor, tkDestructor,tkOperator: begin + SaveComments; pt:=GetProcTypeFromToken(CurToken); AddProcOrFunction(Declarations, ParseProcedureOrFunctionDecl(Declarations, pt)); CurBlock := declNone; end; tkClass: begin + SaveComments; NextToken; If CurToken in [tkprocedure,tkFunction,tkConstructor, tkDestructor] then begin @@ -1960,6 +2026,7 @@ begin end; tkIdentifier: begin + SaveComments; case CurBlock of declConst: begin @@ -2153,6 +2220,7 @@ end; // Starts after the variable name function TPasParser.ParseConstDecl(Parent: TPasElement): TPasConst; begin + SaveComments; Result := TPasConst(CreateElement(TPasConst, CurTokenString, Parent)); try NextToken; @@ -2174,6 +2242,7 @@ end; // Starts after the variable name function TPasParser.ParseResourcestringDecl(Parent: TPasElement): TPasResString; begin + SaveComments; Result := TPasResString(CreateElement(TPasResString, CurTokenString, Parent)); try ExpectToken(tkEqual); @@ -2205,7 +2274,8 @@ begin end; // Starts after the type name -Function TPasParser.ParseRangeType(AParent : TPasElement; Const TypeName : String; Full : Boolean = True) : TPasRangeType; +function TPasParser.ParseRangeType(AParent: TPasElement; + Const TypeName: String; Full: Boolean): TPasRangeType; Var PE : TPasExpr; @@ -2259,7 +2329,8 @@ begin until (CurToken=tkSemicolon); end; -Function TPasParser.ParseSpecializeType(Parent : TPasElement; Const TypeName : String) : TPasClassType; +function TPasParser.ParseSpecializeType(Parent: TPasElement; + Const TypeName: String): TPasClassType; begin Result := TPasClassType(Engine.CreateElement(TPasClassType, TypeName, Parent, Scanner.CurFilename, Scanner.CurRow)); @@ -2274,7 +2345,8 @@ begin end; end; -Function TPasParser.ParseProcedureType(Parent : TPasElement; Const TypeName : String; Const PT : TProcType) : TPasProcedureType; +function TPasParser.ParseProcedureType(Parent: TPasElement; + const TypeName: String; const PT: TProcType): TPasProcedureType; begin if PT in [ptFunction,ptClassFunction] then @@ -2299,7 +2371,8 @@ begin Result:=ParseType(Parent,TypeName,True); end; -Function TPasParser.GetVariableValueAndLocation(Parent : TPasElement; out Value : TPasExpr; Out Location : String) : Boolean; +function TPasParser.GetVariableValueAndLocation(Parent: TPasElement; Out + Value: TPasExpr; Out Location: String): Boolean; begin Value:=Nil; @@ -2329,7 +2402,8 @@ begin UngetToken; end; -Function TPasParser.GetVariableModifiers(Out Varmods : TVariableModifiers; Out Libname,ExportName : string) : string; +function TPasParser.GetVariableModifiers(Out VarMods: TVariableModifiers; Out + Libname, ExportName: string): string; Var S : String; @@ -2399,11 +2473,12 @@ var VarEl: TPasVariable; H : TPasMemberHints; varmods: TVariableModifiers; - Mods,Loc,alibname,aexpname : string; + D,Mods,Loc,alibname,aexpname : string; begin VarNames := TStringList.Create; try + D:=SaveComments; // This means we support only one comment per 'list'. Repeat VarNames.Add(CurTokenString); NextToken; @@ -2425,6 +2500,7 @@ begin Mods:=GetVariableModifiers(varmods,alibname,aexpname) else NextToken; + SaveComments(D); for i := 0 to VarNames.Count - 1 do begin VarEl:=TPasVariable(CreateElement(TPasVariable,VarNames[i],Parent,AVisibility)); @@ -2450,12 +2526,25 @@ begin end; end; +Function TPasParser.SaveComments: String; +begin + if Engine.NeedComments then + FSavedComments:=CurComments.Text; // Expensive, so don't do unless needed. + Result:=FSavedComments; +end; + +Function TPasParser.SaveComments(Const AValue: String): String; +begin + FSavedComments:=AValue; + Result:=FSavedComments; +end; + function TPasParser.LogEvent(E: TPParserLogEvent): Boolean; begin Result:=E in FLogEvents; end; -procedure TPasParser.DoLog(const Msg: String; SkipSourceInfo: Boolean); +Procedure TPasParser.DoLog(Const Msg: String; SkipSourceInfo: Boolean); begin If Assigned(FOnLog) then if SkipSourceInfo or not assigned(scanner) then @@ -2464,7 +2553,7 @@ begin FOnLog(Self,Format('%s(%d) : %s',[Scanner.CurFilename,SCanner.CurRow,Msg])); end; -procedure TPasParser.DoLog(const Fmt: String; Args: array of const; +Procedure TPasParser.DoLog(Const Fmt: String; Args: Array of const; SkipSourceInfo: Boolean); begin DoLog(Format(Fmt,Args),SkipSourceInfo); @@ -2595,7 +2684,8 @@ begin end; -Function TPasParser.CheckProcedureArgs(Parent : TPasElement; Args : TFPList; Mandatory : Boolean) : boolean; +function TPasParser.CheckProcedureArgs(Parent: TPasElement; Args: TFPList; + Mandatory: Boolean): boolean; begin NextToken; @@ -3500,7 +3590,7 @@ begin end; // Starts after the "procedure" or "function" token -Function TPasParser.GetProcedureClass(ProcType : TProcType) : TPTreeElement; +function TPasParser.GetProcedureClass(ProcType: TProcType): TPTreeElement; begin Case ProcType of @@ -3567,7 +3657,8 @@ begin end; // Current token is the first token after tkOf -Procedure TPasParser.ParseRecordVariantParts(ARec : TPasRecordType; AEndToken: TToken); +procedure TPasParser.ParseRecordVariantParts(ARec: TPasRecordType; + AEndToken: TToken); Var M : TPasRecordType; @@ -3613,7 +3704,8 @@ begin end; // Starts on first token after Record or (. Ends on AEndToken -Procedure TPasParser.ParseRecordFieldList(ARec : TPasRecordType; AEndToken : TToken; AllowMethods : Boolean); +procedure TPasParser.ParseRecordFieldList(ARec: TPasRecordType; + AEndToken: TToken; AllowMethods: Boolean); Var VN : String; @@ -3626,6 +3718,7 @@ begin v:=visPublic; while CurToken<>AEndToken do begin + SaveComments; Case CurToken of tkProperty: begin @@ -3722,7 +3815,8 @@ begin end; end; -Function TPasParser.CheckVisibility(S : String; Var AVisibility :TPasMemberVisibility) : Boolean; +function TPasParser.CheckVisibility(S: String; + var AVisibility: TPasMemberVisibility): Boolean; Var B : Boolean; @@ -3764,7 +3858,8 @@ begin AType.Members.Add(Proc); end; -procedure TPasParser.ParseClassFields(AType: TPasClassType; Const AVisibility : TPasMemberVisibility; IsClassField : Boolean); +procedure TPasParser.ParseClassFields(AType: TPasClassType; + const AVisibility: TPasMemberVisibility; IsClassField: Boolean); Var VarList: TFPList; @@ -3839,11 +3934,13 @@ begin tkType: begin ExpectToken(tkIdentifier); + SaveComments; ParseClassLocalTypes(AType,CurVisibility); end; tkConst: begin ExpectToken(tkIdentifier); + SaveComments; ParseClassLocalConsts(AType,CurVisibility); end; tkVar, @@ -3853,17 +3950,20 @@ begin ParseExc(SParserNoFieldsAllowed); if CurToken=tkVar then ExpectToken(tkIdentifier); + SaveComments; if Not CheckVisibility(CurtokenString,CurVisibility) then ParseClassFields(AType,CurVisibility,false); end; tkProcedure,tkFunction,tkConstructor,tkDestructor: begin + SaveComments; if (Curtoken in [tkConstructor,tkDestructor]) and (AType.ObjKind in [okInterface,okRecordHelper]) then ParseExc(SParserNoConstructorAllowed); ProcessMethod(AType,False,CurVisibility); end; tkclass: begin + SaveComments; NextToken; if CurToken in [tkConstructor,tkDestructor,tkprocedure,tkFunction] then ProcessMethod(AType,True,CurVisibility) @@ -3882,6 +3982,7 @@ begin end; tkProperty: begin + SaveComments; ExpectIdentifier; AType.Members.Add(ParseProperty(AType,CurtokenString,CurVisibility)); end; @@ -3948,7 +4049,9 @@ begin end; end; -function TPasParser.ParseClassDecl(Parent: TPasElement; const AClassName: String; AObjKind: TPasObjKind; PackMode : TPackMode= pmNone): TPasType; +Function TPasParser.ParseClassDecl(Parent: TPasElement; + const AClassName: String; AObjKind: TPasObjKind; PackMode: TPackMode + ): TPasType; Var SourcefileName : string; diff --git a/packages/fcl-passrc/tests/tcbaseparser.pas b/packages/fcl-passrc/tests/tcbaseparser.pas index 16f10a954a..75f095e209 100644 --- a/packages/fcl-passrc/tests/tcbaseparser.pas +++ b/packages/fcl-passrc/tests/tcbaseparser.pas @@ -77,6 +77,7 @@ Type Procedure HaveHint(AHint : TPasMemberHint; AHints : TPasMemberHints); Property Resolver : TStreamResolver Read FResolver; Property Scanner : TPascalScanner Read FScanner; + Property Engine : TTestEngine read FEngine; Property Parser : TTestPasParser read FParser ; Property Source : TStrings Read FSource; Property Module : TPasModule Read FModule; @@ -108,6 +109,11 @@ begin Result.Visibility := AVisibility; Result.SourceFilename := ASourceFilename; Result.SourceLinenumber := ASourceLinenumber; + if NeedComments and Assigned(CurrentParser) then + begin +// Writeln('Saving comment : ',CurrentParser.SavedComments); + Result.DocComment:=CurrentParser.SavedComments; + end; If not Assigned(FList) then FList:=TFPList.Create; FList.Add(Result); diff --git a/packages/fcl-passrc/tests/tcclasstype.pas b/packages/fcl-passrc/tests/tcclasstype.pas index 292f3852dd..e1df996aa8 100644 --- a/packages/fcl-passrc/tests/tcclasstype.pas +++ b/packages/fcl-passrc/tests/tcclasstype.pas @@ -60,12 +60,14 @@ type Property Const2 : TPasConst Index 1 Read GetC; published procedure TestEmpty; + procedure TestEmptyComment; procedure TestEmptyDeprecated; procedure TestEmptyEnd; procedure TestEmptyEndNoParent; Procedure TestOneInterface; Procedure TestTwoInterfaces; Procedure TestOneField; + Procedure TestOneFieldComment; Procedure TestOneVarField; Procedure TestOneClassField; Procedure TestOneFieldVisibility; @@ -83,7 +85,9 @@ type procedure TestHintFieldLibraryError; procedure TestHintFieldUninmplemented; Procedure TestMethodSimple; + Procedure TestMethodSimpleComment; Procedure TestClassMethodSimple; + Procedure TestClassMethodSimpleComment; Procedure TestConstructor; Procedure TestClassConstructor; Procedure TestDestructor; @@ -108,6 +112,7 @@ type Procedure Test2Methods; Procedure Test2MethodsDifferentVisibility; Procedure TestPropertyRedeclare; + Procedure TestPropertyRedeclareComment; Procedure TestPropertyRedeclareDefault; Procedure TestPropertyReadOnly; Procedure TestPropertyReadWrite; @@ -306,11 +311,17 @@ Procedure TTestClassType.ParseClass; begin EndClass; Add('Type'); + if AddComment then + begin + Add('// A comment'); + engine.NeedComments:=True; + end; Add(' '+TrimRight(FDecl.Text)+';'); ParseDeclarations; AssertEquals('One class type definition',1,Declarations.Classes.Count); AssertEquals('First declaration is type definition.',TPasClassType,TObject(Declarations.Classes[0]).ClassType); FClass:=TObject(Declarations.Classes[0]) as TPasClassType; + TheType:=FClass; // So assertcomment can get to it if (FParent<>'') then begin AssertNotNull('Have parent class',TheClass.AncestorType); @@ -323,6 +334,7 @@ begin AssertNull('No helperfortype if not helper',TheClass.HelperForType); if TheClass.Members.Count>0 then FMember1:=TObject(TheClass.Members[0]) as TPaselement; + end; procedure TTestClassType.SetUp; @@ -385,6 +397,13 @@ begin AssertEquals('No members',0,TheClass.Members.Count); end; +procedure TTestClassType.TestEmptyComment; +begin + AddComment:=True; + TestEmpty; + AssertComment; +end; + procedure TTestClassType.TestEmptyDeprecated; begin EndClass('end deprecated'); @@ -438,6 +457,16 @@ begin AssertVisibility; end; +Procedure TTestClassType.TestOneFieldComment; +begin + AddComment:=true; + AddMember('{c}a : integer'); + ParseClass; + AssertNotNull('Have 1 field',Field1); + AssertEquals('field comment','c'+sLineBreak,Field1.DocComment); + AssertVisibility; +end; + Procedure TTestClassType.TestOneVarField; begin StartVisibility(visPublished); @@ -640,6 +669,18 @@ begin AssertEquals('No arguments',0,Method1.ProcType.Args.Count) end; +Procedure TTestClassType.TestMethodSimpleComment; +begin + AddComment:=True; + AddMember('{c} Procedure DoSomething'); + ParseClass; + AssertEquals('1 members',1,TheClass.members.Count); + AssertEquals('Default visibility',visDefault,Method1.Visibility); + AssertNotNull('Have method',Method1); + AssertMemberName('DoSomething'); + AssertEquals('Comment','c'+sLineBreak,Method1.DocComment); +end; + Procedure TTestClassType.TestClassMethodSimple; begin AddMember('Class Procedure DoSomething'); @@ -654,6 +695,14 @@ begin AssertEquals('No arguments',0,TPasClassProcedure(Members[0]).ProcType.Args.Count) end; +Procedure TTestClassType.TestClassMethodSimpleComment; +begin + AddComment:=True; + AddMember('{c} Class Procedure DoSomething'); + ParseClass; + AssertEquals('Comment','c'+sLineBreak,Members[0].DocComment); +end; + Procedure TTestClassType.TestConstructor; begin AddMember('Constructor Create'); @@ -967,6 +1016,16 @@ begin Assertequals('No default value','',Property1.DefaultValue); end; +Procedure TTestClassType.TestPropertyRedeclareComment; +begin + StartVisibility(visPublished); + AddComment:=True; + AddMember('{p} Property Something'); + ParseClass; + AssertProperty(Property1,visPublished,'Something','','','','',0,False,False); + AssertEquals('comment','p'+sLineBreak,Property1.DocComment); +end; + Procedure TTestClassType.TestPropertyRedeclareDefault; begin StartVisibility(visPublic); diff --git a/packages/fcl-passrc/tests/tcprocfunc.pas b/packages/fcl-passrc/tests/tcprocfunc.pas index bc36f2103c..ba64abe9d4 100644 --- a/packages/fcl-passrc/tests/tcprocfunc.pas +++ b/packages/fcl-passrc/tests/tcprocfunc.pas @@ -13,6 +13,7 @@ type TTestProcedureFunction= class(TTestParser) private + FAddComment: Boolean; FFunc: TPasFunction; FHint: String; FProc: TPasProcedure; @@ -35,6 +36,8 @@ type protected procedure SetUp; override; procedure TearDown; override; + Procedure AssertComment; + Property AddComment : Boolean Read FAddComment Write FAddComment; Property Hint : String Read FHint Write FHint; Property Proc : TPasProcedure Read FProc; Property ProcType : TPasProcedureType Read GetPT; @@ -42,7 +45,9 @@ type Property FuncType : TPasFunctionType Read GetFT; published procedure TestEmptyProcedure; + procedure TestEmptyProcedureComment; Procedure TestEmptyFunction; + Procedure TestEmptyFunctionComment; procedure TestEmptyProcedureDeprecated; Procedure TestEmptyFunctionDeprecated; procedure TestEmptyProcedurePlatform; @@ -156,7 +161,8 @@ type implementation -procedure TTestProcedureFunction.AddDeclaration(Const ASource : string; Const AHint : String = ''); +procedure TTestProcedureFunction.AddDeclaration(const ASource: string; + const AHint: String); Var D : String; @@ -176,16 +182,24 @@ begin Result:=Proc.ProcType; end; -Function TTestProcedureFunction.ParseProcedure(Const ASource : string; Const AHint : String = '') : TPasProcedure; +function TTestProcedureFunction.ParseProcedure(const ASource: string; + const AHint: String): TPasProcedure; begin + If AddComment then + begin + Add('// A comment'); + Engine.NeedComments:=True; + end; AddDeclaration('procedure A '+ASource,AHint); Self.ParseProcedure; Result:=Fproc; + If AddComment then + AssertComment; end; -procedure TTestProcedureFunction.ParseProcedure; +Procedure TTestProcedureFunction.ParseProcedure; begin // Writeln(source.text); @@ -216,7 +230,7 @@ begin AssertEquals('Correct function result type name',AResult,FuncType.ResultEl.ResultType.Name); end; -procedure TTestProcedureFunction.ParseFunction; +Procedure TTestProcedureFunction.ParseFunction; begin // Writeln(source.text); ParseDeclarations; @@ -261,7 +275,9 @@ begin AssertEquals('Not is nested',False,P.ProcType.IsNested); end; -Function TTestProcedureFunction.BaseAssertArg(ProcType : TPasProcedureType; AIndex : Integer; AName : String; AAccess : TArgumentAccess; AValue : String='') : TPasArgument; +function TTestProcedureFunction.BaseAssertArg(ProcType: TPasProcedureType; + AIndex: Integer; AName: String; AAccess: TArgumentAccess; AValue: String + ): TPasArgument; Var A : TPasArgument; @@ -287,7 +303,9 @@ begin Result:=A; end; -procedure TTestProcedureFunction.AssertArg(ProcType : TPasProcedureType; AIndex : Integer; AName : String; AAccess : TArgumentAccess; Const TypeName : String; AValue : String=''); +procedure TTestProcedureFunction.AssertArg(ProcType: TPasProcedureType; + AIndex: Integer; AName: String; AAccess: TArgumentAccess; + const TypeName: String; AValue: String); Var A : TPasArgument; @@ -343,19 +361,31 @@ begin AssertProc([],ccDefault,0); end; -procedure TTestProcedureFunction.TestEmptyFunction; +procedure TTestProcedureFunction.TestEmptyProcedureComment; +begin + AddComment:=True; + TestEmptyProcedure; +end; + +Procedure TTestProcedureFunction.TestEmptyFunction; begin ParseFunction(''); AssertFunc([],ccDefault,0); end; +Procedure TTestProcedureFunction.TestEmptyFunctionComment; +begin + AddComment:=True; + TestEmptyProcedure; +end; + procedure TTestProcedureFunction.TestEmptyProcedureDeprecated; begin ParseProcedure('','deprecated'); AssertProc([],ccDefault,0); end; -procedure TTestProcedureFunction.TestEmptyFunctionDeprecated; +Procedure TTestProcedureFunction.TestEmptyFunctionDeprecated; begin ParseFunction('','deprecated'); AssertFunc([],ccDefault,0); @@ -367,7 +397,7 @@ begin AssertProc([],ccDefault,0); end; -procedure TTestProcedureFunction.TestEmptyFunctionPlatform; +Procedure TTestProcedureFunction.TestEmptyFunctionPlatform; begin ParseFunction('','platform'); AssertFunc([],ccDefault,0); @@ -379,7 +409,7 @@ begin AssertProc([],ccDefault,0); end; -procedure TTestProcedureFunction.TestEmptyFunctionExperimental; +Procedure TTestProcedureFunction.TestEmptyFunctionExperimental; begin ParseFunction('','experimental'); AssertFunc([],ccDefault,0); @@ -391,7 +421,7 @@ begin AssertProc([],ccDefault,0); end; -procedure TTestProcedureFunction.TestEmptyFunctionUnimplemented; +Procedure TTestProcedureFunction.TestEmptyFunctionUnimplemented; begin ParseFunction('','unimplemented'); AssertFunc([],ccDefault,0); @@ -407,7 +437,7 @@ begin AssertArg(ProcType,0,'B',argDefault,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionOneArg; +Procedure TTestProcedureFunction.TestFunctionOneArg; begin ParseFunction('(B : Integer)'); AssertFunc([],ccDefault,1); @@ -421,7 +451,7 @@ begin AssertArg(ProcType,0,'B',argVar,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionOneVarArg; +Procedure TTestProcedureFunction.TestFunctionOneVarArg; begin ParseFunction('(Var B : Integer)'); AssertFunc([],ccDefault,1); @@ -435,7 +465,7 @@ begin AssertArg(ProcType,0,'B',argConst,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionOneConstArg; +Procedure TTestProcedureFunction.TestFunctionOneConstArg; begin ParseFunction('(Const B : Integer)'); AssertFunc([],ccDefault,1); @@ -449,7 +479,7 @@ begin AssertArg(ProcType,0,'B',argOut,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionOneOutArg; +Procedure TTestProcedureFunction.TestFunctionOneOutArg; begin ParseFunction('(Out B : Integer)'); AssertFunc([],ccDefault,1); @@ -463,7 +493,7 @@ begin AssertArg(ProcType,0,'B',argConstRef,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionOneConstRefArg; +Procedure TTestProcedureFunction.TestFunctionOneConstRefArg; begin ParseFunction('(ConstRef B : Integer)'); AssertFunc([],ccDefault,1); @@ -478,7 +508,7 @@ begin AssertArg(ProcType,1,'C',argDefault,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionTwoArgs; +Procedure TTestProcedureFunction.TestFunctionTwoArgs; begin ParseFunction('(B,C : Integer)'); AssertFunc([],ccDefault,2); @@ -494,7 +524,7 @@ begin AssertArg(ProcType,1,'C',argDefault,'Integer',''); end; -procedure TTestProcedureFunction.TestFunctionTwoArgsSeparate; +Procedure TTestProcedureFunction.TestFunctionTwoArgsSeparate; begin ParseFunction('(B : Integer;C : Integer)'); AssertFunc([],ccDefault,2); @@ -509,7 +539,7 @@ begin AssertArg(ProcType,0,'B',argDefault,'Integer','1'); end; -procedure TTestProcedureFunction.TestFunctionOneArgDefault; +Procedure TTestProcedureFunction.TestFunctionOneArgDefault; begin ParseFunction('(B : Integer = 1)'); AssertFunc([],ccDefault,1); @@ -523,7 +553,7 @@ begin AssertArg(ProcType,0,'B',argDefault,'MySet','[1, 2]'); end; -procedure TTestProcedureFunction.TestFunctionOneArgDefaultSet; +Procedure TTestProcedureFunction.TestFunctionOneArgDefaultSet; begin ParseFunction('(B : MySet = [1,2])'); AssertFunc([],ccDefault,1); @@ -537,7 +567,7 @@ begin AssertArg(ProcType,0,'B',argDefault,'Integer','1 + 2'); end; -procedure TTestProcedureFunction.TestFunctionOneArgDefaultExpr; +Procedure TTestProcedureFunction.TestFunctionOneArgDefaultExpr; begin ParseFunction('(B : Integer = 1 + 2)'); AssertFunc([],ccDefault,1); @@ -552,7 +582,7 @@ begin AssertArg(ProcType,1,'C',argDefault,'Integer','2'); end; -procedure TTestProcedureFunction.TestFunctionTwoArgsDefault; +Procedure TTestProcedureFunction.TestFunctionTwoArgsDefault; begin ParseFunction('(B : Integer = 1; C : Integer = 2)'); AssertFunc([],ccDefault,2); @@ -567,7 +597,7 @@ begin AssertArg(ProcType,0,'B',argVar,'',''); end; -procedure TTestProcedureFunction.TestFunctionOneUntypedVarArg; +Procedure TTestProcedureFunction.TestFunctionOneUntypedVarArg; begin ParseFunction('(Var B)'); AssertFunc([],ccDefault,1); @@ -582,7 +612,7 @@ begin AssertArg(ProcType,1,'C',argVar,'',''); end; -procedure TTestProcedureFunction.TestFunctionTwoUntypedVarArgs; +Procedure TTestProcedureFunction.TestFunctionTwoUntypedVarArgs; begin ParseFunction('(Var B; Var C)'); AssertFunc([],ccDefault,2); @@ -597,7 +627,7 @@ begin AssertArg(ProcType,0,'B',argConst,'',''); end; -procedure TTestProcedureFunction.TestFunctionOneUntypedConstArg; +Procedure TTestProcedureFunction.TestFunctionOneUntypedConstArg; begin ParseFunction('(Const B)'); AssertFunc([],ccDefault,1); @@ -612,7 +642,7 @@ begin AssertArg(ProcType,1,'C',argConst,'',''); end; -procedure TTestProcedureFunction.TestFunctionTwoUntypedConstArgs; +Procedure TTestProcedureFunction.TestFunctionTwoUntypedConstArgs; begin ParseFunction('(Const B; Const C)'); AssertFunc([],ccDefault,2); @@ -627,7 +657,7 @@ begin AssertArrayArg(ProcType,0,'B',argDefault,'Integer'); end; -procedure TTestProcedureFunction.TestFunctionOpenArrayArg; +Procedure TTestProcedureFunction.TestFunctionOpenArrayArg; begin ParseFunction('(B : Array of Integer)'); AssertFunc([],ccDefault,1); @@ -642,7 +672,7 @@ begin AssertArrayArg(ProcType,1,'C',argDefault,'Integer'); end; -procedure TTestProcedureFunction.TestFunctionTwoOpenArrayArgs; +Procedure TTestProcedureFunction.TestFunctionTwoOpenArrayArgs; begin ParseFunction('(B : Array of Integer;C : Array of Integer)'); AssertFunc([],ccDefault,2); @@ -657,7 +687,7 @@ begin AssertArrayArg(ProcType,0,'B',argConst,'Integer'); end; -procedure TTestProcedureFunction.TestFunctionConstOpenArrayArg; +Procedure TTestProcedureFunction.TestFunctionConstOpenArrayArg; begin ParseFunction('(Const B : Array of Integer)'); AssertFunc([],ccDefault,1); @@ -671,7 +701,7 @@ begin AssertArrayArg(ProcType,0,'B',argVar,'Integer'); end; -procedure TTestProcedureFunction.TestFunctionVarOpenArrayArg; +Procedure TTestProcedureFunction.TestFunctionVarOpenArrayArg; begin ParseFunction('(Var B : Array of Integer)'); AssertFunc([],ccDefault,1); @@ -685,7 +715,7 @@ begin AssertArrayArg(ProcType,0,'B',argDefault,''); end; -procedure TTestProcedureFunction.TestFunctionArrayOfConstArg; +Procedure TTestProcedureFunction.TestFunctionArrayOfConstArg; begin ParseFunction('(B : Array of Const)'); AssertFunc([],ccDefault,1); @@ -699,100 +729,100 @@ begin AssertArrayArg(ProcType,0,'B',argConst,''); end; -procedure TTestProcedureFunction.TestFunctionConstArrayOfConstArg; +Procedure TTestProcedureFunction.TestFunctionConstArrayOfConstArg; begin ParseFunction('(Const B : Array of Const)'); AssertFunc([],ccDefault,1); AssertArrayArg(FuncType,0,'B',argConst,''); end; -procedure TTestProcedureFunction.TestProcedureCdecl; +Procedure TTestProcedureFunction.TestProcedureCdecl; begin ParseProcedure('; cdecl'); AssertProc([],ccCdecl,0); end; -procedure TTestProcedureFunction.TestFunctionCdecl; +Procedure TTestProcedureFunction.TestFunctionCdecl; begin ParseFunction('','','',ccCdecl); AssertFunc([],ccCdecl,0); end; -procedure TTestProcedureFunction.TestProcedureCdeclDeprecated; +Procedure TTestProcedureFunction.TestProcedureCdeclDeprecated; begin ParseProcedure('; cdecl;','deprecated'); AssertProc([],ccCdecl,0); end; -procedure TTestProcedureFunction.TestFunctionCdeclDeprecated; +Procedure TTestProcedureFunction.TestFunctionCdeclDeprecated; begin ParseFunction('','','deprecated',ccCdecl); AssertFunc([],ccCdecl,0); end; -procedure TTestProcedureFunction.TestProcedureSafeCall; +Procedure TTestProcedureFunction.TestProcedureSafeCall; begin ParseProcedure('; safecall;',''); AssertProc([],ccSafeCall,0); end; -procedure TTestProcedureFunction.TestFunctionSafeCall; +Procedure TTestProcedureFunction.TestFunctionSafeCall; begin ParseFunction('','','',ccSafecall); AssertFunc([],ccSafecall,0); end; -procedure TTestProcedureFunction.TestProcedurePascal; +Procedure TTestProcedureFunction.TestProcedurePascal; begin ParseProcedure('; pascal;',''); AssertProc([],ccPascal,0); end; -procedure TTestProcedureFunction.TestFunctionPascal; +Procedure TTestProcedureFunction.TestFunctionPascal; begin ParseFunction('','','',ccPascal); AssertFunc([],ccPascal,0); end; -procedure TTestProcedureFunction.TestProcedureStdCall; +Procedure TTestProcedureFunction.TestProcedureStdCall; begin ParseProcedure('; stdcall;',''); AssertProc([],ccstdcall,0); end; -procedure TTestProcedureFunction.TestFunctionStdCall; +Procedure TTestProcedureFunction.TestFunctionStdCall; begin ParseFunction('','','',ccStdCall); AssertFunc([],ccStdCall,0); end; -procedure TTestProcedureFunction.TestProcedureOldFPCCall; +Procedure TTestProcedureFunction.TestProcedureOldFPCCall; begin ParseProcedure('; oldfpccall;',''); AssertProc([],ccoldfpccall,0); end; -procedure TTestProcedureFunction.TestFunctionOldFPCCall; +Procedure TTestProcedureFunction.TestFunctionOldFPCCall; begin ParseFunction('','','',ccOldFPCCall); AssertFunc([],ccOldFPCCall,0); end; -procedure TTestProcedureFunction.TestProcedurePublic; +Procedure TTestProcedureFunction.TestProcedurePublic; begin ParseProcedure('; public name ''myfunc'';',''); AssertProc([pmPublic],ccDefault,0); AssertExpression('Public name',Proc.PublicName,pekString,'''myfunc'''); end; -procedure TTestProcedureFunction.TestProcedurePublicIdent; +Procedure TTestProcedureFunction.TestProcedurePublicIdent; begin ParseProcedure('; public name exportname;',''); AssertProc([pmPublic],ccDefault,0); AssertExpression('Public name',Proc.PublicName,pekIdent,'exportname'); end; -procedure TTestProcedureFunction.TestFunctionPublic; +Procedure TTestProcedureFunction.TestFunctionPublic; begin AddDeclaration('function A : Integer; public name exportname'); ParseFunction; @@ -800,14 +830,14 @@ begin AssertExpression('Public name',Func.PublicName,pekIdent,'exportname'); end; -procedure TTestProcedureFunction.TestProcedureCdeclPublic; +Procedure TTestProcedureFunction.TestProcedureCdeclPublic; begin ParseProcedure('; cdecl; public name exportname;',''); AssertProc([pmPublic],ccCDecl,0); AssertExpression('Public name',Proc.PublicName,pekIdent,'exportname'); end; -procedure TTestProcedureFunction.TestFunctionCdeclPublic; +Procedure TTestProcedureFunction.TestFunctionCdeclPublic; begin AddDeclaration('function A : Integer; cdecl; public name exportname'); ParseFunction; @@ -815,58 +845,58 @@ begin AssertExpression('Public name',Func.PublicName,pekIdent,'exportname'); end; -procedure TTestProcedureFunction.TestProcedureOverload; +Procedure TTestProcedureFunction.TestProcedureOverload; begin ParseProcedure('; overload;',''); AssertProc([pmOverload],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionOverload; +Procedure TTestProcedureFunction.TestFunctionOverload; begin AddDeclaration('function A : Integer; overload'); ParseFunction; AssertFunc([pmOverload],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureVarargs; +Procedure TTestProcedureFunction.TestProcedureVarargs; begin ParseProcedure('; varargs;',''); AssertProc([pmVarArgs],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionVarArgs; +Procedure TTestProcedureFunction.TestFunctionVarArgs; begin AddDeclaration('function A : Integer; varargs'); ParseFunction; AssertFunc([pmVarArgs],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureCDeclVarargs; +Procedure TTestProcedureFunction.TestProcedureCDeclVarargs; begin ParseProcedure(';cdecl; varargs;',''); AssertProc([pmVarArgs],ccCDecl,0); end; -procedure TTestProcedureFunction.TestFunctionCDeclVarArgs; +Procedure TTestProcedureFunction.TestFunctionCDeclVarArgs; begin AddDeclaration('function A : Integer; cdecl; varargs'); ParseFunction; AssertFunc([pmVarArgs],ccCdecl,0); end; -procedure TTestProcedureFunction.TestProcedureForwardInterface; +Procedure TTestProcedureFunction.TestProcedureForwardInterface; begin AddDeclaration('procedure A; forward;'); AssertException(EParserError,@ParseProcedure); end; -procedure TTestProcedureFunction.TestFunctionForwardInterface; +Procedure TTestProcedureFunction.TestFunctionForwardInterface; begin AddDeclaration('function A : integer; forward;'); AssertException(EParserError,@ParseFunction); end; -procedure TTestProcedureFunction.TestProcedureForward; +Procedure TTestProcedureFunction.TestProcedureForward; begin UseImplementation:=True; AddDeclaration('procedure A; forward;'); @@ -874,7 +904,7 @@ begin AssertProc([pmforward],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionForward; +Procedure TTestProcedureFunction.TestFunctionForward; begin UseImplementation:=True; AddDeclaration('function A : integer; forward;'); @@ -882,7 +912,7 @@ begin AssertFunc([pmforward],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureCdeclForward; +Procedure TTestProcedureFunction.TestProcedureCdeclForward; begin UseImplementation:=True; AddDeclaration('procedure A; cdecl; forward;'); @@ -890,7 +920,7 @@ begin AssertProc([pmforward],ccCDecl,0); end; -procedure TTestProcedureFunction.TestFunctionCDeclForward; +Procedure TTestProcedureFunction.TestFunctionCDeclForward; begin UseImplementation:=True; AddDeclaration('function A : integer; cdecl; forward;'); @@ -898,92 +928,92 @@ begin AssertFunc([pmforward],ccCDecl,0); end; -procedure TTestProcedureFunction.TestProcedureCompilerProc; +Procedure TTestProcedureFunction.TestProcedureCompilerProc; begin ParseProcedure(';compilerproc;',''); AssertProc([pmCompilerProc],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionCompilerProc; +Procedure TTestProcedureFunction.TestFunctionCompilerProc; begin AddDeclaration('function A : Integer; compilerproc'); ParseFunction; AssertFunc([pmCompilerProc],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureCDeclCompilerProc; +Procedure TTestProcedureFunction.TestProcedureCDeclCompilerProc; begin ParseProcedure(';cdecl;compilerproc;',''); AssertProc([pmCompilerProc],ccCDecl,0); end; -procedure TTestProcedureFunction.TestFunctionCDeclCompilerProc; +Procedure TTestProcedureFunction.TestFunctionCDeclCompilerProc; begin AddDeclaration('function A : Integer; cdecl; compilerproc'); ParseFunction; AssertFunc([pmCompilerProc],ccCDecl,0); end; -procedure TTestProcedureFunction.TestProcedureAssembler; +Procedure TTestProcedureFunction.TestProcedureAssembler; begin ParseProcedure(';assembler;',''); AssertProc([pmAssembler],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionAssembler; +Procedure TTestProcedureFunction.TestFunctionAssembler; begin AddDeclaration('function A : Integer; assembler'); ParseFunction; AssertFunc([pmAssembler],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureCDeclAssembler; +Procedure TTestProcedureFunction.TestProcedureCDeclAssembler; begin ParseProcedure(';cdecl;assembler;',''); AssertProc([pmAssembler],ccCDecl,0); end; -procedure TTestProcedureFunction.TestFunctionCDeclAssembler; +Procedure TTestProcedureFunction.TestFunctionCDeclAssembler; begin AddDeclaration('function A : Integer; cdecl; assembler'); ParseFunction; AssertFunc([pmAssembler],ccCDecl,0); end; -procedure TTestProcedureFunction.TestProcedureExport; +Procedure TTestProcedureFunction.TestProcedureExport; begin ParseProcedure(';export;',''); AssertProc([pmExport],ccDefault,0); end; -procedure TTestProcedureFunction.TestFunctionExport; +Procedure TTestProcedureFunction.TestFunctionExport; begin AddDeclaration('function A : Integer; export'); ParseFunction; AssertFunc([pmExport],ccDefault,0); end; -procedure TTestProcedureFunction.TestProcedureCDeclExport; +Procedure TTestProcedureFunction.TestProcedureCDeclExport; begin ParseProcedure('cdecl;export;',''); AssertProc([pmExport],ccCDecl,0); end; -procedure TTestProcedureFunction.TestFunctionCDeclExport; +Procedure TTestProcedureFunction.TestFunctionCDeclExport; begin AddDeclaration('function A : Integer; cdecl; export'); ParseFunction; AssertFunc([pmExport],ccCDecl,0); end; -procedure TTestProcedureFunction.TestProcedureExternal; +Procedure TTestProcedureFunction.TestProcedureExternal; begin ParseProcedure(';external',''); AssertProc([pmExternal],ccDefault,0); AssertNull('No Library name expression',Proc.LibraryExpr); end; -procedure TTestProcedureFunction.TestFunctionExternal; +Procedure TTestProcedureFunction.TestFunctionExternal; begin AddDeclaration('function A : Integer; external'); ParseFunction; @@ -991,14 +1021,14 @@ begin AssertNull('No Library name expression',Func.LibraryExpr); end; -procedure TTestProcedureFunction.TestProcedureExternalLibName; +Procedure TTestProcedureFunction.TestProcedureExternalLibName; begin ParseProcedure(';external ''libname''',''); AssertProc([pmExternal],ccDefault,0); AssertExpression('Library name expression',Proc.LibraryExpr,pekString,'''libname'''); end; -procedure TTestProcedureFunction.TestFunctionExternalLibName; +Procedure TTestProcedureFunction.TestFunctionExternalLibName; begin AddDeclaration('function A : Integer; external ''libname'''); ParseFunction; @@ -1006,7 +1036,7 @@ begin AssertExpression('Library name expression',Func.LibraryExpr,pekString,'''libname'''); end; -procedure TTestProcedureFunction.TestProcedureExternalLibNameName; +Procedure TTestProcedureFunction.TestProcedureExternalLibNameName; begin ParseProcedure(';external ''libname'' name ''symbolname''',''); AssertProc([pmExternal],ccDefault,0); @@ -1014,7 +1044,7 @@ begin AssertExpression('Library symbol expression',Proc.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestFunctionExternalLibNameName; +Procedure TTestProcedureFunction.TestFunctionExternalLibNameName; begin AddDeclaration('function A : Integer; external ''libname'' name ''symbolname'''); ParseFunction; @@ -1023,7 +1053,7 @@ begin AssertExpression('Library symbol expression',Func.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestProcedureExternalName; +Procedure TTestProcedureFunction.TestProcedureExternalName; begin ParseProcedure(';external name ''symbolname''',''); AssertProc([pmExternal],ccDefault,0); @@ -1031,7 +1061,7 @@ begin AssertExpression('Library symbol expression',Proc.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestFunctionExternalName; +Procedure TTestProcedureFunction.TestFunctionExternalName; begin AddDeclaration('function A : Integer; external name ''symbolname'''); ParseFunction; @@ -1040,14 +1070,14 @@ begin AssertExpression('Library symbol expression',Func.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestProcedureCdeclExternal; +Procedure TTestProcedureFunction.TestProcedureCdeclExternal; begin ParseProcedure('; cdecl; external',''); AssertProc([pmExternal],ccCdecl,0); AssertNull('No Library name expression',Proc.LibraryExpr); end; -procedure TTestProcedureFunction.TestFunctionCdeclExternal; +Procedure TTestProcedureFunction.TestFunctionCdeclExternal; begin AddDeclaration('function A : Integer; cdecl; external'); ParseFunction; @@ -1055,14 +1085,14 @@ begin AssertNull('No Library name expression',Func.LibraryExpr); end; -procedure TTestProcedureFunction.TestProcedureCdeclExternalLibName; +Procedure TTestProcedureFunction.TestProcedureCdeclExternalLibName; begin ParseProcedure('; cdecl; external ''libname''',''); AssertProc([pmExternal],ccCdecl,0); AssertExpression('Library name expression',Proc.LibraryExpr,pekString,'''libname'''); end; -procedure TTestProcedureFunction.TestFunctionCdeclExternalLibName; +Procedure TTestProcedureFunction.TestFunctionCdeclExternalLibName; begin AddDeclaration('function A : Integer; cdecl; external ''libname'''); ParseFunction; @@ -1070,7 +1100,7 @@ begin AssertExpression('Library name expression',Func.LibraryExpr,pekString,'''libname'''); end; -procedure TTestProcedureFunction.TestProcedureCdeclExternalLibNameName; +Procedure TTestProcedureFunction.TestProcedureCdeclExternalLibNameName; begin ParseProcedure('; cdecl; external ''libname'' name ''symbolname''',''); AssertProc([pmExternal],ccCdecl,0); @@ -1078,7 +1108,7 @@ begin AssertExpression('Library symbol expression',Proc.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestFunctionCdeclExternalLibNameName; +Procedure TTestProcedureFunction.TestFunctionCdeclExternalLibNameName; begin AddDeclaration('function A : Integer; cdecl; external ''libname'' name ''symbolname'''); ParseFunction; @@ -1087,7 +1117,7 @@ begin AssertExpression('Library symbol expression',Func.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestProcedureCdeclExternalName; +Procedure TTestProcedureFunction.TestProcedureCdeclExternalName; begin ParseProcedure('; cdecl; external name ''symbolname''',''); AssertProc([pmExternal],ccCdecl,0); @@ -1095,7 +1125,7 @@ begin AssertExpression('Library symbol expression',Proc.LibrarySymbolName,pekString,'''symbolname'''); end; -procedure TTestProcedureFunction.TestFunctionCdeclExternalName; +Procedure TTestProcedureFunction.TestFunctionCdeclExternalName; begin AddDeclaration('function A : Integer; cdecl; external name ''symbolname'''); ParseFunction; @@ -1114,6 +1144,11 @@ begin Inherited; end; +Procedure TTestProcedureFunction.AssertComment; +begin + AssertEquals('Correct comment',' A comment'+sLineBreak,FProc.DocComment); +end; + initialization RegisterTest(TTestProcedureFunction); diff --git a/packages/fcl-passrc/tests/tcstatements.pas b/packages/fcl-passrc/tests/tcstatements.pas index 74a96ac07e..1e1e7cda60 100644 --- a/packages/fcl-passrc/tests/tcstatements.pas +++ b/packages/fcl-passrc/tests/tcstatements.pas @@ -31,12 +31,15 @@ Type Procedure TestEmptyStatement; Procedure TestEmptyStatements; Procedure TestBlock; + Procedure TestBlockComment; + Procedure TestBlock2Comments; Procedure TestAssignment; Procedure TestAssignmentAdd; Procedure TestAssignmentMinus; Procedure TestAssignmentMul; Procedure TestAssignmentDivision; Procedure TestCall; + Procedure TestCallComment; Procedure TestCallQualified; Procedure TestCallQualified2; Procedure TestCallNoArgs; @@ -95,19 +98,19 @@ implementation { TTestStatementParser } -procedure TTestStatementParser.SetUp; +Procedure TTestStatementParser.SetUp; begin inherited SetUp; FVariables:=TStringList.Create; end; -procedure TTestStatementParser.TearDown; +Procedure TTestStatementParser.TearDown; begin FreeAndNil(FVariables); inherited TearDown; end; -procedure TTestStatementParser.AddStatements(ASource: array of string); +procedure TTestStatementParser.AddStatements(ASource: Array of string); Var I :Integer; @@ -124,8 +127,8 @@ begin Add(' '+ASource[i]); end; -procedure TTestStatementParser.DeclareVar(const AVarType: String; - const AVarName: String); +Procedure TTestStatementParser.DeclareVar(Const AVarType: String; + Const AVarName: String); begin FVariables.Add(AVarName+' : '+AVarType+';'); end; @@ -135,7 +138,8 @@ begin Result:=TestStatement([ASource]); end; -function TTestStatementParser.TestStatement(ASource: array of string): TPasImplElement; +function TTestStatementParser.TestStatement(ASource: Array of string + ): TPasImplElement; begin @@ -152,19 +156,19 @@ begin Result:=FStatement; end; -procedure TTestStatementParser.ExpectParserError(Const Msg : string); +Procedure TTestStatementParser.ExpectParserError(Const Msg: string); begin AssertException(Msg,EParserError,@ParseModule); end; -procedure TTestStatementParser.ExpectParserError(const Msg: string; - ASource: array of string); +Procedure TTestStatementParser.ExpectParserError(Const Msg: string; + ASource: Array of string); begin AddStatements(ASource); ExpectParserError(Msg); end; -function TTestStatementParser.AssertStatement(Msg: String; AClass: TClass; +Function TTestStatementParser.AssertStatement(Msg: String; AClass: TClass; AIndex: Integer): TPasImplBlock; begin if not (AIndex'' then D:=D+' '+Hint; @@ -2210,7 +2219,7 @@ begin CheckHint(TPasMemberHint(Getenumvalue(typeinfo(TPasMemberHint),'h'+Hint))); end; -procedure TBaseTestTypeParser.AssertParseTypeError(ASource: String); +Procedure TBaseTestTypeParser.AssertParseTypeError(ASource: String); begin try ParseType(ASource,Nil,''); @@ -2220,6 +2229,12 @@ begin end; end; +Procedure TBaseTestTypeParser.AssertComment; +begin + AssertNotNull('Have type',TheType); + AssertEquals('Type comment',' A comment'+sLineBreak,TheTYpe.DocComment); +end; + procedure TBaseTestTypeParser.SetUp; begin Inherited; @@ -2228,7 +2243,7 @@ begin FType:=Nil; end; -procedure TBaseTestTypeParser.TearDown; +Procedure TBaseTestTypeParser.TearDown; begin inherited TearDown; FType:=Nil; @@ -2390,6 +2405,13 @@ begin DoTestAliasType('BYTE',''); end; +Procedure TTestTypeParser.TestSimpleTypeByteComment; +begin + AddComment:=True; + DoTestAliasType('BYTE',''); + AssertComment; +end; + Procedure TTestTypeParser.TestSimpleTypeByteDeprecated; begin DoTestAliasType('BYTE','deprecated'); @@ -2656,6 +2678,13 @@ begin AssertEquals('Array type','0..2',TPasArrayType(TheType).IndexRange); end; +Procedure TTestTypeParser.TestStaticArrayComment; +begin + AddComment:=True; + TestStaticArray; + AssertComment; +end; + procedure TTestTypeParser.TestStaticArrayDeprecated; begin DoParseArray('array [0..2] of integer','deprecated',Nil); @@ -2687,6 +2716,14 @@ begin AssertEquals('Array type','',TPasArrayType(TheType).IndexRange); end; +Procedure TTestTypeParser.TestDynamicArrayComment; +begin + AddComment:=True; + DoParseArray('array of integer','',Nil); + AssertEquals('Array type','',TPasArrayType(TheType).IndexRange); + AssertComment; +end; + Procedure TTestTypeParser.TestSimpleEnumerated; begin @@ -2699,6 +2736,25 @@ begin AssertEquals('Assigned value third enumerated empty','',TPasEnumValue(TPasEnumType(TheType).Values[2]).AssignedValue); end; +Procedure TTestTypeParser.TestSimpleEnumeratedComment; +begin + AddComment:=True; + TestSimpleEnumerated; + AssertComment; + AssertEquals('No comment on enum 0','',TPasEnumValue(TPasEnumType(TheType).Values[0]).DocComment); + AssertEquals('No comment on enum 1','',TPasEnumValue(TPasEnumType(TheType).Values[1]).DocComment); + AssertEquals('No comment on enum 2','',TPasEnumValue(TPasEnumType(TheType).Values[2]).DocComment); +end; + +Procedure TTestTypeParser.TestSimpleEnumeratedComment2; +begin + AddComment:=True; + DoParseEnumerated('( {a} one, {b} two, {c} three)','',3); + AssertEquals('comment on enum 0','a'+sLineBreak,TPasEnumValue(TPasEnumType(TheType).Values[0]).DocComment); + AssertEquals('comment on enum 1','b'+sLineBreak,TPasEnumValue(TPasEnumType(TheType).Values[1]).DocComment); + AssertEquals('comment on enum 2','c'+sLineBreak,TPasEnumValue(TPasEnumType(TheType).Values[2]).DocComment); +end; + Procedure TTestTypeParser.TestSimpleEnumeratedDeprecated; begin DoParseEnumerated('(one,two,three)','deprecated',3); @@ -2868,6 +2924,13 @@ begin DoTestClassOf(''); end; +Procedure TTestTypeParser.TestClassOfComment; +begin + AddComment:=True; + DoTestClassOf(''); + AssertComment; +end; + Procedure TTestTypeParser.TestClassOfDeprecated; begin DoTestClassOf('deprecated'); diff --git a/packages/fcl-passrc/tests/testpassrc.lpi b/packages/fcl-passrc/tests/testpassrc.lpi index 86bdfc7194..429ea12e08 100644 --- a/packages/fcl-passrc/tests/testpassrc.lpi +++ b/packages/fcl-passrc/tests/testpassrc.lpi @@ -30,7 +30,7 @@ - + @@ -42,7 +42,6 @@ - @@ -67,17 +66,14 @@ - - - @@ -107,12 +103,6 @@ - - - - - -