From a2c31b16a188f42ec067a79dd13cd0a86ebbafcb Mon Sep 17 00:00:00 2001 From: inoussa Date: Thu, 26 Jun 2008 15:06:00 +0000 Subject: [PATCH] Handling of an enumeration with an empty item ( reported by Michael Van Canneyt ) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@491 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/ws_helper/generator.pas | 6 +++-- wst/trunk/ws_helper/pascal_parser_intf.pas | 31 ++++++++++++++++++++-- wst/trunk/ws_helper/ws_parser_imp.pas | 6 +++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/wst/trunk/ws_helper/generator.pas b/wst/trunk/ws_helper/generator.pas index 7b9615377..0414afab9 100644 --- a/wst/trunk/ws_helper/generator.pas +++ b/wst/trunk/ws_helper/generator.pas @@ -1855,9 +1855,11 @@ begin WriteLn(',%s',[itm.Name]) else WriteLn('%s',[itm.Name]); - if not AnsiSameText(itm.Name,SymbolTable.GetExternalName(itm)) then begin + if SymbolTable.HasExternalName(itm) and + ( not AnsiSameText(itm.Name,SymbolTable.GetExternalName(itm,False)) ) + then begin FImpTempStream.Indent(); - FImpTempStream.WriteLn('GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(%s,%s);',[ASymbol.Name,QuotedStr(itm.Name),QuotedStr(SymbolTable.GetExternalName(itm))]); + FImpTempStream.WriteLn('GetTypeRegistry().ItemByTypeInfo[TypeInfo(%s)].RegisterExternalPropertyName(%s,%s);',[ASymbol.Name,QuotedStr(itm.Name),QuotedStr(SymbolTable.GetExternalName(itm,False))]); end; end; DecIndent(); diff --git a/wst/trunk/ws_helper/pascal_parser_intf.pas b/wst/trunk/ws_helper/pascal_parser_intf.pas index 6b42a1785..4358bad99 100644 --- a/wst/trunk/ws_helper/pascal_parser_intf.pas +++ b/wst/trunk/ws_helper/pascal_parser_intf.pas @@ -74,6 +74,7 @@ type destructor Destroy();override; procedure SetValue(AOwner : TObject; const AName, AValue : string); function GetValue(AOwner : TObject; const AName : string) : string; + function HasValue(AOwner : TObject; const AName : string) : Boolean; function FindList(AOwner : TObject) : TStrings; function GetList(AOwner : TObject) : TStrings; end; @@ -131,7 +132,9 @@ type procedure FreeProperties(AObject : TPasElement); procedure RegisterExternalAlias(AObject : TPasElement; const AExternalName : String); function SameName(AObject : TPasElement; const AName : string) : Boolean; - function GetExternalName(AObject : TPasElement) : string; + function HasExternalName(AObject : TPasElement) : Boolean; + function GetExternalName(AObject : TPasElement) : string;overload; + function GetExternalName(AObject : TPasElement; const AReturnNameIfEmpty : Boolean) : string;overload; function GetNameSpace(AType : TPasType) : string ; function IsAttributeProperty(AObject : TPasVariable) : Boolean; procedure SetPropertyAsAttribute(AObject : TPasVariable; const AValue : Boolean); @@ -826,10 +829,23 @@ begin Result := AnsiSameText(AName,AObject.Name) or AnsiSameText(AName,GetExternalName(AObject)) ; end; +function TwstPasTreeContainer.HasExternalName(AObject : TPasElement) : Boolean; +begin + Result := Properties.HasValue(AObject,sEXTERNAL_NAME); +end; + function TwstPasTreeContainer.GetExternalName(AObject: TPasElement): string; +begin + Result := GetExternalName(AObject,True); +end; + +function TwstPasTreeContainer.GetExternalName( + AObject : TPasElement; + const AReturnNameIfEmpty : Boolean +) : string; begin Result := Properties.GetValue(AObject,sEXTERNAL_NAME); - if IsStrEmpty(Result) then begin + if IsStrEmpty(Result) and AReturnNameIfEmpty then begin Result := AObject.Name; end; end; @@ -961,6 +977,17 @@ begin end; end; +function TPropertyHolder.HasValue(AOwner : TObject; const AName : string) : Boolean; +var + ls : TStrings; +begin + ls := FindList(AOwner); + if ( ls <> nil ) and ( ls.IndexOfName(AName) > -1 ) then + Result := True + else + Result := False; +end; + { TPasNativeSimpleTypeDefinition } destructor TPasNativeSimpleType.Destroy(); diff --git a/wst/trunk/ws_helper/ws_parser_imp.pas b/wst/trunk/ws_helper/ws_parser_imp.pas index 7fa06e35a..a191ab996 100644 --- a/wst/trunk/ws_helper/ws_parser_imp.pas +++ b/wst/trunk/ws_helper/ws_parser_imp.pas @@ -1232,10 +1232,13 @@ var raise EXsdInvalidDefinitionException.CreateFmt('Invalid "enum" item node : no value attribute, type = "%s".',[FTypeName]); tmpNode := (locCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject; locItemName := tmpNode.NodeValue; + { (26-06-2008) empty string "" can be valid enum item! if IsStrEmpty(locItemName) then raise EXsdInvalidDefinitionException.CreateFmt('Invalid "enum" item node : the value attribute is empty, type = "%s".',[FTypeName]); - + } locInternalItemName := ExtractIdentifier(locItemName); + if IsStrEmpty(locInternalItemName) then + locInternalItemName := 'EmptyItem'; locHasInternalName := IsReservedKeyWord(locInternalItemName) or ( not IsValidIdent(locInternalItemName) ) or ( FSymbols.FindElementInModule(locInternalItemName,Self.Module) <> nil ) or @@ -1252,7 +1255,6 @@ var locItem := TPasEnumValue(FSymbols.CreateElement(TPasEnumValue,locInternalItemName,locRes,visDefault,'',0)); locItem.Value := locOrder; locRes.Values.Add(locItem); - //locItem := TEnumItemDefinition.Create(locInternalItemName,locRes,locOrder); if locHasInternalName then FSymbols.RegisterExternalAlias(locItem,locItemName); Inc(locOrder);