/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace
{
[[noreturn]] void badUsage()
{
std::cerr
<< "Usage:\n\n" " wasmbridgegen \n\n" "where each is '+' (primary) or ':' (secondary), followed by: either a\n" "new- or legacy-format .rdb file, a single .idl file, or a root directory of an\n" ".idl file tree. For all primary registries, Wasm UNO bridge code is written to\n" "/, and to-be-exported exception RTTI symbols are written\n" "to .\n";
std::exit(EXIT_FAILURE);
}
OUString resolveAllTypedefs(rtl::Reference<TypeManager> const& manager, std::u16string_view name)
{
sal_Int32 k1;
OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1))); for (;;)
{
rtl::Reference<unoidl::Entity> ent; if (manager->getSort(n, &ent) != codemaker::UnoType::Sort::Typedef)
{ break;
}
sal_Int32 k2;
n = b2u(codemaker::UnoType::decompose(
u2b(static_cast<unoidl::TypedefEntity*>(ent.get())->getType()), &k2));
k1 += k2; //TODO: overflow
}
OUStringBuffer b; for (sal_Int32 i = 0; i != k1; ++i)
{
b.append("[]");
}
b.append(n); return b.makeStringAndClear();
}
enumclass StructKind
{
Empty,
I32,
I64,
F32,
F64,
General
};
StructKind getKind(rtl::Reference<TypeManager> const& manager, std::u16string_view type)
{
std::vector<OUString> args;
rtl::Reference<unoidl::Entity> ent;
OUString singleMemberType; switch (manager->decompose(type, true, nullptr, nullptr, &args, &ent))
{ case codemaker::UnoType::Sort::PlainStruct:
{ autoconst strct = static_cast<unoidl::PlainStructTypeEntity const*>(ent.get()); if (strct->getDirectMembers().size() > 1)
{ return StructKind::General;
} auto k = StructKind::Empty; if (!strct->getDirectBase().isEmpty())
{
k = getKind(manager, strct->getDirectBase());
} if (strct->getDirectMembers().empty())
{ return k;
} if (k != StructKind::Empty)
{ return StructKind::General;
}
singleMemberType = strct->getDirectMembers()[0].type; break;
} case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
{ autoconst strct
= static_cast<unoidl::PolymorphicStructTypeTemplateEntity const*>(ent.get()); switch (strct->getMembers().size())
{ case 0: return StructKind::Empty; case 1: if (strct->getMembers()[0].parameterized)
{ autoconst i = std::find(strct->getTypeParameters().begin(),
strct->getTypeParameters().end(),
strct->getMembers()[0].type); if (i == strct->getTypeParameters().end())
{ throw CannotDumpException("bad type parameter \""
+ strct->getMembers()[0].type
+ "\" in call to getKind");
} autoconst n = i - strct->getTypeParameters().begin(); if (o3tl::make_unsigned(n) > args.size())
{ throw CannotDumpException("bad type parameter \""
+ strct->getMembers()[0].type
+ "\" in call to getKind");
}
singleMemberType = args[n];
} else
{
singleMemberType = strct->getMembers()[0].type;
} break; default: return StructKind::General;
} break;
} default: throw CannotDumpException(OUString::Concat("unexpected entity \"") + type
+ "\" in call to getKind");
} switch (manager->getSort(resolveAllTypedefs(manager, singleMemberType)))
{ case codemaker::UnoType::Sort::Boolean: case codemaker::UnoType::Sort::Byte: case codemaker::UnoType::Sort::Short: case codemaker::UnoType::Sort::UnsignedShort: case codemaker::UnoType::Sort::Long: case codemaker::UnoType::Sort::UnsignedLong: case codemaker::UnoType::Sort::Char: case codemaker::UnoType::Sort::Enum: return StructKind::I32; case codemaker::UnoType::Sort::Hyper: case codemaker::UnoType::Sort::UnsignedHyper: return StructKind::I64; case codemaker::UnoType::Sort::Float: return StructKind::F32; case codemaker::UnoType::Sort::Double: return StructKind::F64; default: return StructKind::General;
}
}
void appendCallSignatureReturnType(OStringBuffer& buffer,
rtl::Reference<TypeManager> const& manager, OUString const& type)
{ switch (manager->getSort(resolveAllTypedefs(manager, type)))
{ case codemaker::UnoType::Sort::Void:
buffer.append('v'); break; case codemaker::UnoType::Sort::Boolean: case codemaker::UnoType::Sort::Byte: case codemaker::UnoType::Sort::Short: case codemaker::UnoType::Sort::UnsignedShort: case codemaker::UnoType::Sort::Long: case codemaker::UnoType::Sort::UnsignedLong: case codemaker::UnoType::Sort::Char: case codemaker::UnoType::Sort::Enum:
buffer.append('i'); break; case codemaker::UnoType::Sort::Hyper: case codemaker::UnoType::Sort::UnsignedHyper:
buffer.append('j'); break; case codemaker::UnoType::Sort::Float:
buffer.append('f'); break; case codemaker::UnoType::Sort::Double:
buffer.append('d'); break; case codemaker::UnoType::Sort::String: case codemaker::UnoType::Sort::Type: case codemaker::UnoType::Sort::Any: case codemaker::UnoType::Sort::Sequence: case codemaker::UnoType::Sort::Interface:
buffer.append("vi"); break; case codemaker::UnoType::Sort::PlainStruct: case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
{ switch (getKind(manager, type))
{ case StructKind::Empty: break; case StructKind::I32:
buffer.append('i'); break; case StructKind::I64:
buffer.append('j'); break; case StructKind::F32:
buffer.append('f'); break; case StructKind::F64:
buffer.append('d'); break; case StructKind::General:
buffer.append("vi"); break;
} break;
} default: throw CannotDumpException("unexpected entity \"" + type
+ "\" in call to appendCallSignatureReturnType");
}
}
void appendCallSignatureParameter(
OStringBuffer& buffer, rtl::Reference<TypeManager> const& manager,
unoidl::InterfaceTypeEntity::Method::Parameter::Direction direction, OUString const& type)
{ if (direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
{ switch (manager->getSort(resolveAllTypedefs(manager, type)))
{ case codemaker::UnoType::Sort::Boolean: case codemaker::UnoType::Sort::Byte: case codemaker::UnoType::Sort::Short: case codemaker::UnoType::Sort::UnsignedShort: case codemaker::UnoType::Sort::Long: case codemaker::UnoType::Sort::UnsignedLong: case codemaker::UnoType::Sort::Char: case codemaker::UnoType::Sort::Enum: case codemaker::UnoType::Sort::String: case codemaker::UnoType::Sort::Type: case codemaker::UnoType::Sort::Any: case codemaker::UnoType::Sort::Sequence: case codemaker::UnoType::Sort::PlainStruct: case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct: case codemaker::UnoType::Sort::Interface:
buffer.append('i'); break; case codemaker::UnoType::Sort::Hyper: case codemaker::UnoType::Sort::UnsignedHyper:
buffer.append('j'); break; case codemaker::UnoType::Sort::Float:
buffer.append('f'); break; case codemaker::UnoType::Sort::Double:
buffer.append('d'); break; default: throw CannotDumpException("unexpected entity \"" + type
+ "\" in call to appendCallSignatureParameter");
}
} else
{
buffer.append('i');
}
}
void appendSlotSignatureReturnType(OStringBuffer& buffer,
rtl::Reference<TypeManager> const& manager, OUString const& type)
{ switch (manager->getSort(resolveAllTypedefs(manager, type)))
{ case codemaker::UnoType::Sort::Void:
buffer.append('v'); break; case codemaker::UnoType::Sort::Boolean: case codemaker::UnoType::Sort::Byte: case codemaker::UnoType::Sort::Short: case codemaker::UnoType::Sort::UnsignedShort: case codemaker::UnoType::Sort::Long: case codemaker::UnoType::Sort::UnsignedLong: case codemaker::UnoType::Sort::Char: case codemaker::UnoType::Sort::Enum:
buffer.append('i'); break; case codemaker::UnoType::Sort::Hyper: case codemaker::UnoType::Sort::UnsignedHyper:
buffer.append('j'); break; case codemaker::UnoType::Sort::Float:
buffer.append('f'); break; case codemaker::UnoType::Sort::Double:
buffer.append('d'); break; case codemaker::UnoType::Sort::String: case codemaker::UnoType::Sort::Type: case codemaker::UnoType::Sort::Any: case codemaker::UnoType::Sort::Sequence: case codemaker::UnoType::Sort::Interface:
buffer.append('I'); break; case codemaker::UnoType::Sort::PlainStruct: case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
{ switch (getKind(manager, type))
{ case StructKind::Empty: break; case StructKind::I32:
buffer.append('i'); break; case StructKind::I64:
buffer.append('j'); break; case StructKind::F32:
buffer.append('f'); break; case StructKind::F64:
buffer.append('d'); break; case StructKind::General:
buffer.append('I'); break;
} break;
} default: throw CannotDumpException("unexpected entity \"" + type
+ "\" in call to appendSlotSignatureReturnType");
}
}
void appendSlotSignatureParameter(
OStringBuffer& buffer, rtl::Reference<TypeManager> const& manager,
unoidl::InterfaceTypeEntity::Method::Parameter::Direction direction, OUString const& type)
{ if (direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
{ switch (manager->getSort(resolveAllTypedefs(manager, type)))
{ case codemaker::UnoType::Sort::Boolean: case codemaker::UnoType::Sort::Byte: case codemaker::UnoType::Sort::Short: case codemaker::UnoType::Sort::UnsignedShort: case codemaker::UnoType::Sort::Long: case codemaker::UnoType::Sort::UnsignedLong: case codemaker::UnoType::Sort::Char: case codemaker::UnoType::Sort::Enum: case codemaker::UnoType::Sort::String: case codemaker::UnoType::Sort::Type: case codemaker::UnoType::Sort::Any: case codemaker::UnoType::Sort::Sequence: case codemaker::UnoType::Sort::PlainStruct: case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct: case codemaker::UnoType::Sort::Interface:
buffer.append('i'); break; case codemaker::UnoType::Sort::Hyper: case codemaker::UnoType::Sort::UnsignedHyper:
buffer.append('j'); break; case codemaker::UnoType::Sort::Float:
buffer.append('f'); break; case codemaker::UnoType::Sort::Double:
buffer.append('d'); break; default: throw CannotDumpException("unexpected entity \"" + type
+ "\" in call to appendSlotSignatureParameter");
}
} else
{
buffer.append('i');
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.