1- using fac . ASTs . Types ;
1+ using fac . ASTs . Stmts ;
2+ using fac . ASTs . Types ;
23using fac . Exceptions ;
34using System ;
45using System . Collections . Generic ;
@@ -15,17 +16,27 @@ public class AstExprName_BuildIn: IAstExprName {
1516
1617
1718 private static Dictionary < string , AstExprName_BuildIn > sBuildIn = new Dictionary < string , AstExprName_BuildIn > {
18- [ "continue" ] = new AstExprName_BuildIn { Token = null , Name = "continue" , NameType = "void" } ,
19- [ "break" ] = new AstExprName_BuildIn { Token = null , Name = "break" , NameType = "void" } ,
20- [ "Console.WriteLine" ] = new AstExprName_BuildIn { Token = null , Name = "Console.WriteLine" , NameType = "Func<string, void>" } ,
21- [ "Console.Write" ] = new AstExprName_BuildIn { Token = null , Name = "Console.Write" , NameType = "Func<string, void>" } ,
22- [ "string.Format" ] = new AstExprName_BuildIn { Token = null , Name = "string.Format" , NameType = "Func<string, params any[], string>" } ,
23- [ "File.Exists" ] = new AstExprName_BuildIn { Token = null , Name = "File.Exists" , NameType = "Func<string, bool>" } ,
24- [ "File.ReadAllText" ] = new AstExprName_BuildIn { Token = null , Name = "File.ReadAllText" , NameType = "Func<string, string>" } ,
25- [ "File.WriteAllText" ] = new AstExprName_BuildIn { Token = null , Name = "File.WriteAllText" , NameType = "Func<string, string, void>" } ,
26- [ "File.AppendAllText" ] = new AstExprName_BuildIn { Token = null , Name = "File.AppendAllText" , NameType = "Func<string, string, void>" } ,
27- [ "@FILE" ] = new AstExprName_BuildIn { Token = null , Name = "@FILE" , NameType = "string" } ,
28- [ "@SOURCE" ] = new AstExprName_BuildIn { Token = null , Name = "@SOURCE" , NameType = "string" } ,
19+ [ "continue" ] = new AstExprName_BuildIn { Name = "continue" , NameType = "void" } ,
20+ [ "break" ] = new AstExprName_BuildIn { Name = "break" , NameType = "void" } ,
21+ //
22+ [ "Console.WriteLine" ] = new AstExprName_BuildIn { Name = "Console.WriteLine" , NameType = "Func<string, void>" } ,
23+ [ "Console.Write" ] = new AstExprName_BuildIn { Name = "Console.Write" , NameType = "Func<string, void>" } ,
24+ //
25+ [ "string.Format" ] = new AstExprName_BuildIn { Name = "string.Format" , NameType = "Func<string, params any[], string>" } ,
26+ //
27+ [ "File.Exists" ] = new AstExprName_BuildIn { Name = "File.Exists" , NameType = "Func<string, bool>" } ,
28+ [ "File.ReadAllText" ] = new AstExprName_BuildIn { Name = "File.ReadAllText" , NameType = "Func<string, string>" } ,
29+ [ "File.WriteAllText" ] = new AstExprName_BuildIn { Name = "File.WriteAllText" , NameType = "Func<string, string, void>" } ,
30+ [ "File.AppendAllText" ] = new AstExprName_BuildIn { Name = "File.AppendAllText" , NameType = "Func<string, string, void>" } ,
31+ [ "File.Delete" ] = new AstExprName_BuildIn { Name = "File.Delete" , NameType = "Func<string, void>" } ,
32+ //
33+ [ "Directory.Exists" ] = new AstExprName_BuildIn { Name = "Directory.Exists" , NameType = "Func<string, bool>" } ,
34+ [ "Directory.Create" ] = new AstExprName_BuildIn { Name = "Directory.Create" , NameType = "Func<string, void>" } ,
35+ [ "Directory.Delete" ] = new AstExprName_BuildIn { Name = "Directory.Delete" , NameType = "Func<string, void>" } ,
36+ [ "Directory.GetFiles" ] = new AstExprName_BuildIn { Name = "Directory.GetFiles" , NameType = "Func<string, string[]>" } ,
37+ //
38+ [ "@FILE" ] = new AstExprName_BuildIn { Name = "@FILE" , NameType = "string" } ,
39+ [ "@FILEDATA" ] = new AstExprName_BuildIn { Name = "@FILEDATA" , NameType = "string" } ,
2940 } ;
3041
3142 public static AstExprName_BuildIn FindFromName ( string _name ) {
@@ -36,29 +47,26 @@ public static AstExprName_BuildIn FindFromName (string _name) {
3647
3748 public override IAstExpr TraversalCalcType ( IAstType _expect_type ) {
3849 if ( ExpectType == null )
39- ExpectType = NameType != "" ? IAstType . FromName ( NameType ) : null ;
50+ ExpectType = IAstType . FromName ( NameType ) ;
4051 return AstExprTypeCast . Make ( this , _expect_type ) ;
4152 }
4253
4354 public override IAstType GuessType ( ) {
4455 if ( ExpectType == null )
45- ExpectType = NameType != "" ? IAstType . FromName ( NameType ) : null ;
56+ ExpectType = IAstType . FromName ( NameType ) ;
4657 return ExpectType ;
4758 }
4859
60+ public override ( List < IAstStmt > , IAstExpr ) ExpandExpr ( ( IAstExprName _var , AstStmt_Label _pos ) ? _cache_err ) {
61+ // TODO 扩展写文件之类的错误判断
62+ return ( new List < IAstStmt > ( ) , this ) ;
63+ }
64+
4965 public override string GenerateCSharp ( int _indent ) => Name switch {
50- "continue" => "continue" ,
51- "break" => "break" ,
52- "Console.WriteLine" => "Console.WriteLine" ,
53- "Console.Write" => "Console.Write" ,
54- "string.Format" => "string.Format" ,
55- "File.Exists" => "File.Exists" ,
56- "File.ReadAllText" => "File.ReadAllText" ,
57- "File.WriteAllText" => "File.WriteAllText" ,
58- "File.AppendAllText" => "File.AppendAllText" ,
66+ "Directory.Create" => "Directory.CreateDirectory" ,
5967 "@FILE" => Common . WrapStringValue ( Info . CurrentFile ) ,
60- "@SOURCE " => Common . WrapStringValue ( File . ReadAllText ( Info . CurrentFile , Encoding . UTF8 ) ) ,
61- _ => throw new UnimplException ( Token ) ,
68+ "@FILEDATA " => Common . WrapStringValue ( File . ReadAllText ( Info . CurrentFile , Encoding . UTF8 ) ) ,
69+ _ => Name ,
6270 } ;
6371
6472 public override bool AllowAssign ( ) => false ;
0 commit comments