Start implementing template class support

Add 'type-template' tag (and 'arg' child tag) to declare a definition of
a template struct/class. Modify 'object-type' and 'value-type' to allow
creating these as template instantiations referencing a 'type-template',
as an alternative to the usual non-template support.

There is also a 'redirect' attribute on 'arg' that will be used to
create "redirection" methods on the wrapped class to allow calling
methods of a template argument class as if they belonged to the
instantiation, which is sort of like having an operator->().

The eventual goal is to support wrapping of e.g. QSharedPointer.

This is sufficient to parse a typesystem XML (updates to 'sample'
included) using the new tags, but not to do anything useful yet, as
neither type resolution is working, nor do we generate code for the
instantiations.

Change-Id: I37960727c4dd69c39e84a414ae08752e3fd0dbf3
(Partly) implement wrappers for instantiations

Teach AbstractMetaBuilder to create wrappers for template instantiation
types. Teach generators to generate valid code for the same.

This is quite half-baked, as type resolution for instantiations is not
yet working (which tends to defeat the purpose). However, a typesystem
defining template instantiation types now generates code which also
compiles (and 'sample' is updated accordingly).

To facilitate code generation, fixedCppTypeName(QString) is now a public
static member of ShibokenGenerator, and is used in quite a few places
that previously only replaced '::'. This is needed as instantiation
wrappers have <>'s in their names that also need to be replaced, and
since the additional substitutions that fixedCppTypeName performs should
be harmless, this way we are using a helper function that already
existed rather than creating a new one for the purpose.

Change-Id: I7d077e89d9c3190e6850c1e04aac23a1f179c33b
Implement type look-up for template instantiatons

Teach translateType() to find and translate template instantiation
types. Teach buildAbstractMetaTypeFromString() how to create
AbstractMetaType's for the same.

This suffices to recognize and translate template instantiation types.
However, since redirection is not yet implemented, and adding methods
directly to the instantiation is not currently working, the wrapped
objects aren't of much use except as opaque handles.

However, this is enough to have at least the start of a meaningful unit
test, and one is accordingly added to 'sample'.

Change-Id: I3aee6ece8ad769a07127ff5fdd67a7af2d05200d
Implement instantiation resolutions

Tweak how we iterate over instantiations to have proper argument
reporting, and to be cleaner and (for the second pass anyway) more
efficient. Implement resolution of template arguments on instantiations.
Implement redirections on template instantiations. Add unit test for
redirections.

Change-Id: I51ac71154cd2e8c2c82e4e1dd6305d90661ceced
Fix adding functions to instantiations

Add the little tiny missing piece of code that broke adding new methods
to a template instantiation type. Add unit test for this.

Change-Id: I4e03805d83669af3b036451845394ca7a5a95276
Test resolution of typedefs of type-templates

Improve type-template test case to test that Shiboken recognizes and
correctly resolves typedefs of type-template instantiations.

Change-Id: I613c3f1938561e8dabb25438616316e314163e7d
Fix container argument resolution corner case

Fix a corner case where type resolution for a container type breaks due
to failing to add the template arguments, due to trailing whitespace
causing resolution of the same to fail. As best I can tell, this only
happens for redirector functions of type-template instantiations inside
of namespaces for which the type-template is also inside of a namespace.

Change-Id: Ie5934bcc03ada92c42df49e255ef6df743f9fac6
Fix scoped resolution of instantiations

Modify AbstractMetaBuilder::translateType, and in particular the
associated helper function findTypeEntryUsingContext, to also find
type-template instantiations within a namespace scope.

Change-Id: Id4408fefcb3f3badfe940f15d0f6adab9edc52a3
Fix type alias creation for instantiations

Modify Binder to correctly qualify type aliases for template
instantiations. This seems to mainly be a problem for type-template
instantiations, but may affect regular instantiations as well. Also
convert the set of qualified types to a QSet (which should be slightly
less expensive than an unused QString value on a QHash). Modify the
tests to exercise the newly-working resolution.

This is in some ways closely related to the previous two commits, and
the test updates are at least partly relevant to those also.

Change-Id: I45ae5ea9573d0c9ba26dd60c3b70056d13e9868c
Fix resolution of instantiation arguments

Modify translateType to also try a canonicalized form of the type name.
This is necessary to resolve function arguments to type-template
instantiations, as the canonical instantiation name has spaces inside
the <>'s, but the function argument has these stripped due to minimal
signature normalization. (Return types are not normalized and so do not
have this problem.)

Change-Id: Ide191042c709f995a04ff7b77855c0e6f80a7d9c
Fix instantiation naming

Fix ::name of AbstractMeta{Type,Class} for type-template instantiations.
These were giving odd results because namespace splitting could split on
a template argument and throw out the actual type name and resulting in
names like 'Object >'. This doesn't seem to obviously affect code
generation (probably it works because the names are still unique for the
cases we've tested so far, but would have collisions in case of more
than one instantiation with the same template argument(s)), but helps
with debugging when inspecting the name()s.

Change-Id: I7de115b31496bf605b9f660d106ba1d6082bfe7f
Omit redirections for protected members

Don't generate redirections to internal class's protected members. This
isn't working right, because it requires a static cast of the inner
class to its wrapper to bypass the access protection, but right now the
generated code is doing the cast on the outer class instead (which is
otherwise the right thing to do). Since 1) it's questionable if
protected methods should be exposed anyway, and 2) likely significant
work to get it working, just disable it for now.

Change-Id: Ia7e3aee3ffd4f670fc74735cec3248dcf8f0d2ef
Always sanitize name of wrapper classes

It isn't obvious why only "inner classes" would need their names
sanitized; at least within our tests, no classes that trip this flag
have names that need to be sanitized. However, names of type template
instantiations must always be sanitized, and there is no ready check for
these at the moment, so just sanitize everything. (It may have just been
for performance reasons that we weren't doing this anyway, but this
shouldn't be in the critical path for that we need to be overly worried
about performance here.)

Change-Id: Ic13089efde9793fc5da8acd049e9d54363f5efa7
Use qualified name for wrapper class name

When generating wrapper classes, use the mangled qualified name instead
of just the base name. This is required to avoid symbol collisions in
the case of wrapping two classes with the same name in different
namespaces.

This doesn't "really" belong on this branch, as it applies to Shiboken
in general, however it effectively depends on the mangling that was
added here, and especially the previous commit, where we changed to
always mangle the wrapper name.

Change-Id: I276a97b4eac4385307a94159437ee4757d88a196
Support type-template function modifications

Modify typesystem parser to (partly) set the correct context for
function additions/modifications to type-template. Modify
AbstractMetaBuilder::createInstantiationMetaClass to add functions from
the type template to the instantiation.

This is only partly complete; template argument types are not yet
supported as types in the function.

Change-Id: Ie6369d2facf3bcd642e9a2a51cbb107046e9094d
Remove unneeded code

Don't bother adding redirection functions to the instantiation type
entry; they are only needed for adding the functions to the abstract
meta objects, which we are doing anyway, and are not needed by the
generate phase, so adding them to the type entry also is superfluous.

Change-Id: I81adc0a3e4d460e98c4a9849da6bbafe65f1ad61
Fix type resolution for type-template functions

Modify type resolution of function modifications to accept a mapping of
template arguments, in order to support e.g. '%INTYPE_0' as return
and/or argument types to functions. This is relevant to function
modifications declared on type templates.

An example of such is added to the sample binding, however there is no
test yet, as functions added to instantiations via type templates are
not being added correctly at the moment. (This will be fixed in the next
commit.)

Change-Id: I8875354547aae2d56d66b5697f1672287717c7b0
Fix type template function additions

Fix the code to add functions from type templates to instantiations to
also copy the code modifications. This fixes the functions being
generated with 'empty' bodies as explained in the previous commit.
Update the unit test to call these, now that they are useful.

Change-Id: I29527973e87cfe7aaf8b5769eb0aa7e7c36ba61f
Fix late resolution of instantiation arguments

Modify ShibokenGenerator::buildAbstractMetaTypeFromString to
canonicalize type names before trying to look up instantiations. Move
canonicalization function to AbstractMetaClass, and use when returning
the name of template instantiation classes.

This should ensure that everyone is looking at the same form of the type
name. This fixes a crash or assertion (depending on whether the type
appears by itself, or as a template type in a container-type) due to
failure to look up the type when it is used in code snippets.

Change-Id: Ic090138a9db9a3acbbd93a9015e07a9504080fd4
Reject container types with unknown arguments

Modify ShibokenGenerator::buildAbstractMetaTypeFromString to explicitly
reject container types if resolution of a template argument type fails.
This prevents us crashing later due to the type having an instantiation
type that is null. (We still exit abnormally, but at least now there is
a useful error message as to why.)

Change-Id: Ief704a7f9d1f50867fc904a5c397435136af9017