mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +00:00
LibJS: Track which Identifier nodes refer to function arguments
This patch adds an "argument index" field to Identifier AST nodes. If the Identifier refers to a function parameter in the currently open function scope, we stash the index of the parameter here. This will allow us to implement much faster direct access to function argument variables.
This commit is contained in:
parent
ae8b55a80a
commit
481cef59b6
4 changed files with 39 additions and 5 deletions
|
@ -768,13 +768,15 @@ private:
|
|||
|
||||
class Identifier final : public Expression {
|
||||
public:
|
||||
explicit Identifier(SourceRange source_range, FlyString const& string)
|
||||
: Expression(move(source_range))
|
||||
, m_string(string)
|
||||
explicit Identifier(SourceRange source_range, FlyString string, Optional<size_t> argument_index = {})
|
||||
: Expression(source_range)
|
||||
, m_string(move(string))
|
||||
, m_argument_index(move(argument_index))
|
||||
{
|
||||
}
|
||||
|
||||
FlyString const& string() const { return m_string; }
|
||||
Optional<size_t> const& argument_index() const { return m_argument_index; }
|
||||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
@ -785,6 +787,7 @@ private:
|
|||
virtual bool is_identifier() const override { return true; }
|
||||
|
||||
FlyString m_string;
|
||||
Optional<size_t> m_argument_index;
|
||||
};
|
||||
|
||||
class ClassMethod final : public ASTNode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue