Skip to content

Commit

Permalink
PR #505: Iterative definition resolving
Browse files Browse the repository at this point in the history
Fixes #435

GitHub PR #505

Copybara import of the project:

  - c686585 CheckPoint by MinaToma <[email protected]>
  - 20fc26d check point by MinaToma <[email protected]>
  - 590ef44 Iterative Defintion Resolving by MinaToma <[email protected]>
  - 0dd2ed7 Tests for resolving definitions by MinaToma <[email protected]>
  - 122030c Fix Typo by MinaToma <[email protected]>
  - 48304cd Fix Typo by MinaToma <[email protected]>
  - 9260916 some refactoring and comments by MinaToma <[email protected]>
  - 773a216 Merge 9260916 into ded8a... by Mina Toma <[email protected]>

Closes #505

PiperOrigin-RevId: 334357291
  • Loading branch information
MinaToma authored and hzeller committed Sep 29, 2020
1 parent 6b0edca commit e57f68b
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 324 deletions.
4 changes: 2 additions & 2 deletions verilog/CST/declaration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ const SyntaxTreeNode& GetUnqualifiedIdFromLocalRoot(const Symbol& local_root) {

const verible::SyntaxTreeNode& GetUnqualifiedIdFromReferenceCallBase(
const verible::Symbol& reference_call_base) {
const SyntaxTreeNode& refernce =
const SyntaxTreeNode& reference =
GetReferenceFromReferenceCallBase(reference_call_base);
const SyntaxTreeNode& local_root = GetLocalRootFromReference(refernce);
const SyntaxTreeNode& local_root = GetLocalRootFromReference(reference);
return GetUnqualifiedIdFromLocalRoot(local_root);
}

Expand Down
3 changes: 2 additions & 1 deletion verilog/tools/kythe/indexing_facts_tree_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ void IndexingFactsTreeExtractor::ExtractMethodCallExtension(
IndexingNodeData function_node_data(IndexingFactType::kFunctionCall);
IndexingFactNode function_node(function_node_data);

if (facts_tree_context_.top().Children().empty()) {
if (facts_tree_context_.empty() ||
facts_tree_context_.top().Children().empty()) {
return;
}

Expand Down
54 changes: 54 additions & 0 deletions verilog/tools/kythe/kythe_facts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
namespace verilog {
namespace kythe {

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Signature::operator==(const Signature& other) const {
return this->ToString() == other.ToString();
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Signature::operator<(const Signature& other) const {
return this->ToString() < other.ToString();
}
Expand All @@ -53,6 +55,16 @@ std::string Signature::ToBase64() const {
return absl::Base64Escape(ToString());
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool VName::operator==(const VName& other) const {
return this->ToString() == other.ToString();
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool VName::operator<(const VName& other) const {
return this->ToString() < other.ToString();
}

std::string VName::ToString() const {
return absl::Substitute(
R"({"signature": "$0","path": "$1","language": "$2","root": "$3","corpus": "$4"})",
Expand All @@ -64,5 +76,47 @@ std::ostream& operator<<(std::ostream& stream, const VName& vname) {
return stream;
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Fact::operator==(const Fact& other) const {
return this->ToString() == other.ToString();
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Fact::operator<(const Fact& other) const {
return this->ToString() < other.ToString();
}

std::string Fact::ToString() const {
return absl::Substitute(
R"({"source": $0,"fact_name": "$1","fact_value": "$2"})",
node_vname.ToString(), fact_name, absl::Base64Escape(fact_value));
}

std::ostream& operator<<(std::ostream& stream, const Fact& fact) {
stream << fact.ToString();
return stream;
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Edge::operator==(const Edge& other) const {
return this->ToString() == other.ToString();
}

// TODO(minatoma): change this string comparison to a tuple comparison.
bool Edge::operator<(const Edge& other) const {
return this->ToString() < other.ToString();
}

std::string Edge::ToString() const {
return absl::Substitute(
R"({"source": $0,"edge_kind": "$1","target": $2,"fact_name": "/"})",
source_node.ToString(), edge_name, target_node.ToString());
}

std::ostream& operator<<(std::ostream& stream, const Edge& edge) {
stream << edge.ToString();
return stream;
}

} // namespace kythe
} // namespace verilog
56 changes: 54 additions & 2 deletions verilog/tools/kythe/kythe_facts.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Signature {
names_.push_back(std::string(name));
}

bool operator==(const Signature& o) const;
bool operator<(const Signature& o) const;
bool operator==(const Signature& other) const;
bool operator<(const Signature& other) const;

// Returns the the signature concatenated as a string.
std::string ToString() const;
Expand Down Expand Up @@ -81,6 +81,9 @@ struct VName {
corpus(corpus),
root(root) {}

bool operator==(const VName& other) const;
bool operator<(const VName& other) const;

std::string ToString() const;

// Unique identifier for this VName.
Expand All @@ -101,6 +104,55 @@ struct VName {

std::ostream& operator<<(std::ostream&, const VName&);

// Facts for kythe.
// For more information:
// https://www.kythe.io/docs/kythe-storage.html#_a_id_termfact_a_fact
// https://www.kythe.io/docs/schema/writing-an-indexer.html#_modeling_kythe_entries
struct Fact {
Fact(const VName& vname, absl::string_view name, absl::string_view value)
: node_vname(vname), fact_name(name), fact_value(value) {}

bool operator==(const Fact& other) const;
bool operator<(const Fact& other) const;

std::string ToString() const;

// The vname of the node this fact is about.
const VName node_vname;

// The name identifying this fact.
const std::string fact_name;

// The given value to this fact.
const std::string fact_value;
};

std::ostream& operator<<(std::ostream&, const Fact&);

// Edges for kythe.
// For more information:
// https://www.kythe.io/docs/schema/writing-an-indexer.html#_modeling_kythe_entries
struct Edge {
Edge(const VName& source, absl::string_view name, const VName& target)
: source_node(source), edge_name(name), target_node(target) {}

bool operator==(const Edge& other) const;
bool operator<(const Edge& other) const;

std::string ToString() const;

// The vname of the source node of this edge.
const VName source_node;

// The edge name which identifies the edge kind.
const std::string edge_name;

// The vname of the target node of this edge.
const VName target_node;
};

std::ostream& operator<<(std::ostream&, const Edge&);

} // namespace kythe
} // namespace verilog

Expand Down
Loading

0 comments on commit e57f68b

Please sign in to comment.