Skip to content

Commit

Permalink
Add Expression::resolve string set
Browse files Browse the repository at this point in the history
Adding Expression::resolve string unordered set to
keep a list of strings that need to be resolved.

It will be used in following patches as a list
to resolve with BTF data.

It's static set so it's cleared in the Driver
constructor, which is the starting point for
parsing.
  • Loading branch information
olsajiri authored and danobi committed Sep 26, 2019
1 parent 80cb0d7 commit 0779333
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/ast/ast.cpp
Expand Up @@ -5,6 +5,11 @@
namespace bpftrace {
namespace ast {

std::unordered_set<std::string>& Expression::getResolve() {
static std::unordered_set<std::string> s;
return s;
}

void Integer::accept(Visitor &v) {
v.visit(*this);
}
Expand Down
24 changes: 20 additions & 4 deletions src/ast/ast.h
Expand Up @@ -5,6 +5,7 @@
#include <map>
#include <string>
#include <vector>
#include <unordered_set>

#include "types.h"

Expand Down Expand Up @@ -34,6 +35,7 @@ class Expression : public Node {
bool is_map = false;
Expression() : Node(){};
Expression(location loc) : Node(loc){};
static std::unordered_set<std::string>& getResolve();
};
using ExpressionList = std::vector<Expression *>;

Expand Down Expand Up @@ -86,12 +88,22 @@ class Identifier : public Expression {

class Builtin : public Expression {
public:
explicit Builtin(std::string ident) : ident(is_deprecated(ident)) {}
explicit Builtin(std::string ident, location loc) : Expression(loc), ident(is_deprecated(ident)) {}
explicit Builtin(std::string ident) : ident(is_deprecated(ident)) {
resolve_curtask(ident);
}
explicit Builtin(std::string ident, location loc) : Expression(loc), ident(is_deprecated(ident)) {
resolve_curtask(ident);
}
std::string ident;
int probe_id;

void accept(Visitor &v) override;

private:
void resolve_curtask(std::string& ident) {
if (ident == "curtask")
getResolve().insert("task_struct");
}
};

class Call : public Expression {
Expand Down Expand Up @@ -174,9 +186,13 @@ class ArrayAccess : public Expression {
class Cast : public Expression {
public:
Cast(const std::string &type, bool is_pointer, Expression *expr)
: cast_type(type), is_pointer(is_pointer), expr(expr) { }
: cast_type(type), is_pointer(is_pointer), expr(expr) {
getResolve().insert(type);
}
Cast(const std::string &type, bool is_pointer, Expression *expr, location loc)
: Expression(loc), cast_type(type), is_pointer(is_pointer), expr(expr) { }
: Expression(loc), cast_type(type), is_pointer(is_pointer), expr(expr) {
getResolve().insert(type);
}
std::string cast_type;
bool is_pointer;
Expression *expr;
Expand Down
1 change: 1 addition & 0 deletions src/driver.cpp
Expand Up @@ -13,6 +13,7 @@ namespace bpftrace {

Driver::Driver(BPFtrace &bpftrace, std::ostream &o) : bpftrace_(bpftrace), out_(o)
{
ast::Expression::getResolve().clear();
yylex_init(&scanner_);
parser_ = std::make_unique<Parser>(*this, scanner_);
}
Expand Down

0 comments on commit 0779333

Please sign in to comment.