mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-17 01:55:07 +01:00
can parse global variable declarations
This commit is contained in:
parent
f53c054a9a
commit
4b646b9128
5 changed files with 189 additions and 74 deletions
|
|
@ -371,10 +371,20 @@ where
|
||||||
span.extend(span2),
|
span.extend(span2),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
expect!(self, Tok::Punct(Punct::Semicolon));
|
||||||
Ok((ExternalDecl::Decl(declaration), span))
|
Ok((ExternalDecl::Decl(declaration), span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn external_declarations(&mut self) -> Result<Vec<Spanned<ExternalDecl>>> {
|
||||||
|
let mut decls = Vec::new();
|
||||||
|
while self.peek_t().is_ok() {
|
||||||
|
let decl = self.external_declaration()?;
|
||||||
|
decls.push(decl);
|
||||||
|
}
|
||||||
|
Ok(decls)
|
||||||
|
}
|
||||||
|
|
||||||
fn function_param_declaration_list(&mut self) -> Result<FunctionParams> {
|
fn function_param_declaration_list(&mut self) -> Result<FunctionParams> {
|
||||||
// If the declarator includes a parameter type list, the declaration of each parameter shall
|
// If the declarator includes a parameter type list, the declaration of each parameter shall
|
||||||
// include an identifier, except for the special case of a parameter list consisting of a single
|
// include an identifier, except for the special case of a parameter list consisting of a single
|
||||||
|
|
|
||||||
|
|
@ -3,42 +3,44 @@ source: parser/src/parser/tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
---
|
---
|
||||||
Ok(
|
Ok(
|
||||||
(
|
[
|
||||||
FunctionDef(
|
(
|
||||||
FunctionDef {
|
FunctionDef(
|
||||||
declaration: Normal(
|
FunctionDef {
|
||||||
NormalDecl {
|
declaration: Normal(
|
||||||
decl_spec: DeclSpec {
|
NormalDecl {
|
||||||
ty: Int,
|
decl_spec: DeclSpec {
|
||||||
attrs: DeclAttr {
|
ty: Int,
|
||||||
is_extern: true,
|
attrs: DeclAttr {
|
||||||
is_static: false,
|
is_extern: true,
|
||||||
is_thread_local: true,
|
is_static: false,
|
||||||
},
|
is_thread_local: true,
|
||||||
},
|
|
||||||
init_declarators: [
|
|
||||||
(
|
|
||||||
InitDecl {
|
|
||||||
declarator: Declarator {
|
|
||||||
decl: WithParams {
|
|
||||||
ident: (
|
|
||||||
"uwu",
|
|
||||||
35..38,
|
|
||||||
),
|
|
||||||
params: [],
|
|
||||||
},
|
|
||||||
pointer: false,
|
|
||||||
},
|
|
||||||
init: None,
|
|
||||||
},
|
},
|
||||||
35..38,
|
},
|
||||||
),
|
init_declarators: [
|
||||||
],
|
(
|
||||||
},
|
InitDecl {
|
||||||
),
|
declarator: Declarator {
|
||||||
body: [],
|
decl: WithParams {
|
||||||
},
|
ident: (
|
||||||
|
"uwu",
|
||||||
|
35..38,
|
||||||
|
),
|
||||||
|
params: [],
|
||||||
|
},
|
||||||
|
pointer: false,
|
||||||
|
},
|
||||||
|
init: None,
|
||||||
|
},
|
||||||
|
35..38,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
body: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
1..43,
|
||||||
),
|
),
|
||||||
1..43,
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,42 +3,44 @@ source: parser/src/parser/tests.rs
|
||||||
expression: parsed
|
expression: parsed
|
||||||
---
|
---
|
||||||
Ok(
|
Ok(
|
||||||
(
|
[
|
||||||
FunctionDef(
|
(
|
||||||
FunctionDef {
|
FunctionDef(
|
||||||
declaration: Normal(
|
FunctionDef {
|
||||||
NormalDecl {
|
declaration: Normal(
|
||||||
decl_spec: DeclSpec {
|
NormalDecl {
|
||||||
ty: Void,
|
decl_spec: DeclSpec {
|
||||||
attrs: DeclAttr {
|
ty: Void,
|
||||||
is_extern: false,
|
attrs: DeclAttr {
|
||||||
is_static: false,
|
is_extern: false,
|
||||||
is_thread_local: false,
|
is_static: false,
|
||||||
},
|
is_thread_local: false,
|
||||||
},
|
|
||||||
init_declarators: [
|
|
||||||
(
|
|
||||||
InitDecl {
|
|
||||||
declarator: Declarator {
|
|
||||||
decl: WithParams {
|
|
||||||
ident: (
|
|
||||||
"uwu",
|
|
||||||
6..9,
|
|
||||||
),
|
|
||||||
params: [],
|
|
||||||
},
|
|
||||||
pointer: false,
|
|
||||||
},
|
|
||||||
init: None,
|
|
||||||
},
|
},
|
||||||
6..9,
|
},
|
||||||
),
|
init_declarators: [
|
||||||
],
|
(
|
||||||
},
|
InitDecl {
|
||||||
),
|
declarator: Declarator {
|
||||||
body: [],
|
decl: WithParams {
|
||||||
},
|
ident: (
|
||||||
|
"uwu",
|
||||||
|
6..9,
|
||||||
|
),
|
||||||
|
params: [],
|
||||||
|
},
|
||||||
|
pointer: false,
|
||||||
|
},
|
||||||
|
init: None,
|
||||||
|
},
|
||||||
|
6..9,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
body: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
1..14,
|
||||||
),
|
),
|
||||||
1..14,
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
---
|
||||||
|
source: parser/src/parser/tests.rs
|
||||||
|
expression: parsed
|
||||||
|
---
|
||||||
|
Ok(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
Decl(
|
||||||
|
Normal(
|
||||||
|
NormalDecl {
|
||||||
|
decl_spec: DeclSpec {
|
||||||
|
ty: Int,
|
||||||
|
attrs: DeclAttr {
|
||||||
|
is_extern: false,
|
||||||
|
is_static: false,
|
||||||
|
is_thread_local: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
init_declarators: [
|
||||||
|
(
|
||||||
|
InitDecl {
|
||||||
|
declarator: Declarator {
|
||||||
|
decl: Ident(
|
||||||
|
(
|
||||||
|
"test",
|
||||||
|
5..9,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pointer: false,
|
||||||
|
},
|
||||||
|
init: None,
|
||||||
|
},
|
||||||
|
5..9,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
1..9,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Decl(
|
||||||
|
Normal(
|
||||||
|
NormalDecl {
|
||||||
|
decl_spec: DeclSpec {
|
||||||
|
ty: Double,
|
||||||
|
attrs: DeclAttr {
|
||||||
|
is_extern: false,
|
||||||
|
is_static: false,
|
||||||
|
is_thread_local: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
init_declarators: [
|
||||||
|
(
|
||||||
|
InitDecl {
|
||||||
|
declarator: Declarator {
|
||||||
|
decl: Ident(
|
||||||
|
(
|
||||||
|
"uwu",
|
||||||
|
32..35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pointer: false,
|
||||||
|
},
|
||||||
|
init: None,
|
||||||
|
},
|
||||||
|
32..35,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
InitDecl {
|
||||||
|
declarator: Declarator {
|
||||||
|
decl: Ident(
|
||||||
|
(
|
||||||
|
"owo",
|
||||||
|
37..40,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
pointer: false,
|
||||||
|
},
|
||||||
|
init: None,
|
||||||
|
},
|
||||||
|
37..40,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
11..40,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
@ -15,7 +15,7 @@ fn the_current_root_parse_thing<'src>(src: impl Iterator<Item = (Tok<'src>, Span
|
||||||
lex: src.peekmore(),
|
lex: src.peekmore(),
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.external_declaration()
|
parser.external_declarations()
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_test {
|
macro_rules! parse_test {
|
||||||
|
|
@ -53,3 +53,13 @@ int uwu(long owo, unsigned qwq) {}
|
||||||
|
|
||||||
parse_test!(src);
|
parse_test!(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn global_variable_declarations() {
|
||||||
|
let src = r#"
|
||||||
|
int test;
|
||||||
|
_Thread_local double uwu, owo;
|
||||||
|
"#;
|
||||||
|
|
||||||
|
parse_test!(src);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue