Unlocking the Power of Atlas (4): Understanding Atlas Queries
In the previous article, we explored how Atlas Shell brings the powerful analysis capabilities of Atlas to your fingertips. But to truly harness its potential, it’s essential to understand the query language that powers this tool. Let’s dive in and uncover what makes this language so impactful.
Atlas Query Language
The Atlas query language is designed to leverage the full power of its specialized graph database, making complex software analysis both intuitive and efficient. At its core, the language can be broken down into three primary categories:
- Selections
- Set Operations
- Graph Traversals
While there’s much more to explore within the language, these three categories form the foundation of its functionality, enabling users to navigate and analyze code with precision. Let’s explore the three individually.
- Selection
This category of queries focuses on selecting code artifacts that meet specific criteria. Since Atlas represents all code artifacts as either nodes or edges within its graph database, the key queries in this set are:
G.nodes(<criteria>)
for selecting nodes.G.edges(<criteria>)
for selecting edges.
These queries form the foundation for isolating and analyzing relevant components within the codebase. The G variable represents the subgraph from which you are selecting nodes/edges. The criteria is described using the database schema of Atlas, eXtensible Common Software Graph (XCSG [1].
2. Set Operations
The result of a selection query in Atlas is always a graph — a collection of nodes and edges. And when working with sets like these, it’s natural to need set operations such as union, intersection, and difference. Atlas provides built-in queries for these operations:
G1.union(G2)
: Combines the node sets and edge sets ofG1
andG2
.G1.intersection(G2)
: Returns only the overlapping nodes and edges betweenG1
andG2
.G1.difference(G2)
: Produces the nodes and edges inG1
that are not inG2
.
These operations enable developers to perform advanced manipulations on graph-based representations, offering the flexibility needed for complex code analysis.
3. Graph Traversals
When working with graphs, traversals are essential for exploring relationships and dependencies. Atlas offers powerful graph traversal queries to navigate its graph-based representations:
G.forward(node)
/G.reverse(node)
: Traverse forward or backward starting from a specific node, following the edges in graphG
.G.predecessors(node)
/G.successors(node)
: Identify all nodes that directly precede or follow a given node in graphG
.G.between(node1, node2)
: Find all paths in graphG
that start atnode1
and end atnode2
.
Graph traversals form the backbone of Atlas analysis, enabling detailed exploration of control flows, dependencies, and relationships within the codebase. And this is just the beginning — there’s much more to uncover about the full potential of graph operations. Stay tuned for deeper dives into this fascinating subject!
The Atlas query language is a gateway to unlocking the full potential of Atlas’s powerful graph database. With its ability to select, manipulate, and traverse code artifacts, it empowers developers to perform sophisticated analyses with precision and flexibility. From filtering specific code elements to navigating intricate relationships, the query language equips you with the tools to tackle even the most complex software systems. Whether you’re just starting or looking to deepen your understanding, mastering these queries is a step toward unparalleled insights into your codebase. The journey into Atlas’s graph capabilities is far from over — there’s much more to explore!
[1] A Humane, Graph-Based Representation of Programs and Analyses, Whitepaper: https://ensoftcorp.com/papers/XCSGWhitepaper.pdf