diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 1b429ecc1ec..c9431073c8a 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -21,6 +21,10 @@ void Builtin::accept(Visitor &v) { v.visit(*this); } +void Identifier::accept(Visitor &v) { + v.visit(*this); +} + void PositionalParameter::accept(Visitor &v) { v.visit(*this); } diff --git a/src/ast/ast.h b/src/ast/ast.h index 9824813028d..ada3bee2c12 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -63,6 +63,14 @@ class StackMode : public Expression { void accept(Visitor &v) override; }; +class Identifier : public Expression { +public: + explicit Identifier(std::string ident) : ident(ident) {} + std::string ident; + + void accept(Visitor &v) override; +}; + class Builtin : public Expression { public: explicit Builtin(std::string ident) : ident(is_deprecated(ident)) {} @@ -288,6 +296,7 @@ class Visitor { virtual void visit(PositionalParameter &integer) = 0; virtual void visit(String &string) = 0; virtual void visit(Builtin &builtin) = 0; + virtual void visit(Identifier &identifier) = 0; virtual void visit(StackMode &mode) = 0; virtual void visit(Call &call) = 0; virtual void visit(Map &map) = 0; diff --git a/src/ast/codegen_llvm.cpp b/src/ast/codegen_llvm.cpp index d90cf4c6b4b..c8fa36ce53c 100644 --- a/src/ast/codegen_llvm.cpp +++ b/src/ast/codegen_llvm.cpp @@ -45,6 +45,12 @@ void CodegenLLVM::visit(String &string) expr_ = buf; } +void CodegenLLVM::visit(Identifier &identifier) +{ + std::cerr << "unknown identifier \"" << identifier.ident << "\"" << std::endl; + abort(); +} + void CodegenLLVM::visit(Builtin &builtin) { if (builtin.ident == "nsecs") diff --git a/src/ast/codegen_llvm.h b/src/ast/codegen_llvm.h index a22ae46750d..24296e26571 100644 --- a/src/ast/codegen_llvm.h +++ b/src/ast/codegen_llvm.h @@ -30,6 +30,7 @@ class CodegenLLVM : public Visitor { void visit(Integer &integer) override; void visit(PositionalParameter ¶m) override; void visit(String &string) override; + void visit(Identifier &identifier) override; void visit(Builtin &builtin) override; void visit(StackMode &) override { }; void visit(Call &call) override; diff --git a/src/ast/printer.cpp b/src/ast/printer.cpp index cf2382be82c..0a8f09fb03a 100644 --- a/src/ast/printer.cpp +++ b/src/ast/printer.cpp @@ -43,6 +43,12 @@ void Printer::visit(Builtin &builtin) out_ << indent << "builtin: " << builtin.ident << std::endl; } +void Printer::visit(Identifier &identifier) +{ + std::string indent(depth_, ' '); + out_ << indent << "identifier: " << identifier.ident << std::endl; +} + void Printer::visit(Call &call) { std::string indent(depth_, ' '); diff --git a/src/ast/printer.h b/src/ast/printer.h index f73800b05fb..11c23c82d8f 100644 --- a/src/ast/printer.h +++ b/src/ast/printer.h @@ -14,6 +14,7 @@ class Printer : public Visitor { void visit(PositionalParameter ¶m) override; void visit(String &string) override; void visit(StackMode &mode) override; + void visit(Identifier &identifier) override; void visit(Builtin &builtin) override; void visit(Call &call) override; void visit(Map &map) override; diff --git a/src/ast/semantic_analyser.cpp b/src/ast/semantic_analyser.cpp index 95325ef3b2d..4144fa8e6e7 100644 --- a/src/ast/semantic_analyser.cpp +++ b/src/ast/semantic_analyser.cpp @@ -59,6 +59,12 @@ void SemanticAnalyser::visit(StackMode &mode) } } +void SemanticAnalyser::visit(Identifier &identifier) +{ + identifier.type = SizedType(Type::none, 0); + err_ << "Unknown identifier: '" << identifier.ident << "'" << std::endl; +} + void SemanticAnalyser::visit(Builtin &builtin) { if (builtin.ident == "nsecs" || diff --git a/src/ast/semantic_analyser.h b/src/ast/semantic_analyser.h index baa8dfdeebb..f42655fe467 100644 --- a/src/ast/semantic_analyser.h +++ b/src/ast/semantic_analyser.h @@ -23,6 +23,7 @@ class SemanticAnalyser : public Visitor { void visit(PositionalParameter ¶m) override; void visit(String &string) override; void visit(StackMode &mode) override; + void visit(Identifier &identifier) override; void visit(Builtin &builtin) override; void visit(Call &call) override; void visit(Map &map) override; diff --git a/src/parser.yy b/src/parser.yy index fb8e80c1063..ed91e62b2c1 100644 --- a/src/parser.yy +++ b/src/parser.yy @@ -203,6 +203,7 @@ stmt : expr { $$ = new ast::ExprStatement($1); } expr : INT { $$ = new ast::Integer($1); } | STRING { $$ = new ast::String($1); } | BUILTIN { $$ = new ast::Builtin($1); } + | IDENT { $$ = new ast::Identifier($1); } | STACK_MODE { $$ = new ast::StackMode($1); } | ternary { $$ = $1; } | param { $$ = $1; } diff --git a/src/tracepoint_format_parser.h b/src/tracepoint_format_parser.h index eae48a5b35a..f40093dca74 100644 --- a/src/tracepoint_format_parser.h +++ b/src/tracepoint_format_parser.h @@ -17,6 +17,7 @@ class TracepointArgsVisitor : public Visitor void visit(__attribute__((unused)) PositionalParameter &integer) override { }; // Leaf void visit(__attribute__((unused)) String &string) override { }; // Leaf void visit(__attribute__((unused)) StackMode &mode) override { }; // Leaf + void visit(__attribute__((unused)) Identifier &identifier) override { }; // Leaf void visit(Builtin &builtin) override { // Leaf if (builtin.ident == "args") probe_->need_tp_args_structs = true;