Commit Graph

50 Commits

Author SHA1 Message Date
Daniel Mensinger 7c757dff71 holders: Fix the remaining code to respect the holder changes 2021-06-18 23:48:33 +02:00
Daniel Mensinger 63ade7d937 interpreter: Add a new MesonInterpreterObject for non-elementary objects 2021-06-18 23:48:33 +02:00
Xavier Claessens a45f939092 Add range() function
Fixes: #5026.
2021-03-16 20:50:16 -04:00
Jussi Pakkanen fcbab5948c Refactor subdir visitation to track files instead of dirs. 2021-03-06 13:11:20 +02:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Daniel Mensinger 057c77f7d0
typing: fixup for #7708 2020-09-08 20:46:11 +02:00
Daniel Mensinger 9c1e72202d
typing: refactor dict handling 2020-09-08 20:15:55 +02:00
Paolo Bonzini 4ed5c3acbf IntrospectInterpreter: allow dictionaries with nonconstant keys
Something like {a: foo} currently stymies the IntrospectionInterpreter and
breaks introspection of the source directory.  The fix is just to walk the keys
and return a dummy dictionary.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-09-08 19:56:20 +02:00
Daniel Mensinger 54511b4a0f
ast: Handle NotNode 2020-05-23 18:13:25 +02:00
Xavier Claessens 4d6faf6a13 interpreterbase: Add warning when built-in object method has no kwargs 2020-03-19 23:01:58 +02:00
Daniel Mensinger 213d2f18fc ast: Implement dummy evaluate_notstatement 2020-03-06 19:47:33 +01:00
Xavier Claessens b78db74ed5 ast: Do not resolve dict keys
Fixes: #6748
2020-03-06 11:50:22 -05:00
Daniel Mensinger d67888bf9b
types: Remove redundant __init__() -> None annotation 2020-03-02 10:52:59 +01:00
Daniel Mensinger ab988198c7
review: Initial fixup 2020-03-02 10:47:20 +01:00
Daniel Mensinger ad5df1b9c3
types: Annotate ast/introspection.py 2020-03-02 10:44:01 +01:00
Daniel Mensinger 5a89a6f804
types: (partially) annotate interpreterbase.py
This commit annotates most of interpreterbase.py. However,
there are stil the @wraps missing, since I am unsure what
the types are supposed to be here.
2020-03-02 10:42:43 +01:00
Daniel Mensinger c48b0dea27
types: Annotate ast/interpreter.py 2020-03-02 10:34:55 +01:00
Daniel Mensinger a75255bc4c
types: Annotate the AST visitors 2020-03-02 10:34:55 +01:00
Daniel Mensinger c14aea2812
types: Annotate mparser.py
This also fixes that the keys in ArgumentNode.kwargs are
all of the type BaseNode now. Before this commit, it was
possible that both strings and Nodes where used as keys.
2020-03-02 10:34:55 +01:00
Jon Turney 346b5c4be7
Store filename in node location
Warnings have a location node object (with subdir and lineno
attributes), which is passed as a location: kwarg to mlog.warning() and
formatted in _log_error().

Re-purpose the subdir attribute (path relative to the source root dir,
with an implied filename of 'meson.build'), which is stored into the
node by parser(), to contain a pathname.

(Properly I should rename 'subdir' -> 'file' everywhere, but that's a
lot of churn just to see if this works)

Notes:
The warning location node may also have a colno attribute, which is
currently ignored by _log_error().

We can't currently issue warnings with locations in meson_options.txt
because the filename isn't part of the location (as it's assumed to be
'meson.build).
2020-02-28 11:54:04 +00:00
Jon Turney 534a974da7
Adjust all the other places MesonException file attribute is set
A MesonException has file, lineno and colno attributes, which get
formatted as a location in mlog.exception().

The file attribute got changed from a path relative to the root source
directory to a pathname (absolute or relative to cwd) in one place in
commit b8fbbf59.  Adjust all the other places the file attribute is set
to match.

Also:
Setting MesonException.file seems to be missing in the case where Parser
returned a non-CodeBlockNode object.  Fortunately, that looks like it's
unreachable, but add it just in case.
2020-02-28 11:54:04 +00:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Xavier Claessens 6e865a2330 Add a summary() function for configuration summarization
Based on patch from Dylan Baker.

Fixes #757
2019-12-12 18:30:17 -05:00
Wolfgang Stöggl f037e7ef45 Fix typos found by codespell
- Typos were found by codespell v1.16.0
2019-11-06 09:55:30 -05:00
Daniel Mensinger bd37147b4b mintro: Fix resolving nodes in kwargs (fixes #5884) 2019-09-04 15:05:41 -07:00
James Hilliard b21fd95f73 Add is_disabler function
This is useful if one needs to check if a variable is a disabler.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2019-08-12 01:05:45 +03:00
Daniel Mensinger b72b5365af mintro: Fix crash related to the sources kwarg (fixes #5741) 2019-07-31 00:30:17 +03:00
Xavier Claessens 12d4031f52 Add alias_target() function 2019-07-10 15:01:18 -04:00
Daniel Mensinger cacc585b44 ast: fix #5376 2019-05-13 02:48:35 +03:00
Daniel Mensinger 8e587dfeba
ast: Address code review 2019-04-23 09:10:48 +02:00
Daniel Mensinger b7ba98a657
make flake8 happy 2019-04-23 09:10:48 +02:00
Daniel Mensinger 38f2eae681
ast: Make sure to avoid infinite recursions 2019-04-23 09:10:48 +02:00
Daniel Mensinger 75b7a856cd
ast: support elementary object methods 2019-04-23 09:10:47 +02:00
Daniel Mensinger feff2630ae
ast: resolve simple arithmetic nodes 2019-04-23 09:10:47 +02:00
Daniel Mensinger 2bb4ec19f2
ast: resolve ID nodes in flatten_args 2019-04-23 09:10:42 +02:00
Dylan Baker add821db64 Don't use mutable types as default arguments
This isn't safe given the way python implements default arguments.
Basically python store a reference to the instance it was passed, and
then if that argument is not provided it uses the default. That means
that two calls to the same function get the same instance, if one of
them mutates that instance every subsequent call that gets the default
will receive the mutated instance. The idiom to this in python is to use
None and replace the None,

def in(value: str, container: Optional[List[str]]) -> boolean:
   return src in (container or [])

if there is no chance of mutation it's less code to use or and take
advantage of None being falsy. If you may want to mutate the value
passed in you need a ternary (this example is stupid):

def add(value: str, container: Optional[List[str]]) -> None:
    container = container if container is not None else []
    container.append(value)

I've used or everywhere I'm sure that the value will not be mutated by
the function and erred toward caution by using ternaries for the rest.
2019-04-23 02:03:19 +03:00
Daniel Mensinger c04651fe24 mintro: Fix set_variable plus assign bug (closes #5256) 2019-04-13 09:51:15 +00:00
Daniel Mensinger 6da0df95c1
mintro: fix some interpreter crashes 2019-04-02 11:39:45 +02:00
Daniel Mensinger e724fd5438
rewriter: Handle duplicate target 2019-03-04 13:00:29 +01:00
Daniel Mensinger 24a2cf02e2
Can now find the assignment node of a value 2019-02-16 14:10:08 +01:00
Jussi Pakkanen 939b011114
Merge pull request #4858 from mensinda/rwKWARGS
rewriter: Add support for kwargs modification
2019-02-16 14:17:49 +02:00
Daniel Mensinger da7b9df16c Ensure that func dicts provide the same set of functions 2019-02-01 11:49:52 +00:00
Daniel Mensinger 8224ecfbe6
Some fixes and assignment based target find 2019-01-31 15:43:04 +01:00
Daniel Mensinger 6fe2c2b209
Fixed flake8 issues 2019-01-22 17:31:15 +01:00
Daniel Mensinger 86d5799bc4
First rewriter test case 2019-01-22 16:41:06 +01:00
Daniel Mensinger f6339d6361
Added support for assignments in the AST interpretor 2019-01-22 16:09:35 +01:00
Daniel Mensinger 08da3873dd
Added target AST Interpreter support 2019-01-22 16:09:35 +01:00
Daniel Mensinger 005a62491b
Removed the RewriteIntrepreter 2019-01-22 16:09:35 +01:00
Daniel Mensinger 750af9c853
Moved the introspection interpreter 2019-01-22 16:09:34 +01:00
Daniel Mensinger ccad493e85
Basic AST visitor pattern 2019-01-22 16:09:34 +01:00