summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibCpp/AST.h3
-rw-r--r--Userland/Libraries/LibCpp/Parser.cpp16
-rw-r--r--Userland/Libraries/LibCpp/Parser.h1
3 files changed, 15 insertions, 5 deletions
diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h
index c89f3388f3..eec5c38224 100644
--- a/Userland/Libraries/LibCpp/AST.h
+++ b/Userland/Libraries/LibCpp/AST.h
@@ -182,6 +182,7 @@ public:
virtual ~Parameter() override = default;
virtual const char* class_name() const override { return "Parameter"; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
+ virtual bool is_parameter() const override { return true; }
Parameter(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename, StringView name)
: VariableOrParameterDeclaration(parent, start, end, filename)
@@ -189,8 +190,6 @@ public:
m_name = name;
}
- virtual bool is_parameter() const override { return true; }
-
bool m_is_ellipsis { false };
};
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp
index 7b7d674801..136175599a 100644
--- a/Userland/Libraries/LibCpp/Parser.cpp
+++ b/Userland/Libraries/LibCpp/Parser.cpp
@@ -870,15 +870,25 @@ String Parser::text_of_node(const ASTNode& node) const
String Parser::text_in_range(Position start, Position end) const
{
+ StringBuilder builder;
+ for (auto token : tokens_in_range(start, end)) {
+ builder.append(token.text());
+ }
+ return builder.to_string();
+}
+
+Vector<Token> Parser::tokens_in_range(Position start, Position end) const
+{
auto start_token_index = index_of_token_at(start);
auto end_node_index = index_of_token_at(end);
VERIFY(start_token_index.has_value());
VERIFY(end_node_index.has_value());
- StringBuilder text;
+
+ Vector<Token> tokens;
for (size_t i = start_token_index.value(); i <= end_node_index.value(); ++i) {
- text.append(m_tokens[i].text());
+ tokens.append(m_tokens[i]);
}
- return text.build();
+ return tokens;
}
void Parser::error(StringView message)
diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h
index 63b8e5278c..665d8f71ee 100644
--- a/Userland/Libraries/LibCpp/Parser.h
+++ b/Userland/Libraries/LibCpp/Parser.h
@@ -49,6 +49,7 @@ public:
Preprocessor::DefinedValue preprocessor_value;
};
const Vector<TokenAndPreprocessorDefinition>& replaced_preprocessor_tokens() const { return m_replaced_preprocessor_tokens; }
+ Vector<Token> tokens_in_range(Position start, Position end) const;
private:
enum class DeclarationType {