microsoft / winmd Goto Github PK
View Code? Open in Web Editor NEWC++ winmd parser
License: MIT License
C++ winmd parser
License: MIT License
Readme should be fleshed out:
see also:
microsoft/xlang#513
When you add the winmd package to your include directories and your project already contains it's own "impl/base.h" header file, it causes problems.
This could be solved by moving everything in impl
up a directory level and removing the impl
folder and renaming base.h
to winmd_base.h
.
for (auto const& type : db.TypeDef) {
std::cout << (type.is_enum() ? "enum " : "class ") << type.TypeName() << std::endl;
...
}
winmd2markdown.exe!winmd::impl::throw_invalid(const std::string & message) Line 47 C++
winmd2markdown.exe!winmd::reader::table_base::get_value(const unsigned int row, const unsigned int column) Line 43 C++
winmd2markdown.exe!winmd::reader::row_basewinmd::reader::TypeDef::get_string(const unsigned int column) Line 545 C++
winmd2markdown.exe!winmd::reader::TypeDef::TypeNamespace() Line 61 C++
winmd2markdown.exe!winmd::reader::get_type_namespace_and_name(const winmd::reader::coded_index & type) Line 9 C++
winmd2markdown.exe!winmd::reader::get_base_class_namespace_and_name(const winmd::reader::TypeDef & type) Line 25 C++
winmd2markdown.exe!winmd::reader::extends_type(winmd::reader::TypeDef type, std::basic_string_view<char,std::char_traits> typeNamespace, std::basic_string_view<char,std::char_traits> typeName) Line 30 C++
winmd2markdown.exe!winmd::reader::TypeDef::is_enum() Line 119 C++
winmd2markdown.exe!main() Line 56 C++
Not quite certain if this is the problem of winmd parser, or of the Windows.winmd file, but as the title suggests, to me the type is illy defined. I'm working on something pretty much like NodeRT and am trying to export the whole WinRT world to the TypeScript definition file, the following is what I got just by range-foring the type.MethodList()
:
export interface IWebSocket extends Windows.Foundation.IClosable {
outputStream: Windows.Storage.Streams.IOutputStream;
connectAsync(uri: Windows.Foundation.Uri): Windows.Foundation.IAsyncAction;
setRequestHeader(headerName: string, headerValue: string): void;
closed(eventHandler: Windows.Foundation.TypedEventHandler<Windows.Networking.Sockets.IWebSocket, Windows.Networking.Sockets.WebSocketClosedEventArgs>): any;
close(code: number, reason: string): void;
}
Verified other class/interface definitions which implements/extends IClosable
and there is such definition available, and now I make IWebSocket
as a special case. Am I missing something here?
impl/winmd_reader/view.h
uses std::exchange
but <utility>
has not been explicitly included. It fails to build on GCC 12 / libstdc++ with error: 'exchange' is not a member of 'std'
.
The comparison predicate in reader::filter
is attempting to order items in descending order of string length, and breaks ties by putting the true booleans before the false booleans.
The problem is that the predicate is ill-formed. A comparison predicate should always return false for compare(a, a)
and should return false for at least one of compare(a, b)
and compare(b, a)
. To put it another way, if compare(a, a)
ever returned true, or compare(a, b)
and compare(b, a)
both returned true, you have an ill-formed predicate.
The filter predicate gets into this situation when there are two entries in exclude
with the same string length, causing misbehavior in release and an assert in debug.
The predicate to sort needs to be updated from
return (size_compare > 0) || ((size_compare == 0) && !lhs.second);
to
return (size_compare > 0) || ((size_compare == 0) && lhs.first && !lhs.second);
It would be great to have docs on how to use this library. Some things I've noticed that weren't obvious to me as a first time user of the library:
std::pair<T, T>
like db.PropertyList()
as a way to enable range-based loops. This is cool but non-obvious, we should document itvalue.Signature().Type().element_type() == ElementType::U4
for WinRTis_enum
on it. These can be filtered out based on e.g. SpecialName()
(lots more to come :) )
A recent change to incorporate the SDK projection removed the hard-coded filtering of non-WinRT types. However, cppwinrt needs this filter to avoid picking up spurious CLR types, issue here. microsoft/cppwinrt#871
for the swift/winrt language projection, we need the ability to filter out exact type names, and not just lazy matching by the beginning of the string. this means changing the implementation of filter::match
from this:
static bool match(std::string_view const& type_namespace, std::string_view const& type_name, std::string_view const& match) noexcept
{
if (match.size() <= type_namespace.size())
{
return impl::starts_with(type_namespace, match);
}
if (!impl::starts_with(match, type_namespace))
{
return false;
}
if (match[type_namespace.size()] != '.')
{
return false;
}
return impl::starts_with(type_name, match.substr(type_namespace.size() + 1));
}
to
static bool match(std::string_view const& type_namespace, std::string_view const& type_name, std::string_view const& match, bool exact) noexcept
{
if (match.size() <= type_namespace.size())
{
if (exact)
{
return type_namespace == match;
}
return impl::starts_with(type_namespace, match);
}
if (!impl::starts_with(match, type_namespace))
{
return false;
}
if (match[type_namespace.size()] != '.')
{
return false;
}
if (exact)
{
return type_name == match.substr(type_namespace.size() + 1);
}
return impl::starts_with(type_name, match.substr(type_namespace.size() + 1));
}
In my WinMD there is a method that returns IList<MyStruct>
. This shows up as a TypeRef and I get IVector`1
and GenericTypeInstSig.gt.GenericArgCount() == 1
, however GenericTypeInstSig.GenericArgs()
is empty
Debugged this via TTT - it turns out my code was doing something like:
if (method.Signature().ReturnType()) {
const auto& type = method.Signature().ReturnType().Type();
returnType = GetType(type);
}
// ...
for (const auto& param : signature.Params()) {
// ...
}
The line where I get the Type() via const auto& was causing the generic params (along other temporaries on that line) to destroy at the end of the line. This can be fixed by removing the &
from my code but I think this might be a bug still?
This is a simple string that says "something" went wrong and I'm not gonna tell ya. Na na nan na nana!
This sort of thing is frustrating for a user as they have no clue what it is referring to. All the information should be there in the code to form a much better message that includes the FQN for the unresolved type, it should also have the module reference to identify what module the type is supposed to come from. This would make resolving such errors WAY easier.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.