From 65a1f81a70e4268801a09106df54fcb2497c6d7d Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 16 Sep 2013 21:53:14 +0200 Subject: Detect reuse of module names for other entities Change-Id: Ifc8d95b4b15a7dd91195e6f727fdb7fa2a267be9 --- unoidl/source/sourceprovider-parser.y | 35 ++++++++++++++++++++++++++++++-- unoidl/source/sourceprovider-scanner.hxx | 9 +++++--- 2 files changed, 39 insertions(+), 5 deletions(-) (limited to 'unoidl/source') diff --git a/unoidl/source/sourceprovider-parser.y b/unoidl/source/sourceprovider-parser.y index 7d5f108fae2f..cc18854b1245 100644 --- a/unoidl/source/sourceprovider-parser.y +++ b/unoidl/source/sourceprovider-parser.y @@ -460,6 +460,8 @@ Found findEntity( case unoidl::detail::SourceProviderEntity::KIND_INTERFACE_DECL: argT = unoidl::detail::SourceProviderType::TYPE_INTERFACE; break; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + assert(false); // this cannot happen } argType = unoidl::detail::SourceProviderType( @@ -546,6 +548,11 @@ Found findEntity( e->entity = ent; } break; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + error( + location, yyscanner, + *name + " is based on module entity " + n); + return FOUND_ERROR; } } if (!typeNucleus.isEmpty() || rank != 0 || !args.empty()) { @@ -696,6 +703,8 @@ Found findEntity( unoidl::detail::SourceProviderType::TYPE_INTERFACE, n, e); break; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + assert(false); // this cannot happen } } } else { @@ -757,6 +766,8 @@ Found findEntity( + n + " that is not a polymorphic struct type template")); return FOUND_ERROR; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + assert(false); // this cannot happen } } if (typedefedType != 0) { @@ -904,7 +915,21 @@ moduleDecl: TOK_MODULE identifier { unoidl::detail::SourceProviderScannerData * data = yyget_extra(yyscanner); - data->modules.push_back(convertToFullName(data, $2)); + OUString name(convertToFullName(data, $2)); + data->modules.push_back(name); + std::pair::iterator, bool> p( + data->entities.insert( + std::map::value_type( + name, + unoidl::detail::SourceProviderEntity( + unoidl::detail::SourceProviderEntity::KIND_MODULE)))); + if (!p.second + && (p.first->second.kind + != unoidl::detail::SourceProviderEntity::KIND_MODULE)) + { + error(@2, yyscanner, "multiple entities named " + name); + YYERROR; + } } '{' definitions '}' ';' { yyget_extra(yyscanner)->modules.pop_back(); } ; @@ -2671,7 +2696,9 @@ interfaceDecl: std::pair::iterator, bool> p( data->entities.insert( std::map::value_type( - name, unoidl::detail::SourceProviderEntity()))); + name, + unoidl::detail::SourceProviderEntity( + unoidl::detail::SourceProviderEntity::KIND_INTERFACE_DECL)))); if (!p.second && (p.first->second.kind != unoidl::detail::SourceProviderEntity::KIND_INTERFACE_DECL)) @@ -3468,6 +3495,8 @@ type: ent); ok = true; break; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + assert(false); // this cannot happen } if (!ok) { error(@1, yyscanner, "non-type entity " + name); @@ -3533,6 +3562,8 @@ type: break; case unoidl::detail::SourceProviderEntity::KIND_INTERFACE_DECL: break; + case unoidl::detail::SourceProviderEntity::KIND_MODULE: + assert(false); // this cannot happen } if (!ok) { error(@1, yyscanner, "non-type entity " + name); diff --git a/unoidl/source/sourceprovider-scanner.hxx b/unoidl/source/sourceprovider-scanner.hxx index 152b9cf6ca2b..51900580e987 100644 --- a/unoidl/source/sourceprovider-scanner.hxx +++ b/unoidl/source/sourceprovider-scanner.hxx @@ -189,19 +189,22 @@ private: }; struct SourceProviderEntity { - enum Kind { KIND_EXTERNAL, KIND_LOCAL, KIND_INTERFACE_DECL }; + enum Kind { KIND_EXTERNAL, KIND_LOCAL, KIND_INTERFACE_DECL, KIND_MODULE }; explicit SourceProviderEntity( Kind theKind, rtl::Reference const & externalEntity): kind(theKind), entity(externalEntity) - { assert(theKind != KIND_INTERFACE_DECL); assert(externalEntity.is()); } + { assert(theKind <= KIND_LOCAL); assert(externalEntity.is()); } explicit SourceProviderEntity( rtl::Reference const & localPad): kind(KIND_LOCAL), pad(localPad) { assert(localPad.is()); } - SourceProviderEntity(): kind(KIND_INTERFACE_DECL) {} + explicit SourceProviderEntity(Kind theKind): kind(theKind) + { assert(theKind >= KIND_INTERFACE_DECL); } + + SourceProviderEntity() {} // needed for std::map::operator [] Kind kind; rtl::Reference entity; -- cgit