Fixed crash in gir2pas when a class is declared with no parent class.

Moved some writeln's to girError.


git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2497 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
drewski207
2012-08-27 02:16:38 +00:00
parent e4dbeca47f
commit d076a47b16
4 changed files with 42 additions and 17 deletions

View File

@ -327,7 +327,6 @@ begin
begin begin
WriteLn(Text); WriteLn(Text);
Free; Free;
end; end;
{ {
Writeln(''); Writeln('');

View File

@ -24,7 +24,7 @@ unit girFiles;
interface interface
uses uses
Classes, SysUtils, XMLRead, DOM, girNameSpaces, girParser; Classes, SysUtils, DOM, girNameSpaces, girParser;
type type

View File

@ -52,6 +52,7 @@ type
FVersion: String; FVersion: String;
FWriting: TGirModeState; FWriting: TGirModeState;
procedure SetImpliedPointerLevel(AValue: Integer); procedure SetImpliedPointerLevel(AValue: Integer);
function MaybeResolvedType: TGirBaseType;
public public
constructor Create(AOwner: TObject; ANode: TDomNode); virtual; constructor Create(AOwner: TObject; ANode: TDomNode); virtual;
property CType: String read FCType write FCType; property CType: String read FCType write FCType;
@ -122,9 +123,10 @@ type
FIsArray: Boolean; FIsArray: Boolean;
FPropType: TgirBaseType; FPropType: TgirBaseType;
FWriteable: Boolean; FWriteable: Boolean;
function GetPropType: TgirBaseType;
public public
constructor Create(AOwner: TObject; ANode: TDomNode); override; constructor Create(AOwner: TObject; ANode: TDomNode); override;
property PropType: TgirBaseType read FPropType; property PropType: TgirBaseType read GetPropType;
property Writable: Boolean read FWriteable; property Writable: Boolean read FWriteable;
property IsArray: Boolean read FIsArray; property IsArray: Boolean read FIsArray;
end; end;
@ -513,6 +515,13 @@ end;
{ TgirProperty } { TgirProperty }
function TgirProperty.GetPropType: TgirBaseType;
begin
Result := FPropType;
if Assigned(Result) and Result.InheritsFrom(TgirFuzzyType) and (TgirFuzzyType(Result).ResolvedType <> nil) then
Result := TgirFuzzyType(Result).ResolvedType;
end;
constructor TgirProperty.Create(AOwner: TObject; ANode: TDomNode); constructor TgirProperty.Create(AOwner: TObject; ANode: TDomNode);
var var
Node: TDOMElement; Node: TDOMElement;
@ -543,7 +552,8 @@ end;
function TgirClass.GetParentClass: TgirClass; function TgirClass.GetParentClass: TgirClass;
begin begin
if (FParentClass <> nil) and (FParentClass.InheritsFrom(TgirFuzzyType)) and (TgirFuzzyType(FParentClass).ResolvedType <> nil) then Result := FParentClass;
if (FParentClass <> nil) and (FParentClass.ObjectType = otFuzzyType) and (TgirFuzzyType(FParentClass).ResolvedType <> nil) then
FParentClass := TgirClass(TgirFuzzyType(FParentClass).ResolvedType); FParentClass := TgirClass(TgirFuzzyType(FParentClass).ResolvedType);
Result := FParentClass; Result := FParentClass;
end; end;
@ -576,7 +586,11 @@ begin
FInterfaces := TList.Create; // must be before inherited else list does not exist when ParseNeode is called FInterfaces := TList.Create; // must be before inherited else list does not exist when ParseNeode is called
inherited Create(AOwner, ANode); inherited Create(AOwner, ANode);
Parent := TDOMElement(ANode).GetAttribute('parent'); Parent := TDOMElement(ANode).GetAttribute('parent');
FParentClass := TgirClass(TgirNamespace(Owner).LookupTypeByName(Parent, '', True)); if Parent = '' then
FParentClass := nil
else
FParentClass := TgirClass(TgirNamespace(Owner).LookupTypeByName(Parent, '', True));
if CType = '' then if CType = '' then
CType := TDOMElement(ANode).GetAttribute('glib:type-name'); CType := TDOMElement(ANode).GetAttribute('glib:type-name');
FObjectType:=otClass; FObjectType:=otClass;
@ -1053,6 +1067,8 @@ begin
if AValue = FResolvedType then if AValue = FResolvedType then
Exit; Exit;
FResolvedType := AValue; FResolvedType := AValue;
if Assigned(FResolvedType) then
FResolvedType.ImpliedPointerLevel:=ImpliedPointerLevel;
//girError(geDebug, 'Resolved FuzzyType '+AValue.Name); //girError(geDebug, 'Resolved FuzzyType '+AValue.Name);
end; end;
@ -1118,6 +1134,14 @@ begin
FImpliedPointerLevel:=3; FImpliedPointerLevel:=3;
end; end;
function TGirBaseType.MaybeResolvedType: TGirBaseType;
begin
if Self.InheritsFrom(TgirFuzzyType) and (TgirFuzzyType(Self).ResolvedType <> nil) then
Result := TgirFuzzyType(Self).ResolvedType
else
Result := Self;
end;
constructor TGirBaseType.Create(AOwner: TObject; ANode: TDOMNode); constructor TGirBaseType.Create(AOwner: TObject; ANode: TDOMNode);
var var
Element: TDOMElement absolute ANode; Element: TDOMElement absolute ANode;

View File

@ -263,7 +263,7 @@ type
end; end;
implementation implementation
uses girpascalwriter, girCTypesMapping; uses girpascalwriter, girCTypesMapping, girErrors, typinfo;
function IndentText(const AText: String; Spaces: Integer = 0; LineEndingCount: Integer = 1): String; function IndentText(const AText: String; Spaces: Integer = 0; LineEndingCount: Integer = 1): String;
begin begin
@ -673,7 +673,7 @@ begin
if (AType.CType = '') then //(AType.Name = '') then if (AType.CType = '') then //(AType.Name = '') then
begin begin
WriteLn('WARNING: Type.Ctype undefined! : ', Atype.Name); girError(geWarn, 'Type.Ctype undefined! : '+ Atype.Name);
//Halt; //Halt;
end; end;
@ -724,7 +724,7 @@ begin
end; end;
else else
//WantTypeSection.Lines.Add(IndentText(AType.ClassName + ' ' +AType.Name + ' ' + AType.CType ,2)); //WantTypeSection.Lines.Add(IndentText(AType.ClassName + ' ' +AType.Name + ' ' + AType.CType ,2));
WriteLn('Unknown Type: ', AType.ClassName); girError(geFatal, 'Type.Ctype undefined! : '+ Atype.Name);
Halt; Halt;
end; // case end; // case
if (AType.InheritsFrom(TgirGType)) then // and (TgirGType(AType).HasFields) then if (AType.InheritsFrom(TgirGType)) then // and (TgirGType(AType).HasFields) then
@ -832,7 +832,8 @@ var
i: Integer; i: Integer;
begin begin
if AItem.ForwardDefinitionWritten then if AItem.ForwardDefinitionWritten then
WriteLn('Warning: Forwards definitions already written for : ', Aitem.TranslatedName); girError(geWarn, 'Forwards definitions already written for : '+ Aitem.TranslatedName);
//WriteLn('Warning: Forwards definitions already written for : ', Aitem.TranslatedName);
AItem.ForwardDefinitionWritten := True; AItem.ForwardDefinitionWritten := True;
PTypes := MakePointerTypesForType(ATypeName, APointerLevel); PTypes := MakePointerTypesForType(ATypeName, APointerLevel);
PTypes.Insert(0, ATypeName); PTypes.Insert(0, ATypeName);
@ -1067,7 +1068,7 @@ begin
TypeSect.Lines.Add(IndentText('{ opaque type }',4,0)); TypeSect.Lines.Add(IndentText('{ opaque type }',4,0));
TypeSect.Lines.Add(IndentText('Unknown: Pointer;',4,0)); // to prevent crashes of the compiler TypeSect.Lines.Add(IndentText('Unknown: Pointer;',4,0)); // to prevent crashes of the compiler
TypeSect.Lines.Add(IndentText('end;',2,1)); TypeSect.Lines.Add(IndentText('end;',2,1));
WriteLn('Wrote Opaque Type Name = ', AItem.Name,' CType = ', AItem.CType); girError(geInfo, 'Wrote Opaque Type Name = ' + AItem.Name +' CType = '+ AItem.CType);
end; end;
@ -1273,6 +1274,7 @@ var
end; end;
FoundPos:=Pos(';', Line); FoundPos:=Pos(';', Line);
Result := Trim(Copy(Line, 1,FoundPos-1)); Result := Trim(Copy(Line, 1,FoundPos-1));
//WriteLn('Found property: ',Result, ' Property Value = ', AProperty.PropType.CType);
break; break;
end end
end; end;
@ -1386,7 +1388,7 @@ var
end; end;
else // case < else // case <
WriteLn('Unknown Field Type : ', Field.ClassName); girError(geFatal, 'Unknown Field Type : '+ Field.ClassName);
Halt; Halt;
end; end;
end; end;
@ -1471,12 +1473,12 @@ begin
ProperUnit := Self; ProperUnit := Self;
end; end;
else else
WriteLn('Unknown ObjectType : ', AObjectType); girError(geFatal, 'Unknown ObjectType : '+ GetEnumName(TypeInfo(TGirToken), Ord(AObjectType)));
Halt; Halt;
end; end;
if ProperUnit = nil then if ProperUnit = nil then
begin begin
WriteLn('ProperUnit is not assigned! : ', AObjectType); girError(geFatal, 'ProperUnit is not assigned! : '+ GetEnumName(TypeInfo(TGirToken), Ord(AObjectType)));
Halt; Halt;
end; end;
if ProperUnit <> Self then if ProperUnit <> Self then
@ -1508,7 +1510,7 @@ begin
gtInterface: ; gtInterface: ;
gtGType: ; gtGType: ;
else else
WriteLn('Got Object Type I don''t understand: ', GirTokenName[AObjectType]); girError(geWarn, 'Got Object Type I don''t understand: ' + GirTokenName[AObjectType]);
end; end;
if AItem.InheritsFrom(TgirGType) then if AItem.InheritsFrom(TgirGType) then
@ -1742,7 +1744,7 @@ begin
end; end;
if APointerLevel > AType.ImpliedPointerLevel then if APointerLevel > AType.ImpliedPointerLevel then
begin begin
WriteLn('Trying to use a pointerlevel > written level!'); girError(geFatal, 'Trying to use a pointerlevel > written level!');
Halt; Halt;
end; end;
end; end;
@ -1821,7 +1823,7 @@ begin
1..32: 1..32:
PT := Format('guint%d { changed from %s to accomodate %d bitsize requirement }',[AParam.Bits, PT, AParam.Bits]); PT := Format('guint%d { changed from %s to accomodate %d bitsize requirement }',[AParam.Bits, PT, AParam.Bits]);
else else
WriteLn('WARNING: Bits are Set to [ ',AParam.Bits,' ]for: ' ,PN+': '+PT); girError(geWarn, 'Bits are Set to [ '+IntToStr(AParam.Bits)+' ]for: ' +PN+': '+PT);
PT +=' { ERROR : Bits are Set to [ '+IntToStr(AParam.Bits)+' ] }'; PT +=' { ERROR : Bits are Set to [ '+IntToStr(AParam.Bits)+' ] }';
end; end;
@ -1922,7 +1924,7 @@ begin
otMethod : Union.Add(IndentText('//'+WriteFunction(TgirFunction(Field), AUnion, True, False, WantFunctionSection.Lines), ABaseIndent+2,0)); otMethod : Union.Add(IndentText('//'+WriteFunction(TgirFunction(Field), AUnion, True, False, WantFunctionSection.Lines), ABaseIndent+2,0));
else else
Union.Add('// Unhandled type for Union: '+ Field.ClassName); // this won't compile obviously Union.Add('// Unhandled type for Union: '+ Field.ClassName); // this won't compile obviously
WriteLn('Unhandled type for Union: ', Field.ClassName); girError(geWarn, 'Unhandled type for Union: '+ Field.ClassName);
end; end;
end; end;