From babebadc29f217033aca52bee78cf5af46290997 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 19 May 2015 10:33:56 +0200 Subject: [PATCH] replace sourceNamne by contractName --- mix/CodeModel.cpp | 87 +++++++++++++++++++++------------------ mix/qml/WebCodeEditor.qml | 21 +++++++--- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 769497dcd..9875ee1aa 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -45,7 +45,7 @@ using namespace dev::mix; const std::set c_predefinedContracts = - { "Config", "Coin", "CoinReg", "coin", "service", "owned", "mortal", "NameReg", "named", "std", "configUser" }; +{ "Config", "Coin", "CoinReg", "coin", "service", "owned", "mortal", "NameReg", "named", "std", "configUser" }; namespace @@ -56,7 +56,7 @@ class CollectLocalsVisitor: public ASTConstVisitor { public: CollectLocalsVisitor(QHash* _locals): - m_locals(_locals), m_functionScope(false) {} + m_locals(_locals), m_functionScope(false) {} private: LocationPair nodeLocation(ASTNode const& _node) @@ -96,7 +96,7 @@ class CollectLocationsVisitor: public ASTConstVisitor { public: CollectLocationsVisitor(SourceMap* _sourceMap): - m_sourceMap(_sourceMap) {} + m_sourceMap(_sourceMap) {} private: LocationPair nodeLocation(ASTNode const& _node) @@ -339,7 +339,14 @@ QVariantMap CodeModel::resolveCompilationErrorLocation(CompilerStack const& _com QVariantMap error; error.insert("start", startError); error.insert("end", endError); - error.insert("source", QString::fromStdString(*_location.sourceName)); + QString sourceName; + if (_location.sourceName) + sourceName = QString::fromStdString(*_location.sourceName); + error.insert("source", sourceName); + if (!sourceName.isEmpty()) + if (CompiledContract* contract = contractByDocumentId(sourceName)) + sourceName = contract->contract()->name(); //substitute the location to match our contract names + error.insert("contractName", sourceName); return error; } @@ -385,7 +392,7 @@ void CodeModel::collectContracts(dev::solidity::CompilerStack const& _cs, std::v { //make sure there are no other contracts in the same source, otherwise it is not a rename if (!std::any_of(result.begin(),result.end(), [=](ContractMap::const_iterator::value_type _v) { return _v != contract && _v->documentId() == contract->documentId(); })) - prevContract = c.value(); + prevContract = c.value(); } } if (prevContract != nullptr && prevContract->contractInterface() != result[name]->contractInterface()) @@ -435,59 +442,59 @@ SolidityType CodeModel::nodeType(dev::solidity::Type const* _type) switch (_type->getCategory()) { case Type::Category::Integer: - { - IntegerType const* it = dynamic_cast(_type); - r.size = it->getNumBits() / 8; - r.type = it->isAddress() ? SolidityType::Type::Address : it->isSigned() ? SolidityType::Type::SignedInteger : SolidityType::Type::UnsignedInteger; - } + { + IntegerType const* it = dynamic_cast(_type); + r.size = it->getNumBits() / 8; + r.type = it->isAddress() ? SolidityType::Type::Address : it->isSigned() ? SolidityType::Type::SignedInteger : SolidityType::Type::UnsignedInteger; + } break; case Type::Category::Bool: r.type = SolidityType::Type::Bool; break; case Type::Category::FixedBytes: - { - FixedBytesType const* b = dynamic_cast(_type); - r.type = SolidityType::Type::Bytes; - r.size = static_cast(b->getNumBytes()); - } + { + FixedBytesType const* b = dynamic_cast(_type); + r.type = SolidityType::Type::Bytes; + r.size = static_cast(b->getNumBytes()); + } break; case Type::Category::Contract: r.type = SolidityType::Type::Address; break; case Type::Category::Array: + { + ArrayType const* array = dynamic_cast(_type); + if (array->isByteArray()) + r.type = SolidityType::Type::Bytes; + else { - ArrayType const* array = dynamic_cast(_type); - if (array->isByteArray()) - r.type = SolidityType::Type::Bytes; - else - { - SolidityType elementType = nodeType(array->getBaseType().get()); - elementType.name = r.name; - r = elementType; - } - r.count = static_cast(array->getLength()); - r.dynamicSize = _type->isDynamicallySized(); - r.array = true; + SolidityType elementType = nodeType(array->getBaseType().get()); + elementType.name = r.name; + r = elementType; } + r.count = static_cast(array->getLength()); + r.dynamicSize = _type->isDynamicallySized(); + r.array = true; + } break; case Type::Category::Enum: - { - r.type = SolidityType::Type::Enum; - EnumType const* e = dynamic_cast(_type); - for(auto const& enumValue: e->getEnumDefinition().getMembers()) - r.enumNames.push_back(QString::fromStdString(enumValue->getName())); - } + { + r.type = SolidityType::Type::Enum; + EnumType const* e = dynamic_cast(_type); + for(auto const& enumValue: e->getEnumDefinition().getMembers()) + r.enumNames.push_back(QString::fromStdString(enumValue->getName())); + } break; case Type::Category::Struct: + { + r.type = SolidityType::Type::Struct; + StructType const* s = dynamic_cast(_type); + for(auto const& structMember: s->getMembers()) { - r.type = SolidityType::Type::Struct; - StructType const* s = dynamic_cast(_type); - for(auto const& structMember: s->getMembers()) - { - auto slotAndOffset = s->getStorageOffsetsOfMember(structMember.name); - r.members.push_back(SolidityDeclaration { QString::fromStdString(structMember.name), nodeType(structMember.type.get()), slotAndOffset.first, slotAndOffset.second }); - } + auto slotAndOffset = s->getStorageOffsetsOfMember(structMember.name); + r.members.push_back(SolidityDeclaration { QString::fromStdString(structMember.name), nodeType(structMember.type.get()), slotAndOffset.first, slotAndOffset.second }); } + } break; case Type::Category::Function: case Type::Category::IntegerConstant: diff --git a/mix/qml/WebCodeEditor.qml b/mix/qml/WebCodeEditor.qml index af3eda094..32e62d584 100644 --- a/mix/qml/WebCodeEditor.qml +++ b/mix/qml/WebCodeEditor.qml @@ -83,9 +83,9 @@ Item { editorBrowser.runJavaScript("setFontSize(" + size + ")", function(result) {}); } - function setSourceName(sourceName) + function setSourceName(_sourceName) { - sourceName = sourceName; + sourceName = _sourceName; if (initialized && editorBrowser) editorBrowser.runJavaScript("setSourceName('" + sourceName + "')", function(result) {}); } @@ -148,19 +148,28 @@ Item { { if (!editorBrowser || !error) return; + + var lineError = firstLocation.start.line + 1; + var errorOrigin = "source error in " + firstLocation.contractName + " line " + lineError + var secondErrorDetail = " Secondary sources: "; + for (var k in secondLocations) + { + lineError = secondLocations[k].start.line + 1; + secondErrorDetail += secondLocations[k].contractName + " line " + lineError + ", "; + displayErrorAnnotations(secondLocations[k], errorOrigin, "second"); + } var detail = error.split('\n')[0]; var reg = detail.match(/:\d+:\d+:/g); if (reg !== null) detail = detail.replace(reg[0], ""); + detail += secondErrorDetail; displayErrorAnnotations(firstLocation, detail, "first"); - for (var k in secondLocations) - displayErrorAnnotations(secondLocations[k], detail, "second"); } function displayErrorAnnotations(location, detail, type) { - //if (location.source === parent.sourceName) - editorBrowser.runJavaScript("compilationError('" + JSON.stringify(location) + "', '" + detail + "', '" + type + "')", function(result){}); + if (location.source === parent.sourceName) + editorBrowser.runJavaScript("compilationError('" + JSON.stringify(location) + "', '" + detail + "', '" + type + "')", function(result){}); } Timer