feat(ast, ir. sema): Add storage class
This commit is contained in:
+14
-28
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
ast::err::ParseError,
|
||||
ast::types::{
|
||||
ArrayDimension, CompileUnit, Expr, FuncDeclStmt, GlobalDeclStmt, Param, VarDeclStmt,
|
||||
VarDeclStmtValue,
|
||||
ArrayDimension, CompileUnit, Expr, FuncDeclStmt, GlobalDeclStmt, Param, StorageClass,
|
||||
VarDeclStmt, VarDeclStmtValue,
|
||||
},
|
||||
diagnostic::span::Span,
|
||||
lexer::types::{TokenValue, TypeIdent},
|
||||
@@ -10,13 +10,8 @@ use crate::{
|
||||
|
||||
use super::{ParseProcessError, ParseType, Parser};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum StorageClass {
|
||||
Static,
|
||||
}
|
||||
|
||||
struct DeclSpecifiers {
|
||||
_storage_class: Option<StorageClass>,
|
||||
storage_class: Option<StorageClass>,
|
||||
type_specifier: TypeIdent,
|
||||
type_span: Span,
|
||||
}
|
||||
@@ -111,7 +106,7 @@ impl Parser {
|
||||
};
|
||||
|
||||
Ok(DeclSpecifiers {
|
||||
_storage_class: storage_class,
|
||||
storage_class,
|
||||
type_specifier,
|
||||
type_span: type_token.span,
|
||||
})
|
||||
@@ -183,13 +178,13 @@ impl Parser {
|
||||
self.advance(1);
|
||||
span
|
||||
}
|
||||
TokenValue::Eof => {
|
||||
self.diagnostics.add_from_frontend_error(
|
||||
ParseError::ExpectedBefore(TokenValue::Eof, "`]`"),
|
||||
start_span,
|
||||
);
|
||||
return Err(ParseProcessError::ErrorInMatch);
|
||||
}
|
||||
// TokenValue::Eof => {
|
||||
// self.diagnostics.add_from_frontend_error(
|
||||
// ParseError::ExpectedBefore(TokenValue::Eof, "`]`"),
|
||||
// start_span,
|
||||
// );
|
||||
// return Err(ParseProcessError::ErrorInMatch);
|
||||
// }
|
||||
_ => {
|
||||
let token = self.next();
|
||||
self.diagnostics.add_from_frontend_error(
|
||||
@@ -279,6 +274,7 @@ impl Parser {
|
||||
let body = self.parse_block_stmt(ParseType::MustParse)?;
|
||||
Ok(FuncDeclStmt {
|
||||
return_type: specifiers.type_specifier.into(),
|
||||
storage_class: specifiers.storage_class,
|
||||
name,
|
||||
params,
|
||||
body,
|
||||
@@ -292,21 +288,10 @@ impl Parser {
|
||||
specifiers: DeclSpecifiers,
|
||||
first_declarator: Declarator,
|
||||
consume_semicolon: bool,
|
||||
allow_empty_declarator_list: bool,
|
||||
_allow_empty_declarator_list: bool,
|
||||
) -> Result<VarDeclStmt, ParseProcessError> {
|
||||
let mut values = vec![];
|
||||
|
||||
if self.peek().value == TokenValue::Semicolon && allow_empty_declarator_list {
|
||||
if consume_semicolon {
|
||||
self.advance(1);
|
||||
}
|
||||
return Ok(VarDeclStmt {
|
||||
values,
|
||||
type_span: specifiers.type_span,
|
||||
data_type: specifiers.type_specifier.into(),
|
||||
});
|
||||
}
|
||||
|
||||
let initializer = self.parse_initializer()?;
|
||||
values.push(self.init_declarator_to_var_value(InitDeclarator {
|
||||
declarator: first_declarator,
|
||||
@@ -328,6 +313,7 @@ impl Parser {
|
||||
}
|
||||
|
||||
Ok(VarDeclStmt {
|
||||
storage_class: specifiers.storage_class,
|
||||
values,
|
||||
type_span: specifiers.type_span,
|
||||
data_type: specifiers.type_specifier.into(),
|
||||
|
||||
Reference in New Issue
Block a user