================ @@ -0,0 +1,263 @@ +//===-- DILParser.cpp -----------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This implements the recursive descent parser for the Data Inspection +// Language (DIL), and its helper functions, which will eventually underlie the +// 'frame variable' command. The language that this parser recognizes is +// described in lldb/docs/dil-expr-lang.ebnf +// +//===----------------------------------------------------------------------===// + +#include "lldb/ValueObject/DILParser.h" +#include "lldb/Target/ExecutionContextScope.h" +#include "lldb/ValueObject/DILAST.h" +#include "lldb/ValueObject/DILEval.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/FormatAdapters.h" +#include <limits.h> +#include <memory> +#include <sstream> +#include <stdlib.h> +#include <string> + +namespace lldb_private::dil { + +std::string FormatDiagnostics(llvm::StringRef text, const std::string &message, + uint32_t loc) { + // Get the position, in the current line of text, of the diagnostics pointer. + // ('loc' is the location of the start of the current token/error within the + // overal text line). + int32_t arrow = loc + 1; // Column offset starts at 1, not 0. + + return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc, message, + llvm::fmt_pad(text, 0, 0), + llvm::fmt_pad("^", arrow - 1, 0)); +} + +llvm::Expected<ASTNodeUP> +DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer, + std::shared_ptr<StackFrame> frame_sp, + lldb::DynamicValueType use_dynamic, bool use_synthetic, + bool fragile_ivar, bool check_ptr_vs_member) { + Status error; + DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic, + fragile_ivar, check_ptr_vs_member, error); + return parser.Run(); +} + +DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer, + std::shared_ptr<StackFrame> frame_sp, + lldb::DynamicValueType use_dynamic, bool use_synthetic, + bool fragile_ivar, bool check_ptr_vs_member, Status &error) + : m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), m_dil_lexer(lexer), + m_error(error), m_use_dynamic(use_dynamic), + m_use_synthetic(use_synthetic), m_fragile_ivar(fragile_ivar), + m_check_ptr_vs_member(check_ptr_vs_member) {} + +llvm::Expected<ASTNodeUP> DILParser::Run() { + ASTNodeUP expr; + + expr = ParseExpression(); ---------------- labath wrote:
```suggestion ASTNodeUP expr = ParseExpression(); ``` https://github.com/llvm/llvm-project/pull/120971 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits