From e49d2da3366d6e36140ef19d5adb21bd86416c7e Mon Sep 17 00:00:00 2001 From: inoussa Date: Mon, 16 Nov 2009 09:28:25 +0000 Subject: [PATCH] Make sure to always use a valid identifier for a type name. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1012 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/ws_helper/ws_parser_imp.pas | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/wst/trunk/ws_helper/ws_parser_imp.pas b/wst/trunk/ws_helper/ws_parser_imp.pas index dd51c363c..b4d2e82eb 100644 --- a/wst/trunk/ws_helper/ws_parser_imp.pas +++ b/wst/trunk/ws_helper/ws_parser_imp.pas @@ -878,7 +878,7 @@ var FSymbols.RegisterExternalAlias(locType,locTypeName); end; end else begin - locTypeInternalName := locTypeName; + locTypeInternalName := ExtractIdentifier(locTypeName); if locIsRefElement or AnsiSameText(locTypeInternalName,locInternalEltName) then begin locTypeInternalName := locTypeInternalName + '_Type'; end; @@ -1585,10 +1585,26 @@ begin end; function TSimpleTypeParser.ParseOtherContent(): TPasType; +var + intrName : string; + hasIntrnName : Boolean; + tmpElement : TPasElement; begin // todo : implement TSimpleTypeParser.ParseOtherContent if IsStrEmpty(FBaseName) then raise EXsdInvalidTypeDefinitionException.CreateFmt('Invalid simple type definition : base type not provided, "%s".',[FTypeName]); - Result := TPasTypeAliasType(FSymbols.CreateElement(TPasTypeAliasType,FTypeName,Self.Module.InterfaceSection,visDefault,'',0)); + intrName := ExtractIdentifier(FTypeName); + hasIntrnName := ( intrName <> FTypeName ) or + IsReservedKeyWord(intrName); + if not hasIntrnName then begin + tmpElement := FindElement(intrName); + if ( tmpElement <> nil ) and ( not tmpElement.InheritsFrom(TPasUnresolvedTypeRef) ) then + hasIntrnName := True; + end; + if hasIntrnName then + intrName := '_' + intrName; + Result := TPasTypeAliasType(FSymbols.CreateElement(TPasTypeAliasType,intrName,Self.Module.InterfaceSection,visDefault,'',0)); + if ( intrName <> FTypeName ) then + FSymbols.RegisterExternalAlias(Result,FTypeName); TPasTypeAliasType(Result).DestType := FindElementNS(FBaseNameSpace,FBaseName,nvtExpandValue) as TPasType; TPasTypeAliasType(Result).DestType.AddRef(); end;