public void LCCTCDeclareERR1() { string source = @" { int (*foo)(char); int (*bar)(double, int, ...); struct s s; } "; List <T> types = new List <T> { TInt.Instance.None(), }; var env = new Env(); var result = Utility.Parse(source, lcc.Parser.Parser.CompoundStatement().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); lcc.AST.CompoundStmt conmpund = stmt as lcc.AST.CompoundStmt; Assert.IsNotNull(conmpund); IEnumerable <lcc.AST.Expr> exprs = conmpund.stmts.OfType <lcc.AST.Expr>(); Assert.AreEqual(types.Count(), exprs.Count()); var tests = exprs.Zip(types, (s, t) => new Tuple <lcc.AST.Expr, T>(s as lcc.AST.Expr, t)); foreach (var test in tests) { Assert.AreEqual(test.Item2, test.Item1.Type); } }
public void LCCTCPreStep() { string source = @" { int a; --a; float b; ++b; int* c; ++c; } "; List <T> types = new List <T> { TInt.Instance.None(), TSingle.Instance.None(), TInt.Instance.None().Ptr() }; var env = new Env(); var result = Utility.Parse(source, lcc.Parser.Parser.CompoundStatement().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); lcc.AST.CompoundStmt conmpund = stmt as lcc.AST.CompoundStmt; Assert.IsNotNull(conmpund); IEnumerable <lcc.AST.Expr> exprs = conmpund.stmts.OfType <lcc.AST.Expr>(); Assert.AreEqual(types.Count(), exprs.Count()); var tests = exprs.Zip(types, (s, t) => new Tuple <lcc.AST.Expr, T>(s as lcc.AST.Expr, t)); foreach (var test in tests) { Assert.AreEqual(test.Item2, test.Item1.Type); } }
public void LCCTCArrSub() { string source = @" { int a[10], b; int x[3][5]; a; b; a[3]; x[3][2]; x[b]; b++; b--; } "; var env = new Env(); var result = Utility.Parse(source, lcc.Parser.Parser.CompoundStatement().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); lcc.AST.CompoundStmt s = stmt as lcc.AST.CompoundStmt; Assert.IsNotNull(s); //Assert.AreEqual(4, stmt.stmts.Count()); }
public void LCCTCSizeof() { string source = @" { int a[32]; sizeof a; sizeof(int); sizeof(double); sizeof(struct { char c; int a; }); sizeof(a[0]); } "; List <T> types = new List <T> { TUInt.Instance.None(), TUInt.Instance.None(), TUInt.Instance.None(), TUInt.Instance.None(), TUInt.Instance.None() }; List <int> values = new List <int> { 128, 4, 8, 8, 4 }; var env = new Env(); var result = Utility.Parse(source, lcc.Parser.Parser.CompoundStatement().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); lcc.AST.CompoundStmt conmpund = stmt as lcc.AST.CompoundStmt; Assert.IsNotNull(conmpund); IEnumerable <lcc.AST.Expr> exprs = conmpund.stmts.OfType <lcc.AST.Expr>(); Assert.AreEqual(types.Count(), exprs.Count()); { var tests = exprs.Zip(types, (s, t) => new Tuple <lcc.AST.Expr, T>(s as lcc.AST.Expr, t)); foreach (var test in tests) { Assert.AreEqual(test.Item2, test.Item1.Type); } } { var tests = exprs.Zip(values, (s, t) => new Tuple <lcc.AST.ConstIntExpr, int>(s as lcc.AST.ConstIntExpr, t)); foreach (var test in tests) { Assert.AreEqual(test.Item2, test.Item1.value); } } }
public bool ExpectException <E>(string src) where E : Error { try { var env = new Env(); var result = Utility.Parse(src, lcc.Parser.Parser.TranslationUnit().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); } catch (E) { /// Get the expect exception. return(true); } catch (Exception e) { /// This is not what we expected. throw e; } return(false); }
public void LCCTCBiExpr() { string source = @" { char c; unsigned char uc; signed char sc; short s; unsigned short us; int i; unsigned int ui; long l; unsigned long ul; long long ll; unsigned long long ull; float f; double d; long double ld; int* ip1; int* ip2; c * uc; s * f; ll * i; d / f; i % ui; f + ll; ip1 + l; i + ip2; ld - f; ip1 - ip2; } "; List <T> types = new List <T> { TInt.Instance.None(), TSingle.Instance.None(), TLLong.Instance.None(), TDouble.Instance.None(), TUInt.Instance.None(), TSingle.Instance.None(), TInt.Instance.None().Ptr(), TInt.Instance.None().Ptr(), TLDouble.Instance.None(), TInt.Instance.None(), }; var env = new Env(); var result = Utility.Parse(source, lcc.Parser.Parser.CompoundStatement().End()); Assert.AreEqual(1, result.Count()); Assert.IsFalse(result.First().Remain.More()); lcc.AST.Node stmt = result.First().Value.ToAST(env); lcc.AST.CompoundStmt conmpund = stmt as lcc.AST.CompoundStmt; Assert.IsNotNull(conmpund); IEnumerable <lcc.AST.Expr> exprs = conmpund.stmts.OfType <lcc.AST.Expr>(); Assert.AreEqual(types.Count(), exprs.Count()); var tests = exprs.Zip(types, (s, t) => new Tuple <lcc.AST.Expr, T>(s as lcc.AST.Expr, t)); foreach (var test in tests) { Assert.AreEqual(test.Item2, test.Item1.Type); } }