Skip to content

Commit 3088f89

Browse files
authored
Merge pull request #231 from nature-lang/feature/generics_refactor
reacotr: generic constraint refactoring and method generic support
2 parents fdda9b6 + 8ae0c90 commit 3088f89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2904
-2683
lines changed

nls/src/analyzer.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod common;
22
pub mod completion;
33
pub mod flow;
4+
pub mod generics;
45
pub mod lexer; // 声明子模块
56
pub mod semantic;
67
pub mod symbol;
@@ -522,35 +523,28 @@ pub fn register_global_symbol(m: &mut Module, symbol_table: &mut SymbolTable, st
522523
if fndef.impl_type.kind.is_unknown() {
523524
fndef.symbol_name = format_global_ident(m.ident.clone(), symbol_name.clone());
524525

525-
if fndef.generics_params.is_none() {
526-
match symbol_table.define_symbol_in_scope(
527-
fndef.symbol_name.clone(),
528-
SymbolKind::Fn(fndef_mutex.clone()),
529-
fndef.symbol_start,
530-
m.scope_id,
531-
) {
532-
Ok(symbol_id) => {
533-
fndef.symbol_id = symbol_id;
534-
}
535-
Err(_e) => {
536-
errors_push(
537-
m,
538-
AnalyzerError {
539-
start: fndef.symbol_start,
540-
end: fndef.symbol_end,
541-
message: format!("ident '{}' redeclared", fndef.symbol_name),
542-
},
543-
);
544-
}
526+
match symbol_table.define_symbol_in_scope(
527+
fndef.symbol_name.clone(),
528+
SymbolKind::Fn(fndef_mutex.clone()),
529+
fndef.symbol_start,
530+
m.scope_id,
531+
) {
532+
Ok(symbol_id) => {
533+
fndef.symbol_id = symbol_id;
534+
}
535+
Err(_e) => {
536+
errors_push(
537+
m,
538+
AnalyzerError {
539+
start: fndef.symbol_start,
540+
end: fndef.symbol_end,
541+
message: format!("ident '{}' redeclared", fndef.symbol_name),
542+
},
543+
);
545544
}
546-
547-
let _ = symbol_table.define_global_symbol(
548-
fndef.symbol_name.clone(),
549-
SymbolKind::Fn(fndef_mutex.clone()),
550-
fndef.symbol_start,
551-
m.scope_id,
552-
);
553545
}
546+
547+
let _ = symbol_table.define_global_symbol(fndef.symbol_name.clone(), SymbolKind::Fn(fndef_mutex.clone()), fndef.symbol_start, m.scope_id);
554548
} else {
555549
// dealy semantic analyze
556550
}

nls/src/analyzer/common.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,13 @@ impl Type {
416416
| TypeKind::Struct(..)
417417
| TypeKind::Arr(..)
418418
| TypeKind::Enum(..)
419-
| TypeKind::Union(..)
420419
| TypeKind::Tuple(..)
420+
| TypeKind::Vec(..)
421+
| TypeKind::String
422+
| TypeKind::Set(..)
423+
| TypeKind::Map(..)
424+
| TypeKind::Tuple(..)
425+
| TypeKind::Union(..)
421426
| TypeKind::TaggedUnion(..)
422427
)
423428
}
@@ -840,11 +845,6 @@ pub enum ExprOp {
840845
Bnot,
841846
#[strum(to_string = "&")]
842847
La,
843-
#[strum(to_string = "&?")]
844-
SafeLa,
845-
#[strum(to_string = "&!")]
846-
UnsafeLa,
847-
848848
#[strum(to_string = "*")]
849849
Ia,
850850

@@ -918,7 +918,6 @@ pub enum AstNode {
918918

919919
// marco
920920
MacroSizeof(Type), // (target_type)
921-
MacroUla(Box<Expr>), // (src)
922921
MacroReflectHash(Type), // (target_type)
923922
MacroTypeEq(Type, Type), // (left_type, right_type)
924923
MacroAsync(MacroAsyncExpr),
@@ -1155,14 +1154,14 @@ impl Default for ImportStmt {
11551154
#[derive(Debug, Clone)]
11561155
pub struct GenericsParam {
11571156
pub ident: String,
1158-
pub constraints: (Vec<Type>, bool, bool, bool), // (elements, any, and, or)
1157+
pub constraints: Vec<Type>, // interface constraints, default AND
11591158
}
11601159

11611160
impl GenericsParam {
11621161
pub fn new(ident: String) -> Self {
11631162
Self {
11641163
ident,
1165-
constraints: (Vec::new(), true, false, false),
1164+
constraints: Vec::new(),
11661165
}
11671166
}
11681167
}
@@ -1253,6 +1252,7 @@ pub struct AstFnDef {
12531252
pub test_name: String,
12541253
pub ret_target_types: Vec<Type>,
12551254
pub linkid: Option<String>,
1255+
pub pending_where_params: Option<Vec<GenericsParam>>,
12561256
pub fn_name: String, // default empty
12571257
pub rel_path: Option<String>,
12581258

@@ -1296,6 +1296,7 @@ impl Default for AstFnDef {
12961296
is_local: false,
12971297
is_tpl: false,
12981298
linkid: None,
1299+
pending_where_params: None,
12991300
is_generics: false,
13001301
is_async: false,
13011302
is_private: false,

0 commit comments

Comments
 (0)