aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@digia.com>2014-03-27 12:11:44 +0100
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-03-31 18:36:51 +0200
commit616b8a5526a5a544bca29857d35476c5bcde9c01 (patch)
tree681c99de50811418039cfe1c5784215745902632
parent9061a660fa596298161354827935cc9a90eb5cb6 (diff)
remove JSSourceValue::Alternative::conditionScopeItem
This member held the scope item for the condition of JSSourceValue alternatives (Properties items). However, the condition scope is always the same as the scope item of the JSSourceValue itself. The missing part was that we need to make sure that the scopes always have a valid FileContext pointer. Removing this member made it possible to remove ItemReaderResult::conditionalValuesPerScopeItem as well. This patch will enable us to implement item inheritance by using the prototype chain. Change-Id: I77e976cdfc5af072e35d430b055b6ae1fac930a4 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
-rw-r--r--src/lib/corelib/language/evaluatorscriptclass.cpp6
-rw-r--r--src/lib/corelib/language/itemreader.h2
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.cpp30
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.h3
-rw-r--r--src/lib/corelib/language/moduleloader.cpp3
-rw-r--r--src/lib/corelib/language/value.h1
6 files changed, 12 insertions, 33 deletions
diff --git a/src/lib/corelib/language/evaluatorscriptclass.cpp b/src/lib/corelib/language/evaluatorscriptclass.cpp
index bd75e9ba2..757885531 100644
--- a/src/lib/corelib/language/evaluatorscriptclass.cpp
+++ b/src/lib/corelib/language/evaluatorscriptclass.cpp
@@ -127,9 +127,9 @@ private:
for (int i = 0; i < value->alternatives().count(); ++i) {
const JSSourceValue::Alternative *alternative = 0;
alternative = &value->alternatives().at(i);
- if (conditionScopeItem != alternative->conditionScopeItem) {
- conditionScopeItem = alternative->conditionScopeItem;
- conditionScope = data->evaluator->scriptValue(alternative->conditionScopeItem);
+ if (conditionScopeItem != data->item->scope()) {
+ conditionScopeItem = data->item->scope();
+ conditionScope = data->evaluator->scriptValue(conditionScopeItem);
QBS_ASSERT(conditionScope.isObject(), return);
conditionFileScope = data->evaluator->fileScope(conditionScopeItem->file());
}
diff --git a/src/lib/corelib/language/itemreader.h b/src/lib/corelib/language/itemreader.h
index 75921577c..f22f69d48 100644
--- a/src/lib/corelib/language/itemreader.h
+++ b/src/lib/corelib/language/itemreader.h
@@ -52,8 +52,6 @@ struct ItemReaderResult
{}
Item *rootItem;
- typedef QHash<const Item *, QSet<JSSourceValuePtr> > SourceValuesPerItem;
- SourceValuesPerItem conditionalValuesPerScopeItem;
};
/*
diff --git a/src/lib/corelib/language/itemreaderastvisitor.cpp b/src/lib/corelib/language/itemreaderastvisitor.cpp
index 9a333a989..e824271e5 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.cpp
+++ b/src/lib/corelib/language/itemreaderastvisitor.cpp
@@ -314,7 +314,7 @@ bool ItemReaderASTVisitor::visit(AST::UiObjectDefinition *ast)
if (!baseTypeFileName.isEmpty()) {
const ItemReaderResult baseFile = m_reader->internalReadFile(baseTypeFileName, false);
- inheritItem(item, baseFile.rootItem, baseFile);
+ inheritItem(item, baseFile.rootItem);
if (baseFile.rootItem->m_file->m_idScope) {
// Make ids from the derived file visible in the base file.
// ### Do we want to turn off this feature? It's QMLish but kind of strange.
@@ -490,8 +490,7 @@ void ItemReaderASTVisitor::checkImportVersion(const AST::SourceLocation &version
toCodeLocation(versionToken));
}
-void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src,
- const ItemReaderResult &baseFile)
+void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src)
{
if (!src->typeName().isEmpty())
dst->setTypeName(src->typeName());
@@ -524,8 +523,7 @@ void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src,
QBS_CHECK(v.staticCast<ItemValue>()->item());
QBS_CHECK(it.value().staticCast<const ItemValue>()->item());
inheritItem(v.staticCast<ItemValue>()->item(),
- it.value().staticCast<const ItemValue>()->item(),
- baseFile);
+ it.value().staticCast<const ItemValue>()->item());
} else {
QBS_CHECK(!"unexpected value type");
}
@@ -540,10 +538,6 @@ void ItemReaderASTVisitor::inheritItem(Item *dst, const Item *src,
it != src->m_propertyDeclarations.constEnd(); ++it) {
dst->m_propertyDeclarations[it.key()] = it.value();
}
- foreach (const JSSourceValuePtr &valueWithAlternatives,
- baseFile.conditionalValuesPerScopeItem.value(src)) {
- replaceConditionScopes(valueWithAlternatives, dst);
- }
}
void ItemReaderASTVisitor::ensureIdScope(const FileContextPtr &file)
@@ -568,26 +562,15 @@ void ItemReaderASTVisitor::setupAlternatives(Item *item)
}
}
-void ItemReaderASTVisitor::replaceConditionScopes(const JSSourceValuePtr &value,
- Item *newScope)
-{
- for (QList<JSSourceValue::Alternative>::iterator it
- = value->m_alternatives.begin(); it != value->m_alternatives.end(); ++it)
- it->conditionScopeItem = newScope;
-}
-
class PropertiesBlockConverter
{
public:
PropertiesBlockConverter(const QString &condition, Item *propertiesBlockContainer,
- const Item *propertiesBlock,
- QSet<JSSourceValuePtr> *valuesWithAlternatives)
+ const Item *propertiesBlock)
: m_propertiesBlockContainer(propertiesBlockContainer)
, m_propertiesBlock(propertiesBlock)
- , m_valuesWithAlternatives(valuesWithAlternatives)
{
m_alternative.condition = condition;
- m_alternative.conditionScopeItem = propertiesBlockContainer;
}
void operator()()
@@ -599,7 +582,6 @@ private:
JSSourceValue::Alternative m_alternative;
Item *m_propertiesBlockContainer;
const Item *m_propertiesBlock;
- QSet<JSSourceValuePtr> *m_valuesWithAlternatives;
void apply(Item *a, const Item *b)
{
@@ -636,7 +618,6 @@ private:
}
m_alternative.value = conditionalValue;
value->addAlternative(m_alternative);
- m_valuesWithAlternatives->insert(value);
}
};
@@ -651,8 +632,7 @@ void ItemReaderASTVisitor::handlePropertiesBlock(Item *item, const Item *block)
block->location());
JSSourceValuePtr srcval = value.staticCast<JSSourceValue>();
const QString condition = srcval->sourceCodeForEvaluation();
- PropertiesBlockConverter convertBlock(condition, item, block,
- &m_readerResult->conditionalValuesPerScopeItem[item]);
+ PropertiesBlockConverter convertBlock(condition, item, block);
convertBlock();
}
diff --git a/src/lib/corelib/language/itemreaderastvisitor.h b/src/lib/corelib/language/itemreaderastvisitor.h
index 109f0a753..dae481c3b 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.h
+++ b/src/lib/corelib/language/itemreaderastvisitor.h
@@ -66,8 +66,7 @@ private:
Item *targetItemForBinding(Item *item, const QStringList &binding,
const JSSourceValueConstPtr &value);
void checkImportVersion(const QbsQmlJS::AST::SourceLocation &versionToken) const;
- static void inheritItem(Item *dst, const Item *src,
- const ItemReaderResult &baseFile);
+ static void inheritItem(Item *dst, const Item *src);
void ensureIdScope(const FileContextPtr &file);
void setupAlternatives(Item *item);
static void replaceConditionScopes(const JSSourceValuePtr &value, Item *newScope);
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 0fe18b90f..e6c911d6e 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -217,6 +217,7 @@ void ModuleLoader::handleProject(ModuleLoaderResult *loadResult, Item *item,
projectContext.item = item;
ItemValuePtr itemValue = ItemValue::create(item);
projectContext.scope = Item::create(m_pool);
+ projectContext.scope->setFile(item->file());
projectContext.scope->setProperty(QLatin1String("project"), itemValue);
foreach (Item *child, item->children()) {
@@ -303,6 +304,7 @@ void ModuleLoader::handleProduct(ProjectContext *projectContext, Item *item)
ItemValuePtr itemValue = ItemValue::create(item);
productContext.scope = Item::create(m_pool);
productContext.scope->setProperty(QLatin1String("product"), itemValue);
+ productContext.scope->setFile(item->file());
productContext.scope->setScope(projectContext->scope);
DependsContext dependsContext;
dependsContext.product = &productContext;
@@ -859,6 +861,7 @@ void ModuleLoader::instantiateModule(ProductContext *productContext, Item *insta
// create module scope
Item *moduleScope = Item::create(m_pool);
+ moduleScope->setFile(instanceScope->file());
moduleScope->setScope(instanceScope);
copyProperty(QLatin1String("project"), productContext->project->scope, moduleScope);
copyProperty(QLatin1String("product"), productContext->scope, moduleScope);
diff --git a/src/lib/corelib/language/value.h b/src/lib/corelib/language/value.h
index a3a2bb457..6114f6b89 100644
--- a/src/lib/corelib/language/value.h
+++ b/src/lib/corelib/language/value.h
@@ -114,7 +114,6 @@ public:
struct Alternative
{
QString condition;
- const Item *conditionScopeItem;
JSSourceValuePtr value;
};