Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/declarationbuilder.cpp
Show First 20 Lines • Show All 592 Lines • ▼ Show 20 Line(s) | 588 | if (Declaration* dec = currentContext()->findDeclarationAt(startPos(node))) { | |||
---|---|---|---|---|---|
593 | } | 593 | } | ||
594 | } | 594 | } | ||
595 | } | 595 | } | ||
596 | return; | 596 | return; | ||
597 | } | 597 | } | ||
598 | 598 | | |||
599 | DUChainWriteLocker lock(DUChain::lock()); | 599 | DUChainWriteLocker lock(DUChain::lock()); | ||
600 | 600 | | |||
601 | // check for redeclaration of private or protected stuff | | |||
602 | { | | |||
603 | // only interesting context might be the class context when we are inside a method | | |||
604 | DUContext *ctx = currentContext()->parentContext(); | | |||
605 | foreach ( Declaration* dec, parentCtx->findDeclarations(identifier) ) { | | |||
606 | if ( ClassMemberDeclaration* cdec = dynamic_cast<ClassMemberDeclaration*>(dec) ) { | | |||
607 | if ( cdec->accessPolicy() == Declaration::Private && cdec->context() != ctx ) { | | |||
608 | reportError(i18n("Cannot redeclare private property %1 from this context.", | | |||
609 | cdec->toString()), node); | | |||
610 | return; | | |||
611 | } else if ( cdec->accessPolicy() == Declaration::Protected | | |||
612 | && cdec->context() != ctx | | |||
613 | && ( !ctx || !ctx->imports(cdec->context()) ) ) { | | |||
614 | reportError(i18n("Cannot redeclare protected property %1 from this context.", | | |||
615 | cdec->toString()), node); | | |||
616 | return; | | |||
617 | } | | |||
618 | if ( cdec->abstractType()->indexed() == type->indexed() ) { | | |||
619 | encounter(dec); | | |||
620 | return; | | |||
621 | } | | |||
622 | } | | |||
623 | } | | |||
624 | } | | |||
625 | | ||||
626 | // this member should be public and non-static | 601 | // this member should be public and non-static | ||
627 | m_currentModifers = ModifierPublic; | 602 | m_currentModifers = ModifierPublic; | ||
628 | injectContext(parentCtx); | 603 | injectContext(parentCtx); | ||
629 | openClassMemberDeclaration(node, identifier); | 604 | openClassMemberDeclaration(node, identifier); | ||
630 | m_currentModifers = 0; | 605 | m_currentModifers = 0; | ||
631 | //own closeDeclaration() that doesn't use lastType() | 606 | //own closeDeclaration() that doesn't use lastType() | ||
632 | currentDeclaration()->setType(type); | 607 | currentDeclaration()->setType(type); | ||
633 | eventuallyAssignInternalContext(); | 608 | eventuallyAssignInternalContext(); | ||
▲ Show 20 Lines • Show All 569 Lines • ▼ Show 20 Line(s) | |||||
1203 | 1178 | | |||
1204 | ///TODO: we need to handle assignment to array-members properly | 1179 | ///TODO: we need to handle assignment to array-members properly | ||
1205 | /// currently we just make sure the array is declared, but don't know | 1180 | /// currently we just make sure the array is declared, but don't know | ||
1206 | /// anything about its contents | 1181 | /// anything about its contents | ||
1207 | void DeclarationBuilder::visitAssignmentExpressionEqual(AssignmentExpressionEqualAst *node) | 1182 | void DeclarationBuilder::visitAssignmentExpressionEqual(AssignmentExpressionEqualAst *node) | ||
1208 | { | 1183 | { | ||
1209 | DeclarationBuilderBase::visitAssignmentExpressionEqual(node); | 1184 | DeclarationBuilderBase::visitAssignmentExpressionEqual(node); | ||
1210 | 1185 | | |||
1211 | if ( !m_findVariable.identifier.isEmpty() && currentAbstractType()) { | 1186 | bool alreadyDeclared = false; | ||
1187 | | ||||
1188 | // check for already declared class members | ||||
1189 | if (!m_findVariable.identifier.isEmpty() && !m_findVariable.parentIdentifier.isEmpty()) { | ||||
1190 | DUContext* ctx = getClassContext(m_findVariable.parentIdentifier, currentContext()); | ||||
1191 | if (ctx) { | ||||
1192 | DUChainReadLocker lock(DUChain::lock()); | ||||
1193 | ifDebug(qCDebug(DUCHAIN) << "checking if already declared: " << m_findVariable.identifier.toString();) | ||||
1194 | QList<Declaration*> decs; | ||||
1195 | foreach ( Declaration* dec, currentContext()->findDeclarations(m_findVariable.identifier) ) { | ||||
1196 | if ( dec->kind() == Declaration::Kind::Instance) { | ||||
1197 | ClassMemberDeclaration *classDec = dynamic_cast<ClassMemberDeclaration*>(dec); | ||||
brauch: move this down below the next condition, it doesn't need it | |||||
1198 | | ||||
1199 | if (dec->range() == editorFindRange(m_findVariable.node)) { | ||||
1200 | // Don't reuse previous declarations as the type might have changed. | ||||
1201 | continue; | ||||
1202 | } | ||||
1203 | | ||||
1204 | if (classDec && classDec->accessPolicy() == Declaration::Private) { | ||||
1205 | if (currentContext()->parentContext() == dec->context()) { | ||||
1206 | decs << dec; | ||||
1207 | ifDebug(qCDebug(DUCHAIN) << "found class property:" << dec->toString();) | ||||
1208 | } | ||||
1209 | } else { | ||||
1210 | decs << dec; | ||||
1211 | ifDebug(qCDebug(DUCHAIN) << "found class property:" << dec->toString();) | ||||
1212 | } | ||||
1213 | } | ||||
1214 | } | ||||
1215 | lock.unlock(); | ||||
I don't think you are allowed to unlock the lock here, you are still using the items below ... but in the builder code, stuff like this usually works because you have the parse lock in addition, so no idea. brauch: I don't think you are allowed to unlock the lock here, you are still using the items below ... | |||||
1216 | | ||||
1217 | if (!decs.isEmpty()) { | ||||
1218 | Declaration * dec = decs.last(); | ||||
1219 | | ||||
1220 | if (dec) { | ||||
1221 | encounter(dec); | ||||
1222 | alreadyDeclared = true; | ||||
1223 | IntegralType::Ptr type = dec->type<IntegralType>(); | ||||
1224 | | ||||
1225 | if (type && type->dataType() == IntegralType::TypeNull) { | ||||
1226 | DUChainWriteLocker wlock(DUChain::lock()); | ||||
brauch: replace by: DUChainWriteLocker wlock; | |||||
1227 | dec->setAbstractType(currentAbstractType()); | ||||
1228 | wlock.unlock(); | ||||
brauch: remove this, it's unlocked automatically here anyways | |||||
1229 | } | ||||
1230 | } | ||||
1231 | } | ||||
1232 | | ||||
1233 | lock.lock(); | ||||
1234 | if (decs.isEmpty() && (!currentContext()->parentContext() || !currentContext()->parentContext()->imports(ctx))) { | ||||
1235 | ifDebug(qCDebug(DUCHAIN) << "nothing found in current context, look in class context of parent";) | ||||
1236 | QList<Declaration*> decs; | ||||
1237 | foreach ( Declaration* dec, ctx->findDeclarations(m_findVariable.identifier) ) { | ||||
1238 | if ( dec->kind() == Declaration::Kind::Instance) { | ||||
1239 | if (dec->range() == editorFindRange(m_findVariable.node)) { | ||||
1240 | // Don't reuse previous declarations as the type might have changed. | ||||
1241 | continue; | ||||
1242 | } | ||||
1243 | | ||||
1244 | ifDebug(qCDebug(DUCHAIN) << "found class property:" << dec->toString();) | ||||
1245 | decs << dec; | ||||
1246 | } | ||||
1247 | } | ||||
1248 | lock.unlock(); | ||||
brauch: as above | |||||
1249 | | ||||
1250 | if (!decs.isEmpty()) { | ||||
1251 | Declaration * dec = decs.last(); | ||||
1252 | | ||||
1253 | if (dec) { | ||||
1254 | alreadyDeclared = true; | ||||
1255 | IntegralType::Ptr type = dec->type<IntegralType>(); | ||||
1256 | | ||||
1257 | // check for redeclaration of private or protected stuff | ||||
1258 | DUContext *parentCtx = currentContext()->parentContext(); | ||||
1259 | ClassMemberDeclaration *classDec = dynamic_cast<ClassMemberDeclaration*>(dec); | ||||
1260 | | ||||
1261 | if (classDec && classDec->accessPolicy() == Declaration::Private && classDec->context() != parentCtx) { | ||||
1262 | reportError(i18n("Cannot access private property %1", | ||||
1263 | classDec->toString()), m_findVariable.node); | ||||
1264 | } else if (classDec && classDec->accessPolicy() == Declaration::Protected && classDec->context() != parentCtx) { | ||||
1265 | reportError(i18n("Cannot access protected property %1", | ||||
1266 | classDec->toString()), m_findVariable.node); | ||||
1267 | } else if (type && type->dataType() == IntegralType::TypeNull) { | ||||
1268 | DUChainWriteLocker wlock(DUChain::lock()); | ||||
1269 | dec->setAbstractType(currentAbstractType()); | ||||
1270 | wlock.unlock(); | ||||
brauch: remove | |||||
1271 | } | ||||
1272 | } | ||||
1273 | } | ||||
1274 | } | ||||
1275 | } | ||||
1276 | } | ||||
1277 | | ||||
1278 | if ( !alreadyDeclared && !m_findVariable.identifier.isEmpty() && currentAbstractType()) { | ||||
1279 | ifDebug(qCDebug(DUCHAIN) << "not yet declared: " << m_findVariable.identifier.toString();) | ||||
1212 | //create new declaration assignments to not-yet declared variables and class members | 1280 | //create new declaration assignments to not-yet declared variables and class members | ||
1213 | 1281 | | |||
1214 | AbstractType::Ptr type; | 1282 | AbstractType::Ptr type; | ||
1215 | if ( m_findVariable.isArray ) { | 1283 | if ( m_findVariable.isArray ) { | ||
1216 | // implicit array declaration | 1284 | // implicit array declaration | ||
1217 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeArray)); | 1285 | type = AbstractType::Ptr(new IntegralType(IntegralType::TypeArray)); | ||
1218 | } else { | 1286 | } else { | ||
1219 | type = currentAbstractType(); | 1287 | type = currentAbstractType(); | ||
▲ Show 20 Lines • Show All 442 Lines • Show Last 20 Lines |
move this down below the next condition, it doesn't need it