Пример #1
0
 protected virtual void VisitTypeTemplate2(TemplateTypeSymbol2 t2)
 {
 }
Пример #2
0
 protected virtual void VisitSimpleTypeBase2(SimpleTypeSymbol t, TemplateTypeSymbol2 baseT2)
 {
 }
Пример #3
0
        public TypeSymbol ResolveType(CodeTypeReference typeRef)
        {
            if (typeRef.ResolvedType != null)
            {
                return(typeRef.ResolvedType);
            }
            //recursive
            switch (typeRef.Kind)
            {
            case CodeTypeReferenceKind.Simple:
            {
                var simpleBase = (CodeSimpleTypeReference)typeRef;
                return(typeRef.ResolvedType = ResolveType(simpleBase.Name));
            }

            case CodeTypeReferenceKind.QualifiedName:
            {
                var qnameType = (CodeQualifiedNameType)typeRef;
                switch (qnameType.LeftPart.ToString())
                {
                //resolve wellknown type template
                case "std":
                    return(ResolveType(qnameType.RightPart));

                default:
                {
                    if (_currentResolvingType != null &&
                        _currentResolvingType.TemplateNotation != null)
                    {
                        //search ns from template notation

                        CodeTemplateParameter foundTemplatePar = null;
                        if (_currentResolvingType.TemplateNotation.TryGetTemplateParByParameterName(qnameType.LeftPart.ToString(), out foundTemplatePar))
                        {
                            //TODO: resolve template type parameter
                            return(typeRef.ResolvedType = new TemplateParameterTypeSymbol(foundTemplatePar));
                        }
                    }
                    //--
                    TypeSymbol found;
                    if (_typeCollection.TryGetType(typeRef.ToString(), out found))
                    {
                        return(found);
                    }
                    throw new NotSupportedException();
                }
                }
            }

            case CodeTypeReferenceKind.TypeTemplate:
            {
                //resolve wellknown type template
                var    typeTemplate = (CodeTypeTemplateTypeReference)typeRef;
                string templateName = typeTemplate.Name;
                //this version => just switch by name first
                //TODO: switch by num of template item
                switch (typeTemplate.Name)
                {
                default:
                    throw new NotSupportedException();

                case "CefOwnPtr":
                case "CefStructBase":
                {
                    TypeSymbol          resolve1 = ResolveType(typeTemplate.Items[0]);
                    TemplateTypeSymbol1 t1       = new TemplateTypeSymbol1(typeTemplate.Name);
                    t1.Item0 = resolve1;
                    return(typeRef.ResolvedType = t1);
                }

                case "multimap":
                case "map":
                {
                    TemplateTypeSymbol2 t2 = new TemplateTypeSymbol2(typeTemplate.Name);
                    t2.Item0 = ResolveType(typeTemplate.Items[0]);
                    t2.Item1 = ResolveType(typeTemplate.Items[1]);
                    return(typeRef.ResolvedType = t2);
                }

                case "CefCppToCScoped":
                case "CefCppToCRefCounted":
                {
                    //cpp to c
                    if (typeTemplate.Items.Count == 3)
                    {
                        //auto add native c/c++ type
                        TemplateTypeSymbol3 t3 = new TemplateTypeSymbol3(typeTemplate.Name);
                        t3.Item1 = ResolveType(typeTemplate.Items[1]);
                        t3.Item2 = this._typeCollection.RegisterBaseCToCppTypeSymbol(typeTemplate.Items[2]);
                        return(typeRef.ResolvedType = t3);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "CefCToCppScoped":
                case "CefCToCppRefCounted":
                case "CefCToCpp":
                {
                    //c to cpp
                    if (typeTemplate.Items.Count == 3)
                    {
                        //auto add native c/c++ type
                        TemplateTypeSymbol3 t3 = new TemplateTypeSymbol3(typeTemplate.Name);
                        t3.Item1 = ResolveType(typeTemplate.Items[1]);
                        t3.Item2 = this._typeCollection.RegisterBaseCToCppTypeSymbol(typeTemplate.Items[2]);
                        return(typeRef.ResolvedType = t3);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "RefCountedThreadSafe":
                {
                    switch (typeTemplate.Items.Count)
                    {
                    case 1:
                        return(typeRef.ResolvedType = ResolveType(typeTemplate.Items[0]));

                    case 2:
                        // from cef c api ,
                        //template <class T, typename Traits = DefaultRefCountedThreadSafeTraits<T> >
                        return(typeRef.ResolvedType = ResolveType(typeTemplate.Items[0]));

                    default:
                        throw new NotSupportedException();
                    }
                }

                case "CefRefPtr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.CefRefPtr));
                    }
                    throw new NotSupportedException();
                }

                case "CefRawPtr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.CefRawPtr));
                    }
                    throw new NotSupportedException();
                }

                case "scoped_ptr":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(ResolveType(typeTemplate.Items[0]), ContainerTypeKind.scoped_ptr));
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                case "vector":
                {
                    if (typeTemplate.Items.Count == 1)
                    {
                        return(typeRef.ResolvedType = new VecTypeSymbol(ResolveType(typeTemplate.Items[0])));
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
                }
            }

            case CodeTypeReferenceKind.Pointer:
            {
                var        pointerType = (CodePointerTypeReference)typeRef;
                TypeSymbol elementType = ResolveType(pointerType.ElementType);
                return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(elementType, ContainerTypeKind.Pointer));
            }

            case CodeTypeReferenceKind.ByRef:
            {
                var        byRefType   = (CodeByRefTypeReference)typeRef;
                TypeSymbol elementType = ResolveType(byRefType.ElementType);
                return(typeRef.ResolvedType = new ReferenceOrPointerTypeSymbol(elementType, ContainerTypeKind.ByRef));
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }