Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/typebuilder.cpp
Context not available. | |||||
26 | #include <language/duchain/ducontext.h> | 26 | #include <language/duchain/ducontext.h> | ||
---|---|---|---|---|---|
27 | #include <language/duchain/declaration.h> | 27 | #include <language/duchain/declaration.h> | ||
28 | #include <language/duchain/types/integraltype.h> | 28 | #include <language/duchain/types/integraltype.h> | ||
29 | #include <language/duchain/types/arraytype.h> | ||||
29 | #include "../declarations/classdeclaration.h" | 30 | #include "../declarations/classdeclaration.h" | ||
30 | #include "../types/indexedcontainer.h" | | |||
31 | #include "../types/integraltypeextended.h" | 31 | #include "../types/integraltypeextended.h" | ||
32 | #include "../types/structuretype.h" | 32 | #include "../types/structuretype.h" | ||
33 | #include <duchaindebug.h> | 33 | #include <duchaindebug.h> | ||
Context not available. | |||||
57 | 57 | | |||
58 | AbstractType::Ptr TypeBuilder::parseType(QString type, AstNode* node) | 58 | AbstractType::Ptr TypeBuilder::parseType(QString type, AstNode* node) | ||
59 | { | 59 | { | ||
60 | uint iType = 0; | | |||
61 | type = type.trimmed(); | 60 | type = type.trimmed(); | ||
61 | | ||||
62 | if (type.contains('|')) { | ||||
63 | QList<AbstractType::Ptr> types; | ||||
64 | foreach (const QString& t, type.split('|')) { | ||||
65 | AbstractType::Ptr subType = parseType(t, node); | ||||
66 | if (!(IntegralType::Ptr::dynamicCast(subType) && IntegralType::Ptr::staticCast(subType)->dataType() == IntegralType::TypeMixed)) { | ||||
67 | types << parseType(t, node); | ||||
68 | } | ||||
69 | } | ||||
70 | UnsureType::Ptr ret(new UnsureType()); | ||||
71 | foreach (const AbstractType::Ptr& t, types) { | ||||
72 | ret->addType(t->indexed()); | ||||
73 | } | ||||
74 | return AbstractType::Ptr::staticCast(ret); | ||||
75 | } | ||||
76 | | ||||
77 | if (type.endsWith(QLatin1String("[]"))) { | ||||
78 | KDevelop::ArrayType* a_type = new KDevelop::ArrayType(); | ||||
79 | a_type->setElementType(parseSimpleType(type.left(type.length() - 2), node)); | ||||
80 | return AbstractType::Ptr(a_type); | ||||
81 | } else { | ||||
82 | return parseSimpleType(type, node); | ||||
83 | } | ||||
84 | } | ||||
85 | | ||||
86 | AbstractType::Ptr TypeBuilder::parseSimpleType(QString type, AstNode* node) | ||||
87 | { | ||||
88 | uint iType = 0; | ||||
62 | if (!type.compare(QLatin1String("int"), Qt::CaseInsensitive) || !type.compare(QLatin1String("integer"), Qt::CaseInsensitive)) { | 89 | if (!type.compare(QLatin1String("int"), Qt::CaseInsensitive) || !type.compare(QLatin1String("integer"), Qt::CaseInsensitive)) { | ||
63 | iType = IntegralType::TypeInt; | 90 | iType = IntegralType::TypeInt; | ||
64 | } else if (!type.compare(QLatin1String("float"), Qt::CaseInsensitive) || !type.compare(QLatin1String("double"), Qt::CaseInsensitive)) { | 91 | } else if (!type.compare(QLatin1String("float"), Qt::CaseInsensitive) || !type.compare(QLatin1String("double"), Qt::CaseInsensitive)) { | ||
Context not available. | |||||
101 | if (decl && decl->abstractType()) { | 128 | if (decl && decl->abstractType()) { | ||
102 | return decl->abstractType(); | 129 | return decl->abstractType(); | ||
103 | } | 130 | } | ||
104 | if (type.contains('|')) { | | |||
105 | QList<AbstractType::Ptr> types; | | |||
106 | foreach (const QString& t, type.split('|')) { | | |||
107 | AbstractType::Ptr subType = parseType(t, node); | | |||
108 | if (!(IntegralType::Ptr::dynamicCast(subType) && IntegralType::Ptr::staticCast(subType)->dataType() == IntegralType::TypeMixed)) { | | |||
109 | types << parseType(t, node); | | |||
110 | } | | |||
111 | } | | |||
112 | if (!type.isEmpty()) { | | |||
113 | UnsureType::Ptr ret(new UnsureType()); | | |||
114 | foreach (const AbstractType::Ptr& t, types) { | | |||
115 | ret->addType(t->indexed()); | | |||
116 | } | | |||
117 | //qCDebug(DUCHAIN) << type << ret->toString(); | | |||
118 | return AbstractType::Ptr::staticCast(ret); | | |||
119 | } | | |||
120 | } | | |||
121 | iType = IntegralType::TypeMixed; | 131 | iType = IntegralType::TypeMixed; | ||
122 | } | 132 | } | ||
123 | AbstractType::Ptr ret(new IntegralType(iType)); | 133 | AbstractType::Ptr ret(new IntegralType(iType)); | ||
Context not available. | |||||
572 | } | 582 | } | ||
573 | } | 583 | } | ||
574 | } | 584 | } | ||
585 | } else if ( ArrayType::Ptr a_type = ArrayType::Ptr::dynamicCast(v.result().type()) ) { | ||||
586 | injectType(a_type->elementType()); | ||||
587 | foundType = true; | ||||
575 | } | 588 | } | ||
589 | | ||||
576 | if (!foundType) { | 590 | if (!foundType) { | ||
577 | injectType(AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed))); | 591 | injectType(AbstractType::Ptr(new IntegralType(IntegralType::TypeMixed))); | ||
578 | } | 592 | } | ||
Context not available. |