Commit Graph

192641 Commits

Author SHA1 Message Date
Arthur Cohen 425ebda243 type-path-fn: Add location info on start of Fn token 2022-02-18 09:10:52 +01:00
Arthur Cohen ef06769781 path-id: Add location info on path identifier 2022-02-18 09:08:07 +01:00
Arthur Cohen 9e524a7f5a closure-arg: Add location info on arg name 2022-02-18 09:08:07 +01:00
Arthur Cohen 63538444fb struct-base: Add location info on `..` token 2022-02-18 09:08:07 +01:00
Arthur Cohen d120c9db18 array-copy-init: Add location info 2022-02-18 09:08:07 +01:00
Arthur Cohen c6daece647 array-values: Add location info 2022-02-18 09:08:07 +01:00
Arthur Cohen 205a9cbf9e fn-arg: Add location on parameter name 2022-02-18 09:08:07 +01:00
bors[bot] 9fb06d66ce
Merge #938
938: First pass at declarative macro expansion  r=philberty a=philberty

This does not support repetition matchers but it supports simple
declarative macros and transcribes them. The approach taken here is that
we reuse our existing parser to call the apropriate functions as specified
as part of the MacroFragmentType enum if the parser does not have errors
parsing that item then it must be a match.
    
Then once we match a rule we have a map of the token begin/end offsets
for each fragment match, this is then used to adjust and create a new token
stream for the macro rule definition so that when we feed it to the parser
the tokens are already substituted. The resulting expression or item is
then attached to the respective macro invocation and this is then name
resolved and used for hir lowering.
    
Fixes #17 #22
Addresses #573

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-17 17:02:43 +00:00
M V V S Manoj Kumar ee4131396e Removed Lambda Function within AST::PathPattern
Addresses issue #717
1) Changed the rust-path.h and removed the iterate_path_segments
   fuction.
2) Removed the lambda fuction form rust-ast-lower.cc and replaced it
   with a for loop.

Signed-off-by : M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2022-02-17 22:11:23 +05:30
Philip Herron 37415eec77 Semicolon based macro invocation
This allows for macro invocation at the toplevel or as statements. This
patched required us to propogate the delimited token tree fix to include
the delimiter tokens. The rest of the fix was straight forward to call
the apropriate visitors in names resolution and hir lowering.

Some thought will be needed to handle hir lowering for repeating items.
2022-02-17 16:41:15 +00:00
Philip Herron 4c70d7ec77 Support block expressions within macros
When we parse DelimTokenTree's the delimiter's are synthesised when we
ask for the token stream which results in tokens lacking location info.
This removes the hack by adding the actual tokens from the lexer into the
stream.
2022-02-17 13:28:25 +00:00
Philip Herron 19c5dde80f When we expand a macro we must visit it to ensure any cfg expansions or recursive macro expansion is required 2022-02-17 13:28:25 +00:00
Philip Herron 2c03f34027 Add initial support for macro expansion
This is the first pass at implementing macros more testcases are needed.

This does not support repetition matchers but it supports simple
declarative macros and transcribes them. The approach taken here is that
we reuse our existing parser to call the apropriate functions as specified
as part of the MacroFragmentType enum if the parser does not have errors
parsing that item then it must be a match.

Then once we match a rule we have a map of the token begin/end offsets
for each fragment match, this is then used to adjust and create a new token
stream for the macro rule definition so that when we feed it to the parser
the tokens are already substituted. The resulting expression or item is
then attached to the respective macro invocation and this is then name
resolved and used for hir lowering.

Fixes #17 #22
Addresses #573
2022-02-17 13:28:25 +00:00
Philip Herron ef626302f7 Add name-resolution helpers for looking up macros 2022-02-17 13:28:24 +00:00
Philip Herron a026c166f0 Add mappings helpers for looking up macros definitions 2022-02-17 13:28:24 +00:00
Philip Herron 864df7901c Add missing copyright header to lexer header 2022-02-17 13:28:24 +00:00
bors[bot] 752bf6c80a
Merge #935
935: frust-cfg: Only allow double quoted values r=philberty a=CohenArthur

Closes #910 

This PR separates the `handle_cfg_option()` function in two, separating the parsing logic from the session logic. The parsing logic is able to be unit tested, and now only allows quoted values.

What remains to be done is to only allow `key` and `value` to be proper rust identifiers. We need to figure out if we'd like to spawn a parser here and parse identifiers, or simply sanitize both strings to make sure they do not contain invalid characters.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-17 10:58:07 +00:00
Arthur Cohen 766a9002a3 frust-cfg: Only allow double quoted values
This commit separates the `handle_cfg_option()` function in two,
separating the parsing logic from the session logic. The parsing logic
is able to be unit tested, and now only allows quoted values.
2022-02-17 11:23:25 +01:00
bors[bot] 6a6c217093
Merge #932
932: Add location information to MacroRule r=CohenArthur a=CohenArthur

Closes #930 

This PR adds location information to the `MacroRule` structure.

The location is from the beginning of the invokation pattern, so that errors look like so:
```rust
test.rs:2:5: error: ...
    2 |     ($a:expr, $b:expr) => { a + b }
      |     ^
```

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-17 09:22:03 +00:00
Arthur Cohen c1e72db48a macrorule: Add location information 2022-02-17 10:20:13 +01:00
bors[bot] d81ba63f48
Merge #933
933: macrotranscriber: Add location info r=CohenArthur a=CohenArthur

Closes #929 

Adds location info to the macro's transcriber. When generating a `MacroRule` error, this PR creates an empty location for the transcriber, since the error function is only called if no fat arrow is present or if there was an error parsing the macro's matcher. Please let me know if this is the expected behavior

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-17 08:44:36 +00:00
Arthur Cohen 45ca46018f macrotranscriber: Add location info 2022-02-17 09:43:48 +01:00
bors[bot] a5272f389b
Merge #934 #937
934: macromatch: Add location to abstract MacroMatch class r=philberty a=CohenArthur

Closes #928 

This adds location to the all child classes of the `MacroMatch` abstract class. The current locations are as follow, which I believe is what is expected but might be wrong.

```rust
test.rs:2:6: error: macro match fragment
    2 |     ($a:expr, $b:expr) => { $a + $b };
      |      ^
test.rs:2:15: error: macro match fragment
    2 |     ($a:expr, $b:expr) => { $a + $b };
      |               ^
test.rs:2:5: error: macro matcher
    2 |     ($a:expr, $b:expr) => { $a + $b };
      |     ^
test.rs:3:8: error: macro match fragment
    3 |     ($($i:ident)*) => { $($i)* }
      |        ^
test.rs:3:17: error: macro match repetition!
    3 |     ($($i:ident)*) => { $($i)* }
      |                 ^
test.rs:3:5: error: macro matcher
    3 |     ($($i:ident)*) => { $($i)* }
      |     ^
```

I think this should be rebased on #932 so that I can remove the FIXME 

937: dockerfile: Install cargo-gccrs alongside gccrs r=philberty a=CohenArthur

Closes #826 

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-16 18:38:44 +00:00
bors[bot] 733db624cf
Merge #931
931: rust-cfg: Quote option name when erroring out r=philberty a=CohenArthur

Removes a warning generated by `-Wformat-diag`

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-16 18:13:03 +00:00
Arthur Cohen 85d78c1b8d dockerfile: Install cargo-gccrs alongside gccrs 2022-02-16 18:47:36 +01:00
Arthur Cohen 3ac17160c8 macromatch: Add location to abstract MacroMatch class 2022-02-16 14:46:59 +01:00
Arthur Cohen 8848a76f83 rust-cfg: Quote option name when erroring out 2022-02-16 12:10:07 +01:00
bors[bot] 330b265134
Merge #926
926: macros: Add multiple macro syntax tests r=CohenArthur a=CohenArthur

This PR adds test cases for macros, including parsing and execution.

I am unsure on how to check for proper execution: The solution I have chosen so far is to make sure that a correct amount of lines is printed, which I'm not entirely satisfied with. 

Another solution would be to increase a global integer to use when exiting, which we can then assert on using dejagnu, which is cleaner but relies on unsafe rust code.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2022-02-16 09:48:58 +00:00
Arthur Cohen 08dbb4e322 macros: Add base for execution tests for macros 2022-02-16 02:14:03 +01:00
Arthur Cohen 29e07e06be macros: Add multiple macro syntax tests 2022-02-16 02:11:12 +01:00
bors[bot] c7275a7fb8
Merge #922
922: Support inline never and always options r=philberty a=philberty

This maps over to DECL_UNINLINEABLE and to use the GCC attribute
always_inline.

Fixes #921

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-13 15:01:35 +00:00
Philip Herron 112f2841ee Support inline never and always options
This maps over to DECL_UNINLINEABLE and to use the GCC attribute
always_inline.

Fixes #921
2022-02-13 14:27:01 +00:00
bors[bot] b71cc52613
Merge #920
920: Support deref_mut lang item during method resolution r=philberty a=philberty

This adds in the lookups for the DEREF_MUT lang item for operator overloading
this needs more testing to ensure the behaviour is correct and is the same as
rustc.

Fixes #890


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-12 16:35:24 +00:00
Philip Herron c0e5ca327b Support deref_mut lang item during method resolution
When we have method resolution we need to look at any deref lang items for
the receiver. The precise rules need to be tested rigorously to ensure this is right.

Fixes #890
2022-02-11 15:34:17 +00:00
bors[bot] 9023bb8687
Merge #918
918: Refactor code to reuse a canonical way to compile items r=philberty a=philberty

This is a big cleanup so all paths that compile functions and constants
end up in the same path so we avoid any duplication in how we actually
compile a function or constant.


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-11 10:29:35 +00:00
Philip Herron 4242d45d3d refactor named_constant_expression out of the backend class 2022-02-11 10:27:55 +00:00
Philip Herron 5801e165b3 Fix warnings when including rust-target.h information 2022-02-11 10:18:24 +00:00
Philip Herron d21ae24049 Cleanup header usage and remove void_type wrapper 2022-02-11 10:11:25 +00:00
Philip Herron df2dbbc034 Remove error_mark_node wrappers from backend proxy class. 2022-02-11 10:02:46 +00:00
Philip Herron b2aa172ff6 Refactor code to reuse a canonical way to compile functions and constants
This is a big cleanup so all paths that compile functions and constants
end up in the same path so we avoid any duplication in how we actually
compile a function.
2022-02-10 19:28:10 +00:00
bors[bot] e2823b6747
Merge #917
917: remove tree addressable context during type checking r=philberty a=philberty

We can reuse more C front-end code c_mark_addressable can be used instead
of trying to track TREE_ADDRESSABLE as part of type-checking. This also
pulls the GCC::Backend::address_expression to be part of the HIRCompileBase
class during code-generation.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-10 17:08:15 +00:00
Philip Herron 1b487d72cd Remove tree addressable flags from back-end local and fnparm decl creation 2022-02-10 16:07:28 +00:00
Philip Herron e49dd22fc2 Remove unsued functions in the GCC wrapper 2022-02-10 15:52:37 +00:00
Philip Herron 859732e4d1 Remove AddressTakenContext
We can reuse more C front-end code c_mark_addressable can be used instead
of trying to track TREE_ADDRESSABLE as part of type-checking. This also
pulls the GCC::Backend::address_expression to be part of the HIRCompileBase
class during code-generation.
2022-02-10 15:40:55 +00:00
bors[bot] f6ba472caf
Merge #916
916: Support inline attribute by marking as DECL_DECLARED_INLINE_P r=philberty a=philberty

This does a refactor by removing more flags for the fndecl construction
from the rust-gcc wrapper code in favour of using the tree api directly.
The ABI option attributes have also been refactored from the backend
interface in favour of their own package.

The gccgo wrapper tried to mark inline fns as extern inline but this
refactor allows us to control the inline options specificly for the
rust semantics.

Fixes #857


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-10 12:50:30 +00:00
Philip Herron c598bbbcc1 Support inline attribute by marking as DECL_DECLARED_INLINE_P
This does a refactor by removing more flags for the fndecl construction
from the rust-gcc wrapper code in favour of using the tree api directly.
The ABI option attributes have also been refactored from the backend
interface in favour of their own package.

The gccgo wrapper tried to mark inline fns as extern inline but this
refactor allows us to control the inline options specificly for the
rust semantics.

Fixes #857
2022-02-09 18:00:00 +00:00
bors[bot] 6d1ff56808
Merge #912
912: Handle generic substitution on path expressions r=philberty a=philberty

In this bug the path expression failed to take Foo::<i32> and apply this
bound generic argument into the impl block. The fn type for this function
test is:

fn <T,Y>test(a:T, b:Y);

But the impl block has a Self of Foo<T> so we need to inherit the T
argument from the previous Foo::<i32> which was missing.

Fixes #893


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-08 17:56:41 +00:00
bors[bot] 055ca34daa
Merge #911
911: Refactor to_string from header to impl file r=philberty a=philberty

This is part of the overal cleanup to move implementation into cc files from the headers.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
2022-02-08 17:30:04 +00:00
Philip Herron 257bf55827 Handle generic substitution on path expressions
In this bug the path expression failed to take Foo::<i32> and apply this
bound generic argument into the impl block. The fn type for this function
test is:

fn <T,Y>test(a:T, b:Y);

But the impl block has a Self of Foo<T> so we need to inherit the T
argument from the previous Foo::<i32> which was missing.

Fixes #893
2022-02-08 15:19:29 +00:00
Philip Herron b7cdd81dbc Refactor to_string from header to impl file 2022-02-07 17:47:48 +00:00