When creating a sub-map for repetitions, we need to be weary of not
accessing matched-fragments beyond the vector's size. For example, with
the following *fragments*
{ "e": [1], "es": [2, 3, 10]},
the sub-maps we want to create are the following:
{ "e": [1], "es": [2]},
{ "e": [1], "es": [3]},
{ "e": [1], "es": [10]},
Up until this point however, we were trying to access the second index
for the "e" metavar when creating the second submap, then the third, and
so on... which is obviously outside of the vector's bounds.
We can simply check if the metavar only has one match and expand that
one in that case. We still need to work on checking that multiple
metavars in the same transcriber repetition pattern have the same amount
of matched fragments (ie the original vectors of matches in the
original map have the same size)
This ports over the code from the cpp front-end which implements the cpp
nodiscard attribute which has the same behaviour and is also implemented
in the front-end explicitly.
Fixes#856
The gcc abstraction contained a method of turning expressions into
statements which used to contain their own types like Bstatement,
Bexpression this produced awkward interfaces which we no longer require.
This is part of a patch series to introduce the CPP front-end
convert_to_void to port over the support for the nodiscard attribute which
maps nicely over to Rust's must_use attribute.
Fixes the -fself-test invalid memory accesses and adds documentation
regarding a possible future fix.
Co-authored-by: tschwinge <thomas@schwinge.name>
Co-authored-by: philberty <philip.herron@embecosm.com>
When creating a sub-map for repetitions, we need to be weary of not
accessing matched-fragments beyond the vector's size. For example, with
the following *fragments*
{ "e": [1], "es": [2, 3, 10]},
the sub-maps we want to create are the following:
{ "e": [1], "es": [2]},
{ "e": [1], "es": [3]},
{ "e": [1], "es": [10]},
Up until this point however, we were trying to access the second index
for the "e" metavar when creating the second submap, then the third, and
so on... which is obviously outside of the vector's bounds.
We can simply check if the metavar only has one match and expand that
one in that case. We still need to work on checking that multiple
metavars in the same transcriber repetition pattern have the same amount
of matched fragments (ie the original vectors of matches in the
original map have the same size)
981: macro-expand: Add SubstitutionCtx class in its own file r=CohenArthur a=CohenArthur
The `MacroExpander` class had multiple static functions which were constantly passing the same parameters around for expansion. This refactor adds a new `SubstituteCtx` class which keeps track of the three common arguments given to the substitute functions, and offers these implementations in a new source file to keep the original expander light.
Closes#957
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
When parsing a macro invocation as a statement, the parser would parse
an expression and then try parsing a semicolon. Since no actual
lookahead was done (which is a good thing), we couldn't convert a
`MacroInvocation` to a `MacroInvocationSemi` after the fact.
Since, unlike function calls, macro invocations can act differently
based on whether or not they are followed by a semicolon, we actually
need to differentiate between the two up until expansion.
This commits adds a new virtual method for ExprWithoutBlock when
converting to ExprStmtWithoutBlock so that classes inheriting
ExprWithoutBlock can specify a new behavior. In the case of our
MacroInvocation class, it simply means toggling a boolean: If we're
converting a macro from an expression to a statement, it must mean that
it should contain a semicolon.
In order to conform to the rust reference, we must make sure that when
parsing -frust-cfg key-value pairs, we actually parse a valid key and
value. The key must be a valid identifier, while the value must be a
valid identifier surrounded by double quotes
By allowing us to parse strings directly instead of necessarily a
filename, we are now able to reuse the parser and lexer in various
places of the compiler. This is useful for -frust-cfg, but may also come
in handy for
other compiler mechanics such as the include!() builtin macro, where we
do not actually want location info but just a stream of tokens.
954: HIR Visitor refactoring r=philberty a=dkm
This change split the single HIR visitor in smaller abstract ones:
- Stmt
- VisItem
- Pattern
- ExternalItem
- Impl
- Type
- Expression
Instead of providing a Base class with empty visit() methods, they are kept
abstract to avoid the case where a missing visit() is silently ignored:
implementors must explicitely override all visit.
There is also a FullVisitor that covers all HIR nodes and also provides a Base
class with empty behavior.
fixes#825
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
This change split the single HIR visitor in smaller abstract ones:
- Stmt
- VisItem
- Pattern
- ExternalItem
- Impl
- Type
- Expression
Instead of providing a Base class with empty visit() methods, they are kept
abstract to avoid the case where a missing visit() is silently ignored:
implementors must explicitely override all visit.
There is also a FullVisitor that covers all HIR nodes and also provides a Base
class with empty behavior.
fixes#825
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
974: Add support for ranges and index lang items along with the TyTy::SliceType r=philberty a=philberty
This PR contains more code to begin supporting Slices which requires support
for more intrinsic, range and index lang items. More work is needed to support
slices such as the const_ptr lang item and the offset intrinsic but this is a big
PR already and adds support for more lang items along the way.
Fixes#975
Addresses #849
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This reuses our code to resolve operator overloads to call into the index
lang item for the array-index-expression this serves as a basis for
supporting slices.
Fixes#975
This means we can reuse the same code for operations that are not
HIR::OperatorExpr's such as ArrayIndexExpr which can resolve to
core::ops::index lang items.
969: Add builtin macros framework r=CohenArthur a=CohenArthur
This PR adds bases to define new builtin macro functions.
Since we operate at the `insert_macro_def` level, this requires builtin macros to be defined, as is the case in the rust standard library:
```rust
macro_rules! assert {
($cond:expr $(,)?) => {{ /* compiler built-in */ }};
($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
}
```
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
956: Substitute repetitions r=CohenArthur a=CohenArthur
Needs #955
This PR splits up the `substitute_tokens` function into multiple smaller functions. Still a draft until I can get repetitions working.
Closes#960Closes#961
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
953: Refactor lang item mappings r=philberty a=philberty
This refactors how we find our lang items so that during HIR lowering
we have a generic outer attributes handler on Items. The old code only
done lang item mappings during the type check pass and assumed all
lang items are Traits which is not the case. To implement slices range
syntax actually map to structs within libcore/ops/range.rs which have
lang items on structs. This means we can have lang items on any Item.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This class keeps track of all known builtin attributes and specifies which
pass they are handled at. This replaces the checks we added for outer
attributes during hir lowering making it a more maintainable data
structure.