├── Expressions
├── Flee
│ ├── .gitignore
│ └── FleeLexer.cs
├── .gitignore
├── VisualBasic
│ ├── .gitignore
│ └── VisualBasicLexer.cs
├── Key.snk
├── CastType.cs
├── Ast
│ ├── IAstNode.cs
│ ├── IdentifierAccess.cs
│ ├── IdentifierCollection.cs
│ ├── UnaryExpression.cs
│ ├── Constant.cs
│ ├── MemberAccess.cs
│ ├── BinaryExpression.cs
│ ├── MethodCall.cs
│ ├── Conditional.cs
│ ├── Cast.cs
│ ├── TypeIdentifier.cs
│ ├── Index.cs
│ └── AstNodeCollection.cs
├── IExpressionContext.cs
├── Expressions
│ ├── IExpression.cs
│ ├── TypeAccess.cs
│ ├── VariableAccess.cs
│ ├── ImportAccess.cs
│ ├── Constant.cs
│ ├── FieldAccess.cs
│ ├── Index.cs
│ ├── UnaryExpression.cs
│ ├── Cast.cs
│ ├── Conditional.cs
│ ├── MethodCall.cs
│ └── BinaryExpression.cs
├── Pack NuGet Package.bat
├── ExpressionLanguage.cs
├── ParseResult.cs
├── Csharp
│ ├── CsharpLexer.cs
│ └── Generated
│ │ ├── Flee.tokens
│ │ └── Csharp.tokens
├── Expressions.nuspec
├── ExpressionType.cs
├── IExecutionContext.cs
├── Variable.cs
├── CachedDynamicExpression.cs
├── Properties
│ └── AssemblyInfo.cs
├── IBindingContext.cs
├── VariableCollection.cs
├── IBoundExpression.cs
├── ExpressionsExceptionType.cs
├── ConstantParsingVisitor.cs
├── CompilerUtil.cs
├── ObjectUtil.cs
├── Require.cs
└── DynamicExpressionCache.cs
├── Expressions.Test
├── .gitignore
├── FleeLanguage
│ ├── BulkTests
│ │ ├── TestScripts
│ │ │ ├── OnDemandMethods.txt
│ │ │ ├── SpecialConstructs.txt
│ │ │ ├── TypeDescriptor.txt
│ │ │ ├── SimpleCalcEngineTests.txt
│ │ │ ├── LongBranchLogicalTest.txt
│ │ │ └── IndividualTests.xml
│ │ └── BulkTests.cs
│ ├── Compilation
│ │ ├── CompilationFailures.cs
│ │ ├── ResultCasting.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Fields.cs
│ │ ├── Indexing.cs
│ │ ├── TestBase.cs
│ │ ├── Caching.cs
│ │ ├── EmitIssues.cs
│ │ └── Imports.cs
│ ├── ExpressionTests
│ │ ├── Constants.cs
│ │ ├── VoidMethods.cs
│ │ ├── SpecialConstructs.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Conversions.cs
│ │ ├── TestBase.cs
│ │ └── Casting.cs
│ └── Parsing
│ │ └── Parsing.cs
├── CsharpLanguage
│ ├── BulkTests
│ │ ├── TestScripts
│ │ │ ├── OnDemandMethods.txt
│ │ │ ├── SpecialConstructs.txt
│ │ │ ├── TypeDescriptor.txt
│ │ │ ├── SimpleCalcEngineTests.txt
│ │ │ ├── LongBranchLogicalTest.txt
│ │ │ └── IndividualTests.xml
│ │ └── BulkTests.cs
│ ├── ExpressionTests
│ │ ├── Constants.cs
│ │ ├── VoidMethods.cs
│ │ ├── SpecialConstructs.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Conversions.cs
│ │ └── TestBase.cs
│ ├── Parsing
│ │ └── Parsing.cs
│ ├── Compilation
│ │ ├── ResultCasting.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Fields.cs
│ │ ├── Indexing.cs
│ │ ├── TestBase.cs
│ │ ├── Caching.cs
│ │ ├── EmitIssues.cs
│ │ ├── Imports.cs
│ │ └── BinaryExpressions.cs
│ └── Issues
│ │ └── Issue14Fixture.cs
├── VisualBasicLanguage
│ ├── BulkTests
│ │ ├── TestScripts
│ │ │ ├── OnDemandMethods.txt
│ │ │ ├── SpecialConstructs.txt
│ │ │ ├── TypeDescriptor.txt
│ │ │ ├── SimpleCalcEngineTests.txt
│ │ │ ├── LongBranchLogicalTest.txt
│ │ │ └── IndividualTests.xml
│ │ └── BulkTests.cs
│ ├── ExpressionTests
│ │ ├── Constants.cs
│ │ ├── VoidMethods.cs
│ │ ├── StringExpressions.cs
│ │ ├── SpecialConstructs.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Conversions.cs
│ │ └── TestBase.cs
│ ├── Parsing
│ │ └── Parsing.cs
│ └── Compilation
│ │ ├── ResultCasting.cs
│ │ ├── UnaryExpressions.cs
│ │ ├── Fields.cs
│ │ ├── Indexing.cs
│ │ ├── TestBase.cs
│ │ ├── Caching.cs
│ │ ├── EmitIssues.cs
│ │ ├── Imports.cs
│ │ └── BinaryExpressions.cs
└── Properties
│ └── AssemblyInfo.cs
├── Libraries
├── NuGet
│ └── NuGet.exe
├── NUnit
│ ├── License.txt
│ └── nunit.framework.dll
├── AntlrTools
│ ├── Antlr3.exe
│ ├── Antlr3.Runtime.dll
│ ├── AntlrBuildTask.dll
│ ├── Antlr3.Runtime.Debug.dll
│ ├── Antlr4.StringTemplate.dll
│ ├── Targets
│ │ ├── Antlr3.Targets.C.dll
│ │ ├── Antlr3.Targets.Cpp.dll
│ │ ├── Antlr3.Targets.Java.dll
│ │ ├── Antlr3.Targets.ObjC.dll
│ │ ├── Antlr3.Targets.Perl5.dll
│ │ ├── Antlr3.Targets.Ruby.dll
│ │ ├── Antlr3.Targets.CSharp2.dll
│ │ ├── Antlr3.Targets.CSharp3.dll
│ │ ├── Antlr3.Targets.Delphi.dll
│ │ ├── Antlr3.Targets.Python.dll
│ │ ├── Antlr3.Targets.JavaScript.dll
│ │ └── Antlr3.Targets.ActionScript.dll
│ ├── Antlr3.Runtime.JavaExtensions.dll
│ ├── Antlr4.StringTemplate.Visualizer.dll
│ ├── Antlr3.exe.config
│ ├── Tool
│ │ └── Templates
│ │ │ ├── depend.stg
│ │ │ ├── messages
│ │ │ └── formats
│ │ │ │ ├── gnu.stg
│ │ │ │ ├── antlr.stg
│ │ │ │ └── vs2005.stg
│ │ │ └── dot
│ │ │ └── dot.stg
│ ├── Codegen
│ │ └── Templates
│ │ │ ├── Ruby
│ │ │ ├── ASTDbg.stg
│ │ │ └── ST.stg
│ │ │ ├── C
│ │ │ └── ASTDbg.stg
│ │ │ ├── Python
│ │ │ └── ASTDbg.stg
│ │ │ ├── LeftRecursiveRules.stg
│ │ │ ├── Java
│ │ │ └── ASTDbg.stg
│ │ │ ├── CSharp2
│ │ │ └── ASTDbg.stg
│ │ │ ├── CSharp3
│ │ │ └── ASTDbg.stg
│ │ │ └── ObjC
│ │ │ └── ASTDbg.stg
│ └── LICENSE.txt
└── Antlr
│ └── Antlr3.Runtime.dll
├── .gitignore
├── Merge.bat
└── Expressions.sln
/Expressions/Flee/.gitignore:
--------------------------------------------------------------------------------
1 | /output
2 | /Generated
3 |
--------------------------------------------------------------------------------
/Expressions/.gitignore:
--------------------------------------------------------------------------------
1 | /*.suo
2 | /*.user
3 | /bin
4 | /obj
5 |
--------------------------------------------------------------------------------
/Expressions/VisualBasic/.gitignore:
--------------------------------------------------------------------------------
1 | /output
2 | /Generated
3 |
--------------------------------------------------------------------------------
/Expressions.Test/.gitignore:
--------------------------------------------------------------------------------
1 | /*.suo
2 | /*.user
3 | /bin
4 | /obj
5 |
--------------------------------------------------------------------------------
/Expressions/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Expressions/Key.snk
--------------------------------------------------------------------------------
/Libraries/NuGet/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/NuGet/NuGet.exe
--------------------------------------------------------------------------------
/Libraries/NUnit/License.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/NUnit/License.txt
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr3.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr3.exe
--------------------------------------------------------------------------------
/Libraries/Antlr/Antlr3.Runtime.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/Antlr/Antlr3.Runtime.dll
--------------------------------------------------------------------------------
/Libraries/NUnit/nunit.framework.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/NUnit/nunit.framework.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr3.Runtime.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr3.Runtime.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/AntlrBuildTask.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/AntlrBuildTask.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr3.Runtime.Debug.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr3.Runtime.Debug.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr4.StringTemplate.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr4.StringTemplate.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.C.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.C.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Cpp.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Cpp.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Java.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Java.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.ObjC.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.ObjC.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Perl5.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Perl5.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Ruby.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Ruby.dll
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /*.suo
2 | /*.user
3 | Thumbs.db
4 | /*Playground*
5 | /*.docstates
6 | /*.shfbproj_*
7 | /*.dotCover
8 | /Everything.sln
9 | /_ReSharper.*
10 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr3.Runtime.JavaExtensions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr3.Runtime.JavaExtensions.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.CSharp2.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.CSharp2.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.CSharp3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.CSharp3.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Delphi.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Delphi.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.Python.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.Python.dll
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/OnDemandMethods.txt:
--------------------------------------------------------------------------------
1 | ' Test proper emit of temp locals using on-demand function
2 | boolean;false OR (x() > 1);true
3 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr4.StringTemplate.Visualizer.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Antlr4.StringTemplate.Visualizer.dll
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.JavaScript.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.JavaScript.dll
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/OnDemandMethods.txt:
--------------------------------------------------------------------------------
1 | ' Test proper emit of temp locals using on-demand function
2 | boolean;false OR (x() > 1);true
3 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Targets/Antlr3.Targets.ActionScript.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvginkel/Expressions/HEAD/Libraries/AntlrTools/Targets/Antlr3.Targets.ActionScript.dll
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/OnDemandMethods.txt:
--------------------------------------------------------------------------------
1 | ' Test proper emit of temp locals using on-demand function
2 | boolean;false OR (x() > 1);true
3 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Antlr3.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Expressions/CastType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | internal enum CastType
8 | {
9 | Cast,
10 | Convert
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/SpecialConstructs.txt:
--------------------------------------------------------------------------------
1 | string;0.ToString();0
2 | string;1.ToString();1
3 | string;0.0.ToString();0
4 | string;0.1.ToString();0.1
5 | string;0x0.ToString();0
6 | string;0f.ToString();0
7 | string;0u.ToString();0
8 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/SpecialConstructs.txt:
--------------------------------------------------------------------------------
1 | string;0.ToString();0
2 | string;1.ToString();1
3 | string;0.0.ToString();0
4 | string;0.1.ToString();0.1
5 | string;0x0.ToString();0
6 | string;0f.ToString();0
7 | string;0u.ToString();0
8 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/SpecialConstructs.txt:
--------------------------------------------------------------------------------
1 | string;0.ToString();0
2 | string;1.ToString();1
3 | string;0.0.ToString();0
4 | string;0.1.ToString();0.1
5 | string;&h0.ToString();0
6 | string;0f.ToString();0
7 | string;0ui.ToString();0
8 |
--------------------------------------------------------------------------------
/Expressions/Ast/IAstNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal interface IAstNode
8 | {
9 | T Accept(IAstVisitor visitor);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/TypeDescriptor.txt:
--------------------------------------------------------------------------------
1 | ' Virtual properties
2 | string;stringA.name;prop!
3 | string;int32A.name;prop!
4 | string;100.name;prop!
5 | string;"abc".name;prop!
6 | int32;stringA.name.length;5
7 | string;int32A.tostring().name;prop!
8 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/TypeDescriptor.txt:
--------------------------------------------------------------------------------
1 | ' Virtual properties
2 | string;stringA.name;prop!
3 | string;int32A.name;prop!
4 | string;100.name;prop!
5 | string;"abc".name;prop!
6 | int32;stringA.name.length;5
7 | string;int32A.tostring().name;prop!
8 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/TypeDescriptor.txt:
--------------------------------------------------------------------------------
1 | ' Virtual properties
2 | string;stringA.name;prop!
3 | string;int32A.name;prop!
4 | string;100.name;prop!
5 | string;"abc".name;prop!
6 | int32;stringA.name.length;5
7 | string;int32A.tostring().name;prop!
8 |
--------------------------------------------------------------------------------
/Expressions/IExpressionContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Represents the context of an expression.
9 | ///
10 | public interface IExpressionContext : IBindingContext, IExecutionContext
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Expressions/Expressions/IExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal interface IExpression
8 | {
9 | Type Type { get; }
10 |
11 | void Accept(IExpressionVisitor visitor);
12 |
13 | T Accept(IExpressionVisitor visitor);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/BulkTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Test.VisualBasicLanguage.BulkTests
6 | {
7 | internal class BulkTests : Test.BulkTests
8 | {
9 | public BulkTests()
10 | : base(ExpressionLanguage.VisualBasic)
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Merge.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | set ILMERGE=%ProgramFiles(x86)%\Microsoft\ILMerge\ILMerge.exe
4 |
5 | if not exist "%ILMERGE%" set ILMERGE=%ProgramFiles%\Microsoft\ILMerge\ILMerge.exe
6 |
7 | if not exist "%ILMERGE%" (
8 | echo Cannot find ILMerge
9 | goto exit
10 | )
11 |
12 | "%ILMERGE%" /keyfile:Expressions\Key.snk /out:Expressions.dll Expressions\bin\Release\Expressions.dll Libraries\Antlr\Antlr3.Runtime.dll
13 |
14 | :exit
15 |
--------------------------------------------------------------------------------
/Expressions/Pack NuGet Package.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | rem We need to replace Expressions.dll in the release folder with the merged
4 | rem one.
5 |
6 | echo Merging
7 |
8 | cd ..
9 | call Merge.bat
10 | cd Expressions
11 |
12 | echo Copying files
13 |
14 | del bin\Release\Expressions.dll
15 | del bin\Release\Antlr3.Runtime.dll
16 | copy ..\Expressions.dll bin\Release
17 |
18 | echo Packing
19 |
20 | ..\Libraries\NuGet\nuget.exe pack -prop configuration=release
21 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Tool/Templates/depend.stg:
--------------------------------------------------------------------------------
1 | /** templates used to generate make-compatible dependencies */
2 | group depend;
3 |
4 | /** Generate "f : x, y, z" dependencies for input
5 | * dependencies and generated files. in and out
6 | * are File objects. For example, you can say
7 | *
8 | */
9 | dependencies(grammarFileName,in,out) ::= <<
10 | :
11 | : }; separator="\n">
12 | >>
13 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/CompilationFailures.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class CompilationFailures : TestBase
10 | {
11 | [Test]
12 | [ExpectedException]
13 | public void InfiniteLoop()
14 | {
15 | Resolve("true && false");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/BulkTests.cs:
--------------------------------------------------------------------------------
1 | // From http://flee.codeplex.com/
2 |
3 | using System.Text;
4 | using System.Collections.Generic;
5 | using System;
6 | using System.Globalization;
7 | using System.Threading;
8 | using NUnit.Framework;
9 |
10 | namespace Expressions.Test.CsharpLanguage.BulkTests
11 | {
12 | internal class BulkTests : Test.BulkTests
13 | {
14 | public BulkTests()
15 | : base(ExpressionLanguage.Csharp)
16 | {
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/ExpressionTests/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Constants : TestBase
11 | {
12 | [Test]
13 | public void Max()
14 | {
15 | Resolve(
16 | int.MinValue.ToString(),
17 | new Constant(int.MinValue)
18 | );
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/ExpressionTests/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Constants : TestBase
11 | {
12 | [Test]
13 | public void Max()
14 | {
15 | Resolve(
16 | int.MinValue.ToString(),
17 | new Constant(int.MinValue)
18 | );
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Constants : TestBase
11 | {
12 | [Test]
13 | public void Max()
14 | {
15 | Resolve(
16 | int.MinValue.ToString(),
17 | new Constant(int.MinValue)
18 | );
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Expressions/ExpressionLanguage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// The language of an expression.
9 | ///
10 | public enum ExpressionLanguage
11 | {
12 | ///
13 | /// Flee language.
14 | ///
15 | Flee,
16 | ///
17 | /// C# language.
18 | ///
19 | Csharp,
20 | ///
21 | /// VB.NET language.
22 | ///
23 | VisualBasic
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Expressions/ParseResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Ast;
5 |
6 | namespace Expressions
7 | {
8 | internal class ParseResult
9 | {
10 | public IAstNode RootNode { get; private set; }
11 |
12 | public IdentifierCollection Identifiers { get; private set; }
13 |
14 | public ParseResult(IAstNode rootNode, IdentifierCollection identifiers)
15 | {
16 | Require.NotNull(rootNode, "rootNode");
17 | Require.NotNull(identifiers, "identifiers");
18 |
19 | RootNode = rootNode;
20 | Identifiers = identifiers;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Expressions/Ast/IdentifierAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class IdentifierAccess : IAstNode
8 | {
9 | public string Name { get; private set; }
10 |
11 | public IdentifierAccess(string name)
12 | {
13 | Require.NotNull(name, "name");
14 |
15 | Name = name;
16 | }
17 |
18 | public T Accept(IAstVisitor visitor)
19 | {
20 | return visitor.IdentifierAccess(this);
21 | }
22 |
23 | public override string ToString()
24 | {
25 | return Name;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("Expressions.Test")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("Pieter van Ginkel")]
9 | [assembly: AssemblyProduct("Expressions.Test")]
10 | [assembly: AssemblyCopyright("Pieter van Ginkel © 2012")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("272e4c50-7ecc-4fc2-8637-0bcc4719f409")]
17 |
18 | [assembly: AssemblyVersion("1.0.0.0")]
19 | [assembly: AssemblyFileVersion("1.0.0.0")]
20 |
--------------------------------------------------------------------------------
/Expressions/Expressions/TypeAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class TypeAccess : IExpression
8 | {
9 | public Type Type { get; private set; }
10 |
11 | public TypeAccess(Type type)
12 | {
13 | Require.NotNull(type, "type");
14 |
15 | Type = type;
16 | }
17 |
18 | public void Accept(IExpressionVisitor visitor)
19 | {
20 | visitor.TypeAccess(this);
21 | }
22 |
23 | public T Accept(IExpressionVisitor visitor)
24 | {
25 | return visitor.TypeAccess(this);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/ExpressionTests/VoidMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.ExpressionTests
7 | {
8 | [TestFixture]
9 | internal class VoidMethods : TestBase
10 | {
11 | [Test]
12 | [ExpectedException]
13 | public void VoidMethodsAreInvisible()
14 | {
15 | Resolve(
16 | new ExpressionContext(null, new Owner()),
17 | "VoidMethod()"
18 | );
19 | }
20 |
21 | public class Owner
22 | {
23 | public void VoidMethod()
24 | {
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/ExpressionTests/VoidMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.ExpressionTests
7 | {
8 | [TestFixture]
9 | internal class VoidMethods : TestBase
10 | {
11 | [Test]
12 | [ExpectedException]
13 | public void VoidMethodsAreInvisible()
14 | {
15 | Resolve(
16 | new ExpressionContext(null, new Owner()),
17 | "VoidMethod()"
18 | );
19 | }
20 |
21 | public class Owner
22 | {
23 | public void VoidMethod()
24 | {
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Parsing/Parsing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Parsing
7 | {
8 | [TestFixture]
9 | internal class Parsing
10 | {
11 | [Test]
12 | public void ValidSyntaxCheck()
13 | {
14 | DynamicExpression.CheckSyntax(
15 | "1", ExpressionLanguage.Flee
16 | );
17 | }
18 |
19 | [Test]
20 | [ExpectedException]
21 | public void InvalidSyntaxCheck()
22 | {
23 | DynamicExpression.CheckSyntax(
24 | "?", ExpressionLanguage.Flee
25 | );
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Parsing/Parsing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Parsing
7 | {
8 | [TestFixture]
9 | internal class Parsing
10 | {
11 | [Test]
12 | public void ValidSyntaxCheck()
13 | {
14 | DynamicExpression.CheckSyntax(
15 | "1", ExpressionLanguage.Csharp
16 | );
17 | }
18 |
19 | [Test]
20 | [ExpectedException]
21 | public void InvalidSyntaxCheck()
22 | {
23 | DynamicExpression.CheckSyntax(
24 | "?", ExpressionLanguage.Csharp
25 | );
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/VoidMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
7 | {
8 | [TestFixture]
9 | internal class VoidMethods : TestBase
10 | {
11 | [Test]
12 | [ExpectedException]
13 | public void VoidMethodsAreInvisible()
14 | {
15 | Resolve(
16 | new ExpressionContext(null, new Owner()),
17 | "VoidMethod()"
18 | );
19 | }
20 |
21 | public class Owner
22 | {
23 | public void VoidMethod()
24 | {
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Parsing/Parsing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Parsing
7 | {
8 | [TestFixture]
9 | internal class Parsing
10 | {
11 | [Test]
12 | public void ValidSyntaxCheck()
13 | {
14 | DynamicExpression.CheckSyntax(
15 | "1", ExpressionLanguage.VisualBasic
16 | );
17 | }
18 |
19 | [Test]
20 | [ExpectedException]
21 | public void InvalidSyntaxCheck()
22 | {
23 | DynamicExpression.CheckSyntax(
24 | "?", ExpressionLanguage.VisualBasic
25 | );
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/StringExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 | using Expressions.Expressions;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class StringExpressions : TestBase
11 | {
12 | [Test]
13 | public void Escaping()
14 | {
15 | Resolve(
16 | @"""\d""",
17 | new Constant(@"\d")
18 | );
19 | }
20 |
21 | [Test]
22 | public void Quotes()
23 | {
24 | Resolve(
25 | "\"\"\"\"",
26 | new Constant("\"")
27 | );
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Expressions/Flee/FleeLexer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Antlr.Runtime;
5 |
6 | namespace Expressions.Flee
7 | {
8 | partial class FleeLexer
9 | {
10 | public override void ReportError(RecognitionException e)
11 | {
12 | throw new ExpressionsException("Invalid syntax", ExpressionsExceptionType.SyntaxError, e);
13 | }
14 |
15 | protected override object RecoverFromMismatchedToken(IIntStream input, int ttype, BitSet follow)
16 | {
17 | throw new MismatchedTokenException(ttype, input);
18 | }
19 |
20 | public override object RecoverFromMismatchedSet(IIntStream input, RecognitionException e, BitSet follow)
21 | {
22 | throw e;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Expressions/Csharp/CsharpLexer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Antlr.Runtime;
5 |
6 | namespace Expressions.Csharp
7 | {
8 | partial class CsharpLexer
9 | {
10 | public override void ReportError(RecognitionException e)
11 | {
12 | throw new ExpressionsException("Invalid syntax", ExpressionsExceptionType.SyntaxError, e);
13 | }
14 |
15 | protected override object RecoverFromMismatchedToken(IIntStream input, int ttype, BitSet follow)
16 | {
17 | throw new MismatchedTokenException(ttype, input);
18 | }
19 |
20 | public override object RecoverFromMismatchedSet(IIntStream input, RecognitionException e, BitSet follow)
21 | {
22 | throw e;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Expressions/Expressions.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Expressions
5 | $version$
6 | Expressions
7 | Pieter van Ginkel
8 | Pieter van Ginkel
9 | http://www.gnu.org/licenses/lgpl-3.0.txt
10 | http://github.com/pvginkel/Expressions
11 | false
12 | Expression parser for C#, Flee and Visual Basic.
13 | Pieter van Ginkel © 2012
14 | expressions parser compiler msil c# vb vb.net flee visualbasic
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Expressions/VisualBasic/VisualBasicLexer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Antlr.Runtime;
5 |
6 | namespace Expressions.VisualBasic
7 | {
8 | partial class VisualBasicLexer
9 | {
10 | public override void ReportError(RecognitionException e)
11 | {
12 | throw new ExpressionsException("Invalid syntax", ExpressionsExceptionType.SyntaxError, e);
13 | }
14 |
15 | protected override object RecoverFromMismatchedToken(IIntStream input, int ttype, BitSet follow)
16 | {
17 | throw new MismatchedTokenException(ttype, input);
18 | }
19 |
20 | public override object RecoverFromMismatchedSet(IIntStream input, RecognitionException e, BitSet follow)
21 | {
22 | throw e;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/SimpleCalcEngineTests.txt:
--------------------------------------------------------------------------------
1 | ' Tests for simple calc engine
2 | ' Format: ([result expression name]=[result expression value])+;([expression name]:[expression text]?[variables])+
3 | ' Simple expressions
4 | c=300;a:100|b:200|c:a+b
5 | ' referencing same expression more than once
6 | c=300;a:100|c:a+a+a
7 | ' with variables
8 | c=300;a:var1?var1=100|b:var1?var1=200|c:a+b
9 | c=10;a:var1?var1=abc|b:var1?var1=string2|c:a.length + b.length
10 | ' variables in last expression
11 | c=400;a:var1?var1=100|b:var1?var1=200|c:a+b+var1?var1=100
12 | ' with functions
13 | c=400;a:-100|c:abs(a) + abs(a) + abs(b)?b=200
14 | ' with namespace
15 | c=400;a:-100|c:abs(a) + math.abs(a) + abs(b)?b=200
16 | ' more complicated
17 | c=500;a:max(var1, var2) * 2?var1=100&var2=200|b:var1.toString().length + 2?var1=abc|c:max(a, b) + var1?var1=100
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/SimpleCalcEngineTests.txt:
--------------------------------------------------------------------------------
1 | ' Tests for simple calc engine
2 | ' Format: ([result expression name]=[result expression value])+;([expression name]:[expression text]?[variables])+
3 | ' Simple expressions
4 | c=300;a:100|b:200|c:a+b
5 | ' referencing same expression more than once
6 | c=300;a:100|c:a+a+a
7 | ' with variables
8 | c=300;a:var1?var1=100|b:var1?var1=200|c:a+b
9 | c=10;a:var1?var1=abc|b:var1?var1=string2|c:a.length + b.length
10 | ' variables in last expression
11 | c=400;a:var1?var1=100|b:var1?var1=200|c:a+b+var1?var1=100
12 | ' with functions
13 | c=400;a:-100|c:abs(a) + abs(a) + abs(b)?b=200
14 | ' with namespace
15 | c=400;a:-100|c:abs(a) + math.abs(a) + abs(b)?b=200
16 | ' more complicated
17 | c=500;a:max(var1, var2) * 2?var1=100&var2=200|b:var1.toString().length + 2?var1=abc|c:max(a, b) + var1?var1=100
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/SimpleCalcEngineTests.txt:
--------------------------------------------------------------------------------
1 | ' Tests for simple calc engine
2 | ' Format: ([result expression name]=[result expression value])+;([expression name]:[expression text]?[variables])+
3 | ' Simple expressions
4 | c=300;a:100|b:200|c:a+b
5 | ' referencing same expression more than once
6 | c=300;a:100|c:a+a+a
7 | ' with variables
8 | c=300;a:var1?var1=100|b:var1?var1=200|c:a+b
9 | c=10;a:var1?var1=abc|b:var1?var1=string2|c:a.length + b.length
10 | ' variables in last expression
11 | c=400;a:var1?var1=100|b:var1?var1=200|c:a+b+var1?var1=100
12 | ' with functions
13 | c=400;a:-100|c:abs(a) + abs(a) + abs(b)?b=200
14 | ' with namespace
15 | c=400;a:-100|c:abs(a) + math.abs(a) + abs(b)?b=200
16 | ' more complicated
17 | c=500;a:max(var1, var2) * 2?var1=100&var2=200|b:var1.toString().length + 2?var1=abc|c:max(a, b) + var1?var1=100
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/ResultCasting.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class ResultCasting : TestBase
10 | {
11 | [Test]
12 | public void CastIntToLong()
13 | {
14 | Resolve(
15 | "1",
16 | 1L,
17 | new BoundExpressionOptions { ResultType = typeof(long) }
18 | );
19 | }
20 |
21 | [Test]
22 | public void CastCharToDecimal()
23 | {
24 | Resolve(
25 | "'a'",
26 | 97m,
27 | new BoundExpressionOptions { ResultType = typeof(decimal) }
28 | );
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/ResultCasting.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class ResultCasting : TestBase
10 | {
11 | [Test]
12 | public void CastIntToLong()
13 | {
14 | Resolve(
15 | "1",
16 | 1L,
17 | new BoundExpressionOptions { ResultType = typeof(long) }
18 | );
19 | }
20 |
21 | [Test]
22 | public void CastCharToDecimal()
23 | {
24 | Resolve(
25 | "'a'",
26 | 97m,
27 | new BoundExpressionOptions { ResultType = typeof(decimal) }
28 | );
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class UnaryExpressions : TestBase
10 | {
11 | [Test]
12 | public void Arithatics()
13 | {
14 | Resolve("+1", 1);
15 | Resolve("-1", -1);
16 |
17 | var context = new ExpressionContext();
18 |
19 | context.Variables.Add(new Variable("Variable1") { Value = 1 });
20 |
21 | Resolve(context, "+Variable1", 1);
22 | Resolve(context, "-Variable1", -1);
23 | }
24 |
25 | [Test]
26 | public void Logicals()
27 | {
28 | Resolve("not true", false);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/ResultCasting.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class ResultCasting : TestBase
10 | {
11 | [Test]
12 | public void CastIntToLong()
13 | {
14 | Resolve(
15 | "1",
16 | 1L,
17 | new BoundExpressionOptions { ResultType = typeof(long) }
18 | );
19 | }
20 |
21 | [Test]
22 | public void CastCharToDecimal()
23 | {
24 | Resolve(
25 | "'a'",
26 | 97m,
27 | new BoundExpressionOptions { ResultType = typeof(decimal) }
28 | );
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions/Ast/IdentifierCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace Expressions.Ast
7 | {
8 | internal class IdentifierCollection : KeyedCollection
9 | {
10 | public IdentifierCollection()
11 | {
12 | }
13 |
14 | public IdentifierCollection(IEqualityComparer comparer)
15 | : base(comparer)
16 | {
17 | }
18 |
19 | public IdentifierCollection(IEqualityComparer comparer, int dictionaryCreationThreshold)
20 | : base(comparer, dictionaryCreationThreshold)
21 | {
22 | }
23 |
24 | protected override string GetKeyForItem(IdentifierAccess item)
25 | {
26 | return item.Name;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Expressions/Ast/UnaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class UnaryExpression : IAstNode
8 | {
9 | public IAstNode Operand { get; private set; }
10 |
11 | public ExpressionType Type { get; private set; }
12 |
13 | public UnaryExpression(IAstNode operand, ExpressionType type)
14 | {
15 | Require.NotNull(operand, "operand");
16 |
17 | Operand = operand;
18 | Type = type;
19 | }
20 |
21 | public override string ToString()
22 | {
23 | return String.Format("({0} {1})", Type, Operand);
24 | }
25 |
26 | public T Accept(IAstVisitor visitor)
27 | {
28 | return visitor.UnaryExpression(this);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class UnaryExpressions : TestBase
10 | {
11 | [Test]
12 | public void Arithatics()
13 | {
14 | Resolve("+1", 1);
15 | Resolve("-1", -1);
16 |
17 | var context = new ExpressionContext();
18 |
19 | context.Variables.Add(new Variable("Variable1") { Value = 1 });
20 |
21 | Resolve(context, "+Variable1", 1);
22 | Resolve(context, "-Variable1", -1);
23 | }
24 |
25 | [Test]
26 | public void Logicals()
27 | {
28 | Resolve("!true", false);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions/Ast/Constant.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class Constant : IAstNode
8 | {
9 | public static readonly Constant True = new Constant(true);
10 | public static readonly Constant False = new Constant(false);
11 | public static readonly Constant Null = new Constant(null);
12 |
13 | public object Value { get; private set; }
14 |
15 | public Constant(object value)
16 | {
17 | Value = value;
18 | }
19 |
20 | public override string ToString()
21 | {
22 | return Value == null ? "null" : Value.ToString();
23 | }
24 |
25 | public T Accept(IAstVisitor visitor)
26 | {
27 | return visitor.Constant(this);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Expressions/Expressions/VariableAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class VariableAccess : IExpression
8 | {
9 | public Type Type { get; private set; }
10 |
11 | public int ParameterIndex { get; private set; }
12 |
13 | public VariableAccess(Type type, int parameterIndex)
14 | {
15 | Require.NotNull(type, "type");
16 |
17 | Type = type;
18 | ParameterIndex = parameterIndex;
19 | }
20 |
21 | public void Accept(IExpressionVisitor visitor)
22 | {
23 | visitor.VariableAccess(this);
24 | }
25 |
26 | public T Accept(IExpressionVisitor visitor)
27 | {
28 | return visitor.VariableAccess(this);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class UnaryExpressions : TestBase
10 | {
11 | [Test]
12 | public void Arithatics()
13 | {
14 | Resolve("+1", 1);
15 | Resolve("-1", -1);
16 |
17 | var context = new ExpressionContext();
18 |
19 | context.Variables.Add(new Variable("Variable1") { Value = 1 });
20 |
21 | Resolve(context, "+Variable1", 1);
22 | Resolve(context, "-Variable1", -1);
23 | }
24 |
25 | [Test]
26 | public void Logicals()
27 | {
28 | Resolve("not true", false);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions/Ast/MemberAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class MemberAccess : IAstNode
8 | {
9 | public IAstNode Operand { get; private set; }
10 |
11 | public string Member { get; private set; }
12 |
13 | public MemberAccess(IAstNode operand, string member)
14 | {
15 | Require.NotNull(operand, "operand");
16 | Require.NotNull(member, "member");
17 |
18 | Operand = operand;
19 | Member = member;
20 | }
21 |
22 | public T Accept(IAstVisitor visitor)
23 | {
24 | return visitor.MemberAccess(this);
25 | }
26 |
27 | public override string ToString()
28 | {
29 | return Operand + "." + Member;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Expressions/Expressions/ImportAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class ImportAccess : IExpression
8 | {
9 | public Type Type
10 | {
11 | get { throw new NotSupportedException(); }
12 | }
13 |
14 | public Import Import { get; private set; }
15 |
16 | public ImportAccess(Import import)
17 | {
18 | Require.NotNull(import, "import");
19 |
20 | Import = import;
21 | }
22 |
23 | public void Accept(IExpressionVisitor visitor)
24 | {
25 | throw new NotSupportedException();
26 | }
27 |
28 | public T Accept(IExpressionVisitor visitor)
29 | {
30 | throw new NotSupportedException();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/LongBranchLogicalTest.txt:
--------------------------------------------------------------------------------
1 | ((M0100_ASSMT_REASON = "01" OR M0100_ASSMT_REASON = "03") AND (M0220_PRIOR_UR_INCON_bool OR M0220_PRIOR_CATH_bool OR M0220_PRIOR_INTRACT_PAIN_bool OR M0220_PRIOR_IMPR_DECSN_bool OR M0220_PRIOR_DISRUPTIVE_bool OR M0220_PRIOR_MEM_LOSS_bool OR M0220_PRIOR_NONE_bool OR M0220_PRIOR_NOCHG_14D_bool OR M0220_PRIOR_UNKNOWN_bool) AND ((M0220_PRIOR_UR_INCON = "0" OR M0220_PRIOR_UR_INCON = "0") AND (M0220_PRIOR_CATH = "0" OR M0220_PRIOR_CATH = "0") AND (M0220_PRIOR_INTRACT_PAIN = "0" OR M0220_PRIOR_INTRACT_PAIN = "0") AND (M0220_PRIOR_IMPR_DECSN = "0" OR M0220_PRIOR_IMPR_DECSN = "0") AND (M0220_PRIOR_DISRUPTIVE = "0" OR M0220_PRIOR_DISRUPTIVE = "0") AND (M0220_PRIOR_MEM_LOSS = "0" OR M0220_PRIOR_MEM_LOSS = "0") AND (M0220_PRIOR_NONE = "0" OR M0220_PRIOR_NONE = "0") AND (M0220_PRIOR_NOCHG_14D = "0" OR M0220_PRIOR_NOCHG_14D = "0") AND (M0220_PRIOR_UNKNOWN = "0" OR M0220_PRIOR_UNKNOWN = "0")))
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/LongBranchLogicalTest.txt:
--------------------------------------------------------------------------------
1 | ((M0100_ASSMT_REASON = "01" OR M0100_ASSMT_REASON = "03") AND (M0220_PRIOR_UR_INCON_bool OR M0220_PRIOR_CATH_bool OR M0220_PRIOR_INTRACT_PAIN_bool OR M0220_PRIOR_IMPR_DECSN_bool OR M0220_PRIOR_DISRUPTIVE_bool OR M0220_PRIOR_MEM_LOSS_bool OR M0220_PRIOR_NONE_bool OR M0220_PRIOR_NOCHG_14D_bool OR M0220_PRIOR_UNKNOWN_bool) AND ((M0220_PRIOR_UR_INCON = "0" OR M0220_PRIOR_UR_INCON = "0") AND (M0220_PRIOR_CATH = "0" OR M0220_PRIOR_CATH = "0") AND (M0220_PRIOR_INTRACT_PAIN = "0" OR M0220_PRIOR_INTRACT_PAIN = "0") AND (M0220_PRIOR_IMPR_DECSN = "0" OR M0220_PRIOR_IMPR_DECSN = "0") AND (M0220_PRIOR_DISRUPTIVE = "0" OR M0220_PRIOR_DISRUPTIVE = "0") AND (M0220_PRIOR_MEM_LOSS = "0" OR M0220_PRIOR_MEM_LOSS = "0") AND (M0220_PRIOR_NONE = "0" OR M0220_PRIOR_NONE = "0") AND (M0220_PRIOR_NOCHG_14D = "0" OR M0220_PRIOR_NOCHG_14D = "0") AND (M0220_PRIOR_UNKNOWN = "0" OR M0220_PRIOR_UNKNOWN = "0")))
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/LongBranchLogicalTest.txt:
--------------------------------------------------------------------------------
1 | ((M0100_ASSMT_REASON = "01" OR M0100_ASSMT_REASON = "03") AND (M0220_PRIOR_UR_INCON_bool OR M0220_PRIOR_CATH_bool OR M0220_PRIOR_INTRACT_PAIN_bool OR M0220_PRIOR_IMPR_DECSN_bool OR M0220_PRIOR_DISRUPTIVE_bool OR M0220_PRIOR_MEM_LOSS_bool OR M0220_PRIOR_NONE_bool OR M0220_PRIOR_NOCHG_14D_bool OR M0220_PRIOR_UNKNOWN_bool) AND ((M0220_PRIOR_UR_INCON = "0" OR M0220_PRIOR_UR_INCON = "0") AND (M0220_PRIOR_CATH = "0" OR M0220_PRIOR_CATH = "0") AND (M0220_PRIOR_INTRACT_PAIN = "0" OR M0220_PRIOR_INTRACT_PAIN = "0") AND (M0220_PRIOR_IMPR_DECSN = "0" OR M0220_PRIOR_IMPR_DECSN = "0") AND (M0220_PRIOR_DISRUPTIVE = "0" OR M0220_PRIOR_DISRUPTIVE = "0") AND (M0220_PRIOR_MEM_LOSS = "0" OR M0220_PRIOR_MEM_LOSS = "0") AND (M0220_PRIOR_NONE = "0" OR M0220_PRIOR_NONE = "0") AND (M0220_PRIOR_NOCHG_14D = "0" OR M0220_PRIOR_NOCHG_14D = "0") AND (M0220_PRIOR_UNKNOWN = "0" OR M0220_PRIOR_UNKNOWN = "0")))
--------------------------------------------------------------------------------
/Expressions/ExpressionType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | internal enum ExpressionType
8 | {
9 | And,
10 | AndBoth,
11 | Or,
12 | OrBoth,
13 | Xor,
14 | Equals,
15 | Compares,
16 | NotEquals,
17 | NotCompares,
18 | Greater,
19 | GreaterOrEquals,
20 | Less,
21 | LessOrEquals,
22 | In,
23 | ShiftLeft,
24 | ShiftRight,
25 | Add,
26 | Subtract,
27 | Power,
28 | Multiply,
29 | Divide,
30 | Modulo,
31 | Plus,
32 | Minus,
33 | Not,
34 | Group,
35 | LogicalAnd,
36 | LogicalOr,
37 | LogicalNot,
38 | BitwiseAnd,
39 | BitwiseOr,
40 | BitwiseNot,
41 | Concat
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Expressions/Expressions/Constant.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class Constant : IExpression
8 | {
9 | public Type Type { get; private set; }
10 |
11 | public object Value { get; private set; }
12 |
13 | public Constant(object value)
14 | {
15 | Value = value;
16 |
17 | if (value == null)
18 | Type = typeof(object);
19 | else if (value is UnparsedNumber)
20 | Type = ((UnparsedNumber)value).Type;
21 | else
22 | Type = value.GetType();
23 | }
24 |
25 | public void Accept(IExpressionVisitor visitor)
26 | {
27 | visitor.Constant(this);
28 | }
29 |
30 | public T Accept(IExpressionVisitor visitor)
31 | {
32 | return visitor.Constant(this);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Expressions/Ast/BinaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class BinaryExpression : IAstNode
8 | {
9 | public IAstNode Left { get; private set; }
10 |
11 | public IAstNode Right { get; private set; }
12 |
13 | public ExpressionType Type { get; private set; }
14 |
15 | public BinaryExpression(IAstNode left, IAstNode right, ExpressionType type)
16 | {
17 | Require.NotNull(left, "left");
18 | Require.NotNull(right, "right");
19 |
20 | Left = left;
21 | Right = right;
22 | Type = type;
23 | }
24 |
25 | public T Accept(IAstVisitor visitor)
26 | {
27 | return visitor.BinaryExpression(this);
28 | }
29 |
30 | public override string ToString()
31 | {
32 | return String.Format("({0} {1} {2})", Left, Type, Right);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Expressions/Ast/MethodCall.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class MethodCall : IAstNode
8 | {
9 | public IAstNode Operand { get; private set; }
10 |
11 | public AstNodeCollection Arguments { get; private set; }
12 |
13 | public MethodCall(IAstNode operand)
14 | : this(operand, null)
15 | {
16 | }
17 |
18 | public MethodCall(IAstNode operand, AstNodeCollection arguments)
19 | {
20 | Require.NotNull(operand, "operand");
21 |
22 | Operand = operand;
23 | Arguments = arguments;
24 | }
25 |
26 | public T Accept(IAstVisitor visitor)
27 | {
28 | return visitor.MethodCall(this);
29 | }
30 |
31 | public override string ToString()
32 | {
33 | return Operand + (Arguments == null ? "()" : Arguments.ToString());
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Expressions/Csharp/Generated/Flee.tokens:
--------------------------------------------------------------------------------
1 | T__32=32
2 | T__33=33
3 | T__34=34
4 | T__35=35
5 | T__36=36
6 | T__37=37
7 | T__38=38
8 | T__39=39
9 | T__40=40
10 | T__41=41
11 | T__42=42
12 | T__43=43
13 | T__44=44
14 | T__45=45
15 | T__46=46
16 | T__47=47
17 | T__48=48
18 | T__49=49
19 | T__50=50
20 | AND=4
21 | CAST=5
22 | CHARACTER_LITERAL=6
23 | DATETIME_LITERAL=7
24 | DECIMAL_LITERAL=8
25 | DOT=9
26 | Digits=10
27 | EscapeSequence=11
28 | Exponent=12
29 | FALSE=13
30 | FLOATING_POINT_LITERAL=14
31 | FloatTypeSuffix=15
32 | HEX_LITERAL=16
33 | HexDigit=17
34 | IDENTIFIER=18
35 | IF=19
36 | IN=20
37 | LETTER=21
38 | NOT=22
39 | NULL=23
40 | NumericTypeSuffix=24
41 | OR=25
42 | STRING_LITERAL=26
43 | TIMESPAN_LITERAL=27
44 | TRUE=28
45 | UnicodeEscape=29
46 | WS=30
47 | XOR=31
48 | '%'=32
49 | '('=33
50 | ')'=34
51 | '*'=35
52 | '+'=36
53 | ','=37
54 | '-'=38
55 | '/'=39
56 | '<'=40
57 | '<<'=41
58 | '<='=42
59 | '<>'=43
60 | '='=44
61 | '>'=45
62 | '>='=46
63 | '>>'=47
64 | '['=48
65 | ']'=49
66 | '^'=50
67 |
--------------------------------------------------------------------------------
/Expressions/IExecutionContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Represents the execution context supplied when executing a bound expression.
9 | ///
10 | public interface IExecutionContext
11 | {
12 | ///
13 | /// Get the owner of the expression or null when the expression
14 | /// does not have an owner.
15 | ///
16 | object Owner { get; }
17 |
18 | ///
19 | /// Get the value of a variable of the expression or null when
20 | /// the variable does not exist.
21 | ///
22 | /// The name of the variable to get the value for.
23 | /// True to ignore case when resolving the variable; otherwise false.
24 | ///
25 | object GetVariableValue(string variable, bool ignoreCase);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Expressions/Variable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Describes a variable used in an .
9 | ///
10 | public sealed class Variable
11 | {
12 | ///
13 | /// Get the name of the variable.
14 | ///
15 | public string Name { get; private set; }
16 |
17 | ///
18 | /// Get or set the value of the variable.
19 | ///
20 | public object Value { get; set; }
21 |
22 | ///
23 | /// Initializes a new instance of the class with
24 | /// the specified name.
25 | ///
26 | /// The name of the variable.
27 | public Variable(string name)
28 | {
29 | Require.NotNull(name, "name");
30 |
31 | Name = name;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Expressions/CachedDynamicExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 |
6 | namespace Expressions
7 | {
8 | internal class CachedDynamicExpression
9 | {
10 | private readonly BoundExpressionCache _boundExpressionCache;
11 |
12 | public ParseResult ParseResult { get; private set; }
13 |
14 | public ExpressionLanguage Language { get; private set; }
15 |
16 | public CachedDynamicExpression(ParseResult parseResult, ExpressionLanguage language)
17 | {
18 | Require.NotNull(parseResult, "parseResult");
19 |
20 | _boundExpressionCache = new BoundExpressionCache(this);
21 |
22 | ParseResult = parseResult;
23 | Language = language;
24 | }
25 |
26 | public BoundExpression GetOrCreateBoundExpression(IBindingContext binder, BoundExpressionOptions options)
27 | {
28 | return _boundExpressionCache.GetOrCreateBoundExpression(binder, options);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Issues/Issue14Fixture.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Test.CsharpLanguage.ExpressionTests;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.Issues
8 | {
9 | [TestFixture]
10 | internal class Issue14Fixture : TestBase
11 | {
12 | [Test]
13 | [ExpectedException(typeof(ExpressionsException))]
14 | public void Test()
15 | {
16 | string translatedString = "uppercase(\"hello\")";
17 | var expr = new DynamicExpression(translatedString, ExpressionLanguage.Csharp);
18 | var context = new ExpressionContext(null, new CustomOwner(), true);
19 | var boundExpression = expr.Bind(context);
20 | object res = boundExpression.Invoke();
21 | }
22 |
23 | public class CustomOwner
24 | {
25 | public string uppercase(string str)
26 | {
27 | return str.ToUpperInvariant();
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Expressions/Ast/Conditional.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class Conditional : IAstNode
8 | {
9 | public IAstNode Condition { get; private set; }
10 |
11 | public IAstNode Then { get; private set; }
12 |
13 | public IAstNode Else { get; private set; }
14 |
15 | public Conditional(IAstNode condition, IAstNode then, IAstNode @else)
16 | {
17 | Require.NotNull(condition, "condition");
18 | Require.NotNull(then, "then");
19 | Require.NotNull(@else, "else");
20 |
21 | Condition = condition;
22 | Then = then;
23 | Else = @else;
24 | }
25 |
26 | public T Accept(IAstVisitor visitor)
27 | {
28 | return visitor.Conditional(this);
29 | }
30 |
31 | public override string ToString()
32 | {
33 | return String.Format("Conditional({0}, {1}, {2})", Condition, Then, Else);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Expressions/Expressions/FieldAccess.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Text;
5 |
6 | namespace Expressions.Expressions
7 | {
8 | internal class FieldAccess : IExpression
9 | {
10 | public Type Type
11 | {
12 | get { return FieldInfo.FieldType; }
13 | }
14 |
15 | public IExpression Operand { get; private set; }
16 |
17 | public FieldInfo FieldInfo { get; private set; }
18 |
19 | public FieldAccess(IExpression operand, FieldInfo fieldInfo)
20 | {
21 | Require.NotNull(operand, "operand");
22 | Require.NotNull(fieldInfo, "fieldInfo");
23 |
24 | Operand = operand;
25 | FieldInfo = fieldInfo;
26 | }
27 |
28 | public void Accept(IExpressionVisitor visitor)
29 | {
30 | visitor.FieldAccess(this);
31 | }
32 |
33 | public T Accept(IExpressionVisitor visitor)
34 | {
35 | return visitor.FieldAccess(this);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Expressions/Expressions/Index.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace Expressions.Expressions
7 | {
8 | internal class Index : IExpression
9 | {
10 | public IExpression Operand { get; private set; }
11 |
12 | public IExpression Argument { get; private set; }
13 |
14 | public Type Type { get; private set; }
15 |
16 | public Index(IExpression operand, IExpression argument, Type type)
17 | {
18 | Require.NotNull(operand, "operand");
19 | Require.NotNull(argument, "argument");
20 | Require.NotNull(type, "type");
21 |
22 | Operand = operand;
23 | Type = type;
24 |
25 | Argument = argument;
26 | }
27 |
28 | public void Accept(IExpressionVisitor visitor)
29 | {
30 | visitor.Index(this);
31 | }
32 |
33 | public T Accept(IExpressionVisitor visitor)
34 | {
35 | return visitor.Index(this);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Expressions/Expressions/UnaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Ast;
5 |
6 | namespace Expressions.Expressions
7 | {
8 | internal class UnaryExpression : IExpression
9 | {
10 | public IExpression Operand { get; private set; }
11 |
12 | public Type Type { get; private set; }
13 |
14 | public ExpressionType ExpressionType { get; private set; }
15 |
16 | public UnaryExpression(IExpression operand, Type type, ExpressionType expressionType)
17 | {
18 | Require.NotNull(operand, "operand");
19 | Require.NotNull(type, "type");
20 |
21 | Operand = operand;
22 | Type = type;
23 | ExpressionType = expressionType;
24 | }
25 |
26 | public void Accept(IExpressionVisitor visitor)
27 | {
28 | visitor.UnaryExpression(this);
29 | }
30 |
31 | public T Accept(IExpressionVisitor visitor)
32 | {
33 | return visitor.UnaryExpression(this);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Codegen/Templates/Ruby/ASTDbg.stg:
--------------------------------------------------------------------------------
1 | @parserBody.additionalMembers() ::= <<
2 | def self.return_scope_members
3 | super.push( :tree )
4 | end
5 |
6 | attr_reader :adaptor
7 | def adaptor=( adaptor )
8 | @adaptor =
9 | adaptor.is_a?( ANTLR3::Debug::TreeAdaptor ) ? adaptor :
10 | ANTLR3::Debug::TreeAdaptor.wrap( adaptor, @debug_listener )
11 | .adaptor = @adaptor}; separator="\n">
12 | end
13 |
14 | alias tree_adaptor adaptor
15 | alias tree_adaptor= adaptor=
16 | >>
17 |
18 |
19 | createListenerAndHandshake() ::= <<
20 | options[ :debug_listener ] ||= begin
21 | port = options[ :port ]
22 | log = options[ :log ]
23 | proxy = ANTLR3::Debug::EventSocketProxy.new( self,
24 | :adaptor => adaptor,
25 | :log => log,
26 | :port => port
27 | )
28 | proxy.handshake
29 | proxy
30 | end
31 | >>
32 |
33 | @parserConstructor.init() ::= "self.adaptor = adaptor"
34 |
35 | @newDelegate.delegateOptions() ::= ", :adaptor => adaptor"
36 |
37 | @rewriteElement.pregen() ::= "@debug_listener.location( , )"
38 |
--------------------------------------------------------------------------------
/Expressions/Expressions/Cast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class Cast : IExpression
8 | {
9 | public IExpression Operand { get; private set; }
10 |
11 | public Type Type { get; private set; }
12 |
13 | public CastType CastType { get; set; }
14 |
15 | public Cast(IExpression operand, Type type)
16 | : this(operand, type, CastType.Cast)
17 | {
18 | }
19 |
20 | public Cast(IExpression operand, Type type, CastType castType)
21 | {
22 | Require.NotNull(operand, "operand");
23 | Require.NotNull(type, "type");
24 |
25 | Operand = operand;
26 | Type = type;
27 | CastType = castType;
28 | }
29 |
30 | public void Accept(IExpressionVisitor visitor)
31 | {
32 | visitor.Cast(this);
33 | }
34 |
35 | public T Accept(IExpressionVisitor visitor)
36 | {
37 | return visitor.Cast(this);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Expressions/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | [assembly: AssemblyTitle("Expressions")]
7 | [assembly: AssemblyDescription("")]
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("Pieter van Ginkel")]
10 | [assembly: AssemblyProduct("Expressions")]
11 | [assembly: AssemblyCopyright("Pieter van Ginkel © 2012")]
12 | [assembly: AssemblyTrademark("")]
13 | [assembly: AssemblyCulture("")]
14 |
15 | [assembly: ComVisible(false)]
16 | [assembly: CLSCompliant(true)]
17 |
18 | [assembly: Guid("e84f56bf-8a44-4787-acb5-0dc2f22b1f8f")]
19 | [assembly: InternalsVisibleTo("Expressions.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100157527ab8ef03d584cd8fff60c6642b9172c679da194efc5591f3bf9ea6919ff5e905d624c1e2146e27f84478e4b6f985a24e556fcea3bd072b2761c077a5540900553040e8fd335b7fbf9080ba585055c9e9ae9a1ae1169c89120f99f149bb396d1f7796a73f8ae69734b807352a89b096fe540c602f48cb0a7a0de053bcea2")]
20 |
21 | [assembly: AssemblyVersion("0.1.3.0")]
22 | [assembly: AssemblyFileVersion("0.1.3.0")]
23 |
--------------------------------------------------------------------------------
/Expressions/Ast/Cast.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class Cast : IAstNode
8 | {
9 | public IAstNode Operand { get; private set; }
10 |
11 | public TypeIdentifier Type { get; private set; }
12 |
13 | public CastType CastType { get; private set; }
14 |
15 | public Cast(IAstNode operand, TypeIdentifier type)
16 | : this(operand, type, CastType.Cast)
17 | {
18 | }
19 |
20 | public Cast(IAstNode operand, TypeIdentifier type, CastType castType)
21 | {
22 | Require.NotNull(operand, "operand");
23 | Require.NotNull(type, "type");
24 |
25 | Operand = operand;
26 | Type = type;
27 | CastType = castType;
28 | }
29 |
30 | public T Accept(IAstVisitor visitor)
31 | {
32 | return visitor.Cast(this);
33 | }
34 |
35 | public override string ToString()
36 | {
37 | return String.Format("Cast({0}, {1})", Operand, Type);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/BulkTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.BulkTests
7 | {
8 | internal class BulkTests : Test.BulkTests
9 | {
10 | public BulkTests()
11 | : base(ExpressionLanguage.Flee)
12 | {
13 | }
14 |
15 | [Test(Description = "Expressions that should not be valid")]
16 | public void TestInvalidExpressions()
17 | {
18 | ProcessScriptTests("InvalidExpressions.txt", DoTestInvalidExpressions);
19 | }
20 |
21 | private void DoTestInvalidExpressions(string[] arr)
22 | {
23 | var reason = (ExpressionsExceptionType)Enum.Parse(typeof(ExpressionsExceptionType), arr[2], true);
24 |
25 | var options = new BoundExpressionOptions
26 | {
27 | ResultType = Type.GetType(arr[0], true, true),
28 | AllowPrivateAccess = true
29 | };
30 |
31 | AssertCompileException(arr[1], MyGenericContext, options, reason);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Expressions/IBindingContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Represents the binding context supplied when binding an expression.
9 | ///
10 | public interface IBindingContext
11 | {
12 | ///
13 | /// Get the type of the owner of the expression or null when
14 | /// the expression does not have an owner.
15 | ///
16 | Type OwnerType { get; }
17 |
18 | ///
19 | /// Get the imports of the expression.
20 | ///
21 | IList Imports { get; }
22 |
23 | ///
24 | /// Get the type of a variable of the expression or null when the
25 | /// variable doesn't exist.
26 | ///
27 | /// The name of the variable.
28 | /// True to ignore case when resolving the variable; otherwise false.
29 | ///
30 | Type GetVariableType(string variable, bool ignoreCase);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/Fields.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Fields : TestBase
10 | {
11 | [Test]
12 | public void StaticFieldOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "StaticField", 8);
17 | }
18 |
19 | [Test]
20 | public void FieldOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "Field", 7);
25 | }
26 |
27 | [Test]
28 | public void ConstantAccess()
29 | {
30 | var context = new ExpressionContext(new[] { new Import("int", typeof(int)) });
31 |
32 | Resolve(context, "int.MaxValue", int.MaxValue);
33 | }
34 |
35 | public class Owner
36 | {
37 | public static int StaticField = 8;
38 |
39 | public int Field = 7;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/Fields.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Fields : TestBase
10 | {
11 | [Test]
12 | public void StaticFieldOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "StaticField", 8);
17 | }
18 |
19 | [Test]
20 | public void FieldOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "Field", 7);
25 | }
26 |
27 | [Test]
28 | public void ConstantAccess()
29 | {
30 | var context = new ExpressionContext(new[] { new Import("int", typeof(int)) });
31 |
32 | Resolve(context, "int.MaxValue", int.MaxValue);
33 | }
34 |
35 | public class Owner
36 | {
37 | public static int StaticField = 8;
38 |
39 | public int Field = 7;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/Fields.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Fields : TestBase
10 | {
11 | [Test]
12 | public void StaticFieldOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "StaticField", 8);
17 | }
18 |
19 | [Test]
20 | public void FieldOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "Field", 7);
25 | }
26 |
27 | [Test]
28 | public void ConstantAccess()
29 | {
30 | var context = new ExpressionContext(new[] { new Import("int", typeof(int)) });
31 |
32 | Resolve(context, "int.MaxValue", int.MaxValue);
33 | }
34 |
35 | public class Owner
36 | {
37 | public static int StaticField = 8;
38 |
39 | public int Field = 7;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Expressions/Ast/TypeIdentifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class TypeIdentifier : IAstNode
8 | {
9 | public string Name { get; private set; }
10 |
11 | public int ArrayIndex { get; private set; }
12 |
13 | public TypeIdentifier(string name, int arrayIndex)
14 | {
15 | Require.NotNull(name, "name");
16 |
17 | Name = name;
18 | ArrayIndex = arrayIndex;
19 | }
20 |
21 | public T Accept(IAstVisitor visitor)
22 | {
23 | throw new NotSupportedException();
24 | }
25 |
26 | public override string ToString()
27 | {
28 | var sb = new StringBuilder();
29 |
30 | sb.Append(Name);
31 |
32 | if (ArrayIndex > 0)
33 | {
34 | sb.Append('[');
35 |
36 | if (ArrayIndex > 1)
37 | sb.Append(new String(',', ArrayIndex - 1));
38 |
39 | sb.Append(']');
40 | }
41 |
42 | return sb.ToString();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Expressions/Csharp/Generated/Csharp.tokens:
--------------------------------------------------------------------------------
1 | T__22=22
2 | T__23=23
3 | T__24=24
4 | T__25=25
5 | T__26=26
6 | T__27=27
7 | T__28=28
8 | T__29=29
9 | T__30=30
10 | T__31=31
11 | T__32=32
12 | T__33=33
13 | T__34=34
14 | T__35=35
15 | T__36=36
16 | T__37=37
17 | T__38=38
18 | T__39=39
19 | T__40=40
20 | T__41=41
21 | T__42=42
22 | T__43=43
23 | T__44=44
24 | T__45=45
25 | T__46=46
26 | T__47=47
27 | T__48=48
28 | T__49=49
29 | T__50=50
30 | T__51=51
31 | CHARACTER_LITERAL=4
32 | DATETIME_LITERAL=5
33 | DECIMAL_LITERAL=6
34 | DOT=7
35 | Digits=8
36 | EscapeSequence=9
37 | Exponent=10
38 | FLOATING_POINT_LITERAL=11
39 | FloatTypeSuffix=12
40 | HEX_LITERAL=13
41 | HexDigit=14
42 | IDENTIFIER=15
43 | LETTER=16
44 | NumericTypeSuffix=17
45 | STRING_LITERAL=18
46 | TIMESPAN_LITERAL=19
47 | UnicodeEscape=20
48 | WS=21
49 | '!'=22
50 | '!='=23
51 | '%'=24
52 | '&&'=25
53 | '&'=26
54 | '('=27
55 | ')'=28
56 | '*'=29
57 | '+'=30
58 | ','=31
59 | '-'=32
60 | '/'=33
61 | ':'=34
62 | '<'=35
63 | '<<'=36
64 | '<='=37
65 | '=='=38
66 | '>'=39
67 | '>='=40
68 | '>>'=41
69 | '?'=42
70 | '['=43
71 | ']'=44
72 | '^'=45
73 | 'false'=46
74 | 'null'=47
75 | 'true'=48
76 | '|'=49
77 | '||'=50
78 | '~'=51
79 |
--------------------------------------------------------------------------------
/Expressions/Expressions/Conditional.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Expressions
6 | {
7 | internal class Conditional : IExpression
8 | {
9 | public IExpression Condition { get; private set; }
10 |
11 | public IExpression Then { get; private set; }
12 |
13 | public IExpression Else { get; private set; }
14 |
15 | public Type Type { get; private set; }
16 |
17 | public Conditional(IExpression condition, IExpression then, IExpression @else, Type type)
18 | {
19 | Require.NotNull(condition, "condition");
20 | Require.NotNull(then, "then");
21 | Require.NotNull(@else, "else");
22 | Require.NotNull(type, "type");
23 |
24 | Condition = condition;
25 | Then = then;
26 | Else = @else;
27 | Type = type;
28 | }
29 |
30 | public void Accept(IExpressionVisitor visitor)
31 | {
32 | visitor.Conditional(this);
33 | }
34 |
35 | public T Accept(IExpressionVisitor visitor)
36 | {
37 | return visitor.Conditional(this);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Expressions/Ast/Index.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions.Ast
6 | {
7 | internal class Index : IAstNode
8 | {
9 | public IAstNode Operand { get; private set; }
10 |
11 | public AstNodeCollection Arguments { get; private set; }
12 |
13 | public Index(IAstNode operand, AstNodeCollection arguments)
14 | {
15 | Require.NotNull(operand, "operand");
16 | Require.NotNull(arguments, "arguments");
17 |
18 | Operand = operand;
19 | Arguments = arguments;
20 | }
21 |
22 | public T Accept(IAstVisitor visitor)
23 | {
24 | return visitor.Index(this);
25 | }
26 |
27 | public override string ToString()
28 | {
29 | var sb = new StringBuilder();
30 |
31 | sb.Append(Operand);
32 | sb.Append('[');
33 |
34 | for (int i = 0; i < Arguments.Nodes.Count; i++)
35 | {
36 | if (i > 0)
37 | sb.Append(", ");
38 |
39 | sb.Append(Arguments.Nodes[i]);
40 | }
41 |
42 | sb.Append(']');
43 |
44 | return sb.ToString();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/Indexing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Indexing : TestBase
10 | {
11 | [Test]
12 | public void ArrayIndexOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "ArrayProperty[0]", 1);
17 | }
18 |
19 | [Test]
20 | public void RankedArrayIndexOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "RankedProperty[0,0]", 1);
25 | Resolve(context, "RankedProperty[1,1]", 4);
26 | }
27 |
28 | public class Owner
29 | {
30 | public int[] ArrayProperty
31 | {
32 | get { return new[] { 1, 2, 3 }; }
33 | }
34 |
35 | public int[,] RankedProperty
36 | {
37 | get
38 | {
39 | return new[,]
40 | {
41 | { 1, 2 },
42 | { 3, 4 }
43 | };
44 | }
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/Indexing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Indexing : TestBase
10 | {
11 | [Test]
12 | public void ArrayIndexOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "ArrayProperty[0]", 1);
17 | }
18 |
19 | [Test]
20 | public void RankedArrayIndexOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "RankedProperty[0,0]", 1);
25 | Resolve(context, "RankedProperty[1,1]", 4);
26 | }
27 |
28 | public class Owner
29 | {
30 | public int[] ArrayProperty
31 | {
32 | get { return new[] { 1, 2, 3 }; }
33 | }
34 |
35 | public int[,] RankedProperty
36 | {
37 | get
38 | {
39 | return new[,]
40 | {
41 | { 1, 2 },
42 | { 3, 4 }
43 | };
44 | }
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/Indexing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Indexing : TestBase
10 | {
11 | [Test]
12 | public void ArrayIndexOnOwner()
13 | {
14 | var context = new ExpressionContext(null, new Owner());
15 |
16 | Resolve(context, "ArrayProperty(0)", 1);
17 | }
18 |
19 | [Test]
20 | public void RankedArrayIndexOnOwner()
21 | {
22 | var context = new ExpressionContext(null, new Owner());
23 |
24 | Resolve(context, "RankedProperty(0,0)", 1);
25 | Resolve(context, "RankedProperty(1,1)", 4);
26 | }
27 |
28 | public class Owner
29 | {
30 | public int[] ArrayProperty
31 | {
32 | get { return new[] { 1, 2, 3 }; }
33 | }
34 |
35 | public int[,] RankedProperty
36 | {
37 | get
38 | {
39 | return new[,]
40 | {
41 | { 1, 2 },
42 | { 3, 4 }
43 | };
44 | }
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Expressions/VariableCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace Expressions
7 | {
8 | ///
9 | /// A collection of 's.
10 | ///
11 | public sealed class VariableCollection : KeyedCollection
12 | {
13 | internal VariableCollection(IEqualityComparer comparer)
14 | : base(comparer)
15 | {
16 | }
17 |
18 | ///
19 | /// When implemented in a derived class, extracts the key from the specified element.
20 | ///
21 | ///
22 | /// The key for the specified element.
23 | ///
24 | /// The element from which to extract the key.
25 | ///
26 | protected override string GetKeyForItem(Variable item)
27 | {
28 | return item.Name;
29 | }
30 |
31 | ///
32 | /// Add a new to the collection with the specified
33 | /// name and value.
34 | ///
35 | /// The name of the variable.
36 | /// The value of the variable.
37 | public void Add(string name, object value)
38 | {
39 | Add(new Variable(name) { Value = value });
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Expressions/Expressions/MethodCall.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Reflection;
5 | using System.Text;
6 |
7 | namespace Expressions.Expressions
8 | {
9 | internal class MethodCall : IExpression
10 | {
11 | private static readonly IExpression[] EmptyArguments = new IExpression[0];
12 |
13 | public IExpression Operand { get; private set; }
14 |
15 | public MethodInfo MethodInfo { get; private set; }
16 |
17 | public IList Arguments { get; private set; }
18 |
19 | public Type Type
20 | {
21 | get { return MethodInfo.ReturnType; }
22 | }
23 |
24 | public MethodCall(IExpression operand, MethodInfo methodInfo, IList arguments)
25 | {
26 | Require.NotNull(operand, "operand");
27 | Require.NotNull(methodInfo, "methodInfo");
28 |
29 | Operand = operand;
30 | MethodInfo = methodInfo;
31 |
32 | if (arguments == null || arguments.Count == 0)
33 | Arguments = EmptyArguments;
34 | else
35 | Arguments = new ReadOnlyCollection(arguments);
36 | }
37 |
38 | public void Accept(IExpressionVisitor visitor)
39 | {
40 | visitor.MethodCall(this);
41 | }
42 |
43 | public T Accept(IExpressionVisitor visitor)
44 | {
45 | return visitor.MethodCall(this);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/ExpressionTests/SpecialConstructs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class SpecialConstructs : TestBase
11 | {
12 | [Test]
13 | public void MethodOnZeroConstant()
14 | {
15 | Resolve(
16 | "0.ToString()",
17 | new MethodCall(
18 | new Constant(0),
19 | typeof(int).GetMethod("ToString", new Type[0]),
20 | new IExpression[0]
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void MethodOnZerosConstant()
27 | {
28 | Resolve(
29 | "000.ToString()",
30 | new MethodCall(
31 | new Constant(0),
32 | typeof(int).GetMethod("ToString", new Type[0]),
33 | new IExpression[0]
34 | )
35 | );
36 | }
37 |
38 | [Test]
39 | public void MethodOnOneConstant()
40 | {
41 | Resolve(
42 | "1.ToString()",
43 | new MethodCall(
44 | new Constant(1),
45 | typeof(int).GetMethod("ToString", new Type[0]),
46 | new IExpression[0]
47 | )
48 | );
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/ExpressionTests/SpecialConstructs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class SpecialConstructs : TestBase
11 | {
12 | [Test]
13 | public void MethodOnZeroConstant()
14 | {
15 | Resolve(
16 | "0.ToString()",
17 | new MethodCall(
18 | new Constant(0),
19 | typeof(int).GetMethod("ToString", new Type[0]),
20 | new IExpression[0]
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void MethodOnZerosConstant()
27 | {
28 | Resolve(
29 | "000.ToString()",
30 | new MethodCall(
31 | new Constant(0),
32 | typeof(int).GetMethod("ToString", new Type[0]),
33 | new IExpression[0]
34 | )
35 | );
36 | }
37 |
38 | [Test]
39 | public void MethodOnOneConstant()
40 | {
41 | Resolve(
42 | "1.ToString()",
43 | new MethodCall(
44 | new Constant(1),
45 | typeof(int).GetMethod("ToString", new Type[0]),
46 | new IExpression[0]
47 | )
48 | );
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/SpecialConstructs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class SpecialConstructs : TestBase
11 | {
12 | [Test]
13 | public void MethodOnZeroConstant()
14 | {
15 | Resolve(
16 | "0.ToString()",
17 | new MethodCall(
18 | new Constant(0),
19 | typeof(int).GetMethod("ToString", new Type[0]),
20 | new IExpression[0]
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void MethodOnZerosConstant()
27 | {
28 | Resolve(
29 | "000.ToString()",
30 | new MethodCall(
31 | new Constant(0),
32 | typeof(int).GetMethod("ToString", new Type[0]),
33 | new IExpression[0]
34 | )
35 | );
36 | }
37 |
38 | [Test]
39 | public void MethodOnOneConstant()
40 | {
41 | Resolve(
42 | "1.ToString()",
43 | new MethodCall(
44 | new Constant(1),
45 | typeof(int).GetMethod("ToString", new Type[0]),
46 | new IExpression[0]
47 | )
48 | );
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/LICENSE.txt:
--------------------------------------------------------------------------------
1 | [The "BSD license"]
2 | Copyright (c) 2011 Terence Parr
3 | C# Port (c) 2011 Sam Harwell, Tunnel Vision Laboratories, LLC
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 |
10 | 1. Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | 2. Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | 3. The name of the author may not be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/BulkTests/TestScripts/IndividualTests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | = 360 AND 402 <= 361))) OR (((402 >= 369 AND 402 <= 369))) OR (((402 >= 490 AND 402 <= 490))) OR (((402 >= 499 AND 402 <= 499)))) AND (((("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564"))))) OR (((402 >= 360 AND 402 <= 361) OR (402 >= 369 AND 402 <= 369) OR (402 >= 490 AND 402 <= 490) OR (402 >= 499 AND 402 <= 499)) AND (("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564")))]]>
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/BulkTests/TestScripts/IndividualTests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | = 360 AND 402 <= 361))) OR (((402 >= 369 AND 402 <= 369))) OR (((402 >= 490 AND 402 <= 490))) OR (((402 >= 499 AND 402 <= 499)))) AND (((("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564"))))) OR (((402 >= 360 AND 402 <= 361) OR (402 >= 369 AND 402 <= 369) OR (402 >= 490 AND 402 <= 490) OR (402 >= 499 AND 402 <= 499)) AND (("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564")))]]>
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/BulkTests/TestScripts/IndividualTests.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | = 360 AND 402 <= 361))) OR (((402 >= 369 AND 402 <= 369))) OR (((402 >= 490 AND 402 <= 490))) OR (((402 >= 499 AND 402 <= 499)))) AND (((("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564"))))) OR (((402 >= 360 AND 402 <= 361) OR (402 >= 369 AND 402 <= 369) OR (402 >= 490 AND 402 <= 490) OR (402 >= 499 AND 402 <= 499)) AND (("76856" = "47562" OR "76830" = "47562") OR ("76856" = "47563" OR "76830" = "47563") OR ("76856" = "47564" OR "76830" = "47564")))]]>
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Expressions/IBoundExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Represents a bound expression.
9 | ///
10 | public interface IBoundExpression
11 | {
12 | ///
13 | /// Invokes the expression.
14 | ///
15 | /// The result of the expression.
16 | object Invoke();
17 |
18 | ///
19 | /// Invokes the expression.
20 | ///
21 | /// The execution context used to
22 | /// execute the expression.
23 | /// The result of the expression.
24 | object Invoke(IExecutionContext executionContext);
25 | }
26 |
27 | ///
28 | /// Represents a bound expression.
29 | ///
30 | /// The type of the result of the expression.
31 | public interface IBoundExpression : IBoundExpression
32 | {
33 | ///
34 | /// Invokes the expression.
35 | ///
36 | /// The result of the expression.
37 | new T Invoke();
38 |
39 | ///
40 | /// Invokes the expression.
41 | ///
42 | /// The execution context used to
43 | /// execute the expression.
44 | /// The result of the expression.
45 | new T Invoke(IExecutionContext executionContext);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Expressions/Expressions/BinaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Ast;
5 |
6 | namespace Expressions.Expressions
7 | {
8 | internal class BinaryExpression : IExpression
9 | {
10 | public IExpression Left { get; private set; }
11 |
12 | public IExpression Right { get; private set; }
13 |
14 | public ExpressionType ExpressionType { get; private set; }
15 |
16 | public Type Type { get; private set; }
17 |
18 | public Type CommonType { get; private set; }
19 |
20 | public BinaryExpression(IExpression left, IExpression right, ExpressionType expressionType, Type type)
21 | : this(left, right, expressionType, type, type)
22 | {
23 | }
24 |
25 | public BinaryExpression(IExpression left, IExpression right, ExpressionType expressionType, Type type, Type commonType)
26 | {
27 | Require.NotNull(left, "left");
28 | Require.NotNull(right, "right");
29 | Require.NotNull(type, "type");
30 | Require.NotNull(commonType, "commonType");
31 |
32 | Left = left;
33 | Right = right;
34 | ExpressionType = expressionType;
35 | Type = type;
36 | CommonType = commonType;
37 | }
38 |
39 | public void Accept(IExpressionVisitor visitor)
40 | {
41 | visitor.BinaryExpression(this);
42 | }
43 |
44 | public T Accept(IExpressionVisitor visitor)
45 | {
46 | return visitor.BinaryExpression(this);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/TestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | internal abstract class TestBase
9 | {
10 | protected void Resolve(string expression)
11 | {
12 | Resolve(null, expression);
13 | }
14 |
15 | protected void Resolve(ExpressionContext expressionContext, string expression)
16 | {
17 | Resolve(expressionContext, expression, null);
18 | }
19 |
20 | protected void Resolve(string expression, object expected)
21 | {
22 | Resolve(expression, expected, null);
23 | }
24 |
25 | protected void Resolve(string expression, object expected, BoundExpressionOptions options)
26 | {
27 | Resolve(null, expression, expected, options);
28 | }
29 |
30 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected)
31 | {
32 | Resolve(expressionContext, expression, expected, null);
33 | }
34 |
35 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected, BoundExpressionOptions options)
36 | {
37 | if (expression == null)
38 | throw new ArgumentNullException("expression");
39 |
40 | object actual = new DynamicExpression(
41 | expression,
42 | ExpressionLanguage.Flee
43 | ).Invoke(
44 | expressionContext ?? new ExpressionContext(),
45 | options
46 | );
47 |
48 | Assert.AreEqual(expected, actual);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/TestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | internal abstract class TestBase
9 | {
10 | protected void Resolve(string expression)
11 | {
12 | Resolve(null, expression);
13 | }
14 |
15 | protected void Resolve(ExpressionContext expressionContext, string expression)
16 | {
17 | Resolve(expressionContext, expression, null);
18 | }
19 |
20 | protected void Resolve(string expression, object expected)
21 | {
22 | Resolve(expression, expected, null);
23 | }
24 |
25 | protected void Resolve(string expression, object expected, BoundExpressionOptions options)
26 | {
27 | Resolve(null, expression, expected, options);
28 | }
29 |
30 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected)
31 | {
32 | Resolve(expressionContext, expression, expected, null);
33 | }
34 |
35 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected, BoundExpressionOptions options)
36 | {
37 | if (expression == null)
38 | throw new ArgumentNullException("expression");
39 |
40 | object actual = new DynamicExpression(
41 | expression,
42 | ExpressionLanguage.Csharp
43 | ).Invoke(
44 | expressionContext ?? new ExpressionContext(),
45 | options
46 | );
47 |
48 | Assert.AreEqual(expected, actual);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Expressions.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Expressions", "Expressions\Expressions.csproj", "{CC920AB6-D51E-4227-AFAD-112C358B0FC8}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Expressions.Test", "Expressions.Test\Expressions.Test.csproj", "{0BD2D942-77DA-4C6B-84C3-F33174E10BFF}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{EDB2E9A9-F60D-4B21-8671-1977D34899D4}"
9 | ProjectSection(SolutionItems) = preProject
10 | License.txt = License.txt
11 | Merge.bat = Merge.bat
12 | README.markdown = README.markdown
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Release|Any CPU = Release|Any CPU
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {CC920AB6-D51E-4227-AFAD-112C358B0FC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {CC920AB6-D51E-4227-AFAD-112C358B0FC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {CC920AB6-D51E-4227-AFAD-112C358B0FC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {CC920AB6-D51E-4227-AFAD-112C358B0FC8}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {0BD2D942-77DA-4C6B-84C3-F33174E10BFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {0BD2D942-77DA-4C6B-84C3-F33174E10BFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {0BD2D942-77DA-4C6B-84C3-F33174E10BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {0BD2D942-77DA-4C6B-84C3-F33174E10BFF}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/TestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | internal abstract class TestBase
9 | {
10 | protected void Resolve(string expression)
11 | {
12 | Resolve(null, expression);
13 | }
14 |
15 | protected void Resolve(ExpressionContext expressionContext, string expression)
16 | {
17 | Resolve(expressionContext, expression, null);
18 | }
19 |
20 | protected void Resolve(string expression, object expected)
21 | {
22 | Resolve(expression, expected, null);
23 | }
24 |
25 | protected void Resolve(string expression, object expected, BoundExpressionOptions options)
26 | {
27 | Resolve(null, expression, expected, options);
28 | }
29 |
30 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected)
31 | {
32 | Resolve(expressionContext, expression, expected, null);
33 | }
34 |
35 | protected void Resolve(ExpressionContext expressionContext, string expression, object expected, BoundExpressionOptions options)
36 | {
37 | if (expression == null)
38 | throw new ArgumentNullException("expression");
39 |
40 | object actual = new DynamicExpression(
41 | expression,
42 | ExpressionLanguage.VisualBasic
43 | ).Invoke(
44 | expressionContext ?? new ExpressionContext(),
45 | options
46 | );
47 |
48 | Assert.AreEqual(expected, actual);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Expressions/Ast/AstNodeCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Text;
5 |
6 | namespace Expressions.Ast
7 | {
8 | internal class AstNodeCollection : IAstNode
9 | {
10 | private readonly IAstNode[] _nodes;
11 |
12 | public IList Nodes { get; private set; }
13 |
14 | public AstNodeCollection(IAstNode node)
15 | {
16 | Require.NotNull(node, "node");
17 |
18 | _nodes = new[] { node };
19 |
20 | Nodes = new ReadOnlyCollection(_nodes);
21 | }
22 |
23 | public AstNodeCollection(AstNodeCollection other, IAstNode node)
24 | {
25 | Require.NotNull(other, "other");
26 | Require.NotNull(node, "node");
27 |
28 | _nodes = new IAstNode[other._nodes.Length + 1];
29 |
30 | Array.Copy(other._nodes, _nodes, other._nodes.Length);
31 |
32 | _nodes[_nodes.Length - 1] = node;
33 |
34 | Nodes = new ReadOnlyCollection(_nodes);
35 | }
36 |
37 | public AstNodeCollection(IList nodes)
38 | {
39 | Nodes = new ReadOnlyCollection(nodes);
40 | }
41 |
42 | public T Accept(IAstVisitor visitor)
43 | {
44 | throw new NotSupportedException();
45 | }
46 |
47 | public override string ToString()
48 | {
49 | var sb = new StringBuilder();
50 |
51 | sb.Append('(');
52 |
53 | for (int i = 0; i < _nodes.Length; i++)
54 | {
55 | if (i > 0)
56 | sb.Append(", ");
57 |
58 | sb.Append(_nodes[i]);
59 | }
60 |
61 | sb.Append(')');
62 |
63 | return sb.ToString();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/ExpressionTests/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class UnaryExpressions : TestBase
11 | {
12 | [Test]
13 | public void UnaryPlus()
14 | {
15 | Resolve(
16 | "+1",
17 | new UnaryExpression(
18 | new Constant(1),
19 | typeof(int),
20 | ExpressionType.Plus
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void UnaryMinus()
27 | {
28 | Resolve(
29 | "-1",
30 | new Constant(-1)
31 | );
32 | }
33 |
34 | [Test]
35 | [ExpectedException]
36 | public void IllegalUnaryPlus()
37 | {
38 | Resolve(
39 | "+\"\""
40 | );
41 | }
42 |
43 | [Test]
44 | [ExpectedException]
45 | public void IllegalUnaryMinus()
46 | {
47 | Resolve(
48 | "-\"\""
49 | );
50 | }
51 |
52 | [Test]
53 | public void UnaryNot()
54 | {
55 | Resolve(
56 | "not true",
57 | new UnaryExpression(
58 | new Constant(true),
59 | typeof(bool),
60 | ExpressionType.Not
61 | )
62 | );
63 | }
64 |
65 | [Test]
66 | [ExpectedException]
67 | public void IllegalUnaryNot()
68 | {
69 | Resolve(
70 | "not \"\""
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/ExpressionTests/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class UnaryExpressions : TestBase
11 | {
12 | [Test]
13 | public void UnaryPlus()
14 | {
15 | Resolve(
16 | "+1",
17 | new UnaryExpression(
18 | new Constant(1),
19 | typeof(int),
20 | ExpressionType.Plus
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void UnaryMinus()
27 | {
28 | Resolve(
29 | "-1",
30 | new Constant(-1)
31 | );
32 | }
33 |
34 | [Test]
35 | [ExpectedException]
36 | public void IllegalUnaryPlus()
37 | {
38 | Resolve(
39 | "+\"\""
40 | );
41 | }
42 |
43 | [Test]
44 | [ExpectedException]
45 | public void IllegalUnaryMinus()
46 | {
47 | Resolve(
48 | "-\"\""
49 | );
50 | }
51 |
52 | [Test]
53 | public void UnaryNot()
54 | {
55 | Resolve(
56 | "!true",
57 | new UnaryExpression(
58 | new Constant(true),
59 | typeof(bool),
60 | ExpressionType.LogicalNot
61 | )
62 | );
63 | }
64 |
65 | [Test]
66 | [ExpectedException]
67 | public void IllegalUnaryNot()
68 | {
69 | Resolve(
70 | "!\"\""
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/UnaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class UnaryExpressions : TestBase
11 | {
12 | [Test]
13 | public void UnaryPlus()
14 | {
15 | Resolve(
16 | "+1",
17 | new UnaryExpression(
18 | new Constant(1),
19 | typeof(int),
20 | ExpressionType.Plus
21 | )
22 | );
23 | }
24 |
25 | [Test]
26 | public void UnaryMinus()
27 | {
28 | Resolve(
29 | "-1",
30 | new Constant(-1)
31 | );
32 | }
33 |
34 | [Test]
35 | [ExpectedException]
36 | public void IllegalUnaryPlus()
37 | {
38 | Resolve(
39 | "+\"\""
40 | );
41 | }
42 |
43 | [Test]
44 | [ExpectedException]
45 | public void IllegalUnaryMinus()
46 | {
47 | Resolve(
48 | "-\"\""
49 | );
50 | }
51 |
52 | [Test]
53 | public void UnaryNot()
54 | {
55 | Resolve(
56 | "not true",
57 | new UnaryExpression(
58 | new Constant(true),
59 | typeof(bool),
60 | ExpressionType.Not
61 | )
62 | );
63 | }
64 |
65 | [Test]
66 | [ExpectedException]
67 | public void IllegalUnaryNot()
68 | {
69 | Resolve(
70 | "not \"\""
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Expressions/ExpressionsExceptionType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | ///
8 | /// Type of an ExpressionsException.
9 | ///
10 | public enum ExpressionsExceptionType
11 | {
12 | ///
13 | /// Exception is because of a syntax error.
14 | ///
15 | SyntaxError,
16 | ///
17 | /// Exception is because of a constant overflow during parsing.
18 | ///
19 | ConstantOverflow,
20 | ///
21 | /// Exception is because of a type mismatch in a method call.
22 | ///
23 | TypeMismatch,
24 | ///
25 | /// Exception is because of an undefined name.
26 | ///
27 | UndefinedName,
28 | ///
29 | /// Exception is because a function was used that did not have a return value.
30 | ///
31 | FunctionHasNoReturnValue,
32 | ///
33 | /// Exception is because an invalid cast was made.
34 | ///
35 | InvalidExplicitCast,
36 | ///
37 | /// Exception is because of a method overload could not be matched unambiguously.
38 | ///
39 | AmbiguousMatch,
40 | ///
41 | /// Exception is because of access is denied.
42 | ///
43 | AccessDenied,
44 | ///
45 | /// Exception is because of an invalid format.
46 | ///
47 | InvalidFormat,
48 | ///
49 | /// Exception is because a method could not be resolved.
50 | ///
51 | UnresolvedMethod,
52 | ///
53 | /// Exception is because of an undefined invalid operation.
54 | ///
55 | InvalidOperation
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Expressions/ConstantParsingVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 | using Expressions.Ast;
6 |
7 | namespace Expressions
8 | {
9 | internal class ConstantParsingVisitor : AstVisitor
10 | {
11 | public override IAstNode UnaryExpression(UnaryExpression unaryExpression)
12 | {
13 | if (unaryExpression.Type == ExpressionType.Minus)
14 | {
15 | var constant = unaryExpression.Operand as Constant;
16 |
17 | if (constant != null)
18 | {
19 | var unparsedNumber = constant.Value as UnparsedNumber;
20 |
21 | // We do not parse hex in this manner because int.Parse
22 | // doesn't allow hex and sign to be combined.
23 |
24 | if (
25 | unparsedNumber != null &&
26 | TypeUtil.IsConvertible(unparsedNumber.Type) &&
27 | (unparsedNumber.NumberStyles & NumberStyles.AllowHexSpecifier) == 0
28 | ) {
29 | // Actually parse the constant including the minus sign.
30 |
31 | unparsedNumber = new UnparsedNumber("-" + unparsedNumber.Value, unparsedNumber.Type, unparsedNumber.NumberStyles | NumberStyles.AllowLeadingSign);
32 |
33 | return new Constant(
34 | unparsedNumber.Parse()
35 | );
36 | }
37 | }
38 | }
39 |
40 | return base.UnaryExpression(unaryExpression);
41 | }
42 |
43 | public override IAstNode Constant(Constant constant)
44 | {
45 | var unparsedNumber = constant.Value as UnparsedNumber;
46 |
47 | if (unparsedNumber != null)
48 | return new Constant(unparsedNumber.Parse());
49 |
50 | return base.Constant(constant);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Tool/Templates/messages/formats/gnu.stg:
--------------------------------------------------------------------------------
1 | /*
2 | [The "BSD license"]
3 | Copyright (c) 2006 Kay Roepke
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | 3. The name of the author may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 | /*
29 | New style messages. This file contains the actual layout of the messages emitted by ANTLR.
30 | The text itself is coming out of the languages/*stg files, according to the chosen locale.
31 | This file contains the format that mimicks GCC output.
32 | */
33 |
34 | group gnu;
35 |
36 | location(file, line, column) ::= "::"
37 |
38 | message(id, text) ::= " ()"
39 |
40 | report(location, message, type) ::= " : "
41 |
42 | wantsSingleLineMessage() ::= "true"
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Tool/Templates/messages/formats/antlr.stg:
--------------------------------------------------------------------------------
1 | /*
2 | [The "BSD license"]
3 | Copyright (c) 2006 Kay Roepke
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | 3. The name of the author may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 | /*
29 | New style messages. This file contains the actual layout of the messages emitted by ANTLR.
30 | The text itself is coming out of the languages/*stg files, according to the chosen locale.
31 | This file contains the default format ANTLR uses.
32 | */
33 |
34 | group antlr;
35 |
36 | location(file, line, column) ::= ":::"
37 |
38 | message(id, text) ::= "() "
39 |
40 | report(location, message, type) ::= "(): "
41 |
42 | wantsSingleLineMessage() ::= "false"
--------------------------------------------------------------------------------
/Expressions/CompilerUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Expressions
7 | {
8 | internal static class CompilerUtil
9 | {
10 | public static bool InEnumerable(object arg, IEnumerable set)
11 | {
12 | Require.NotNull(set, "set");
13 |
14 | var dictionary = set as IDictionary;
15 |
16 | if (dictionary != null)
17 | return dictionary.Contains(arg);
18 |
19 | Type argType = null;
20 |
21 | if (arg != null)
22 | argType = arg.GetType();
23 |
24 | foreach (var item in set)
25 | {
26 | if (arg == null)
27 | {
28 | if (item == null)
29 | return true;
30 | }
31 | else if (item != null)
32 | {
33 | var targetType = item.GetType();
34 |
35 | if (argType != targetType)
36 | {
37 | if (TypeUtil.CanCastImplicitely(argType, targetType, false))
38 | {
39 | if (Equals(TypeUtil.CastImplicitely(arg, targetType), item))
40 | return true;
41 | }
42 | else if (TypeUtil.CanCastImplicitely(targetType, argType, false))
43 | {
44 | if (Equals(arg, TypeUtil.CastImplicitely(item, argType)))
45 | return true;
46 | }
47 | }
48 | else
49 | {
50 | if (Equals(arg, item))
51 | return true;
52 | }
53 | }
54 | }
55 |
56 | return false;
57 | }
58 |
59 | public static bool InSet(object arg, params object[] set)
60 | {
61 | return InEnumerable(arg, set);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Tool/Templates/messages/formats/vs2005.stg:
--------------------------------------------------------------------------------
1 | /*
2 | [The "BSD license"]
3 | Copyright (c) 2006 Kay Roepke
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | 3. The name of the author may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 | /*
29 | New style messages. This file contains the actual layout of the messages emitted by ANTLR.
30 | The text itself is coming out of the languages/*stg files, according to the chosen locale.
31 | This file contains the default format ANTLR uses.
32 | */
33 |
34 | group antlr;
35 |
36 | location(file, line, column) ::= "(,)"
37 |
38 | message(id, text) ::= "error : "
39 |
40 | report(location, message, type) ::= " : : "
41 |
42 | wantsSingleLineMessage() ::= "true"
43 |
--------------------------------------------------------------------------------
/Expressions/ObjectUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Expressions
6 | {
7 | internal static class ObjectUtil
8 | {
9 | public static int CombineHashCodes(int hash1, int hash2)
10 | {
11 | return (((hash1 << 5) + hash1) ^ hash2);
12 | }
13 |
14 | public static int CombineHashCodes(int hash1, int hash2, int hash3)
15 | {
16 | return CombineHashCodes(CombineHashCodes(hash1, hash2), hash3);
17 | }
18 |
19 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4)
20 | {
21 | return CombineHashCodes(CombineHashCodes(hash1, hash2), CombineHashCodes(hash3, hash4));
22 | }
23 |
24 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4, int hash5)
25 | {
26 | return CombineHashCodes(CombineHashCodes(hash1, hash2, hash3, hash4), hash5);
27 | }
28 |
29 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4, int hash5, int hash6)
30 | {
31 | return CombineHashCodes(CombineHashCodes(hash1, hash2, hash3, hash4), CombineHashCodes(hash5, hash6));
32 | }
33 |
34 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4, int hash5, int hash6, int hash7)
35 | {
36 | return CombineHashCodes(CombineHashCodes(hash1, hash2, hash3, hash4), CombineHashCodes(hash5, hash6, hash7));
37 | }
38 |
39 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4, int hash5, int hash6, int hash7, int hash8)
40 | {
41 | return CombineHashCodes(CombineHashCodes(hash1, hash2, hash3, hash4), CombineHashCodes(hash5, hash6, hash7, hash8));
42 | }
43 |
44 | public static int CombineHashCodes(int hash1, int hash2, int hash3, int hash4, int hash5, int hash6, int hash7, int hash8, int hash9)
45 | {
46 | return CombineHashCodes(CombineHashCodes(hash1, hash2, hash3, hash4), CombineHashCodes(CombineHashCodes(hash5, hash6, hash7, hash8), hash9));
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/ExpressionTests/Conversions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Conversions : TestBase
11 | {
12 | [Test]
13 | public void StringConcat()
14 | {
15 | Resolve(
16 | "\"a\" + \"a\"",
17 | new MethodCall(
18 | new TypeAccess(typeof(string)),
19 | typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }),
20 | new IExpression[]
21 | {
22 | new Constant("a"),
23 | new Constant("a")
24 | }
25 | )
26 | );
27 | }
28 |
29 | [Test]
30 | public void MultipleConcat()
31 | {
32 | Resolve(
33 | "\"a\" + \"a\" + \"a\" + \"a\" + \"a\" + \"a\"",
34 | new MethodCall(
35 | new TypeAccess(typeof(string)),
36 | typeof(string).GetMethod("Concat", new[] { typeof(string[]) }),
37 | new IExpression[]
38 | {
39 | new Constant("a"),
40 | new Constant("a"),
41 | new Constant("a"),
42 | new Constant("a"),
43 | new Constant("a"),
44 | new Constant("a")
45 | }
46 | )
47 | );
48 | }
49 |
50 | [Test]
51 | public void ConcatWithBoxing()
52 | {
53 | Resolve(
54 | "\"a\" + 1",
55 | new MethodCall(
56 | new TypeAccess(typeof(string)),
57 | typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
58 | new IExpression[]
59 | {
60 | new Constant("a"),
61 | new Constant(1)
62 | }
63 | )
64 | );
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Codegen/Templates/C/ASTDbg.stg:
--------------------------------------------------------------------------------
1 | /*
2 | [The "BSD license"]
3 | Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
4 | http://www.temporal-wave.com
5 | http://www.linkedin.com/in/jimidle
6 |
7 | All rights reserved.
8 |
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions
11 | are met:
12 | 1. Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | 2. Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in the
16 | documentation and/or other materials provided with the distribution.
17 | 3. The name of the author may not be used to endorse or promote products
18 | derived from this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | /** Template overrides to add debugging to AST stuff. Dynamic inheritance
33 | * hierarchy is set up as ASTDbg : AST : Dbg : Java by code generator.
34 | */
35 | parserMembers() ::= <<
36 | protected DebugTreeAdaptor adaptor =
37 | new DebugTreeAdaptor(null,new CommonTreeAdaptor());
38 | public void setTreeAdaptor(TreeAdaptor adaptor) {
39 | this.adaptor = new DebugTreeAdaptor(dbg,adaptor);
40 | }
41 | public TreeAdaptor getTreeAdaptor() {
42 | return adaptor;
43 | }<\n>
44 | >>
45 |
46 | parserCtorBody() ::= <<
47 | >>
48 |
49 | createListenerAndHandshake() ::= <<
50 |
51 | >>
52 |
53 | ctorForPredefinedListener() ::= <<
54 | >>
55 |
56 | @rewriteElement.pregen() ::= ""
57 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/Caching.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class Caching : TestBase
11 | {
12 | [Test]
13 | public void SameExpressionReuses()
14 | {
15 | Assert.AreSame(
16 | new DynamicExpression("1", ExpressionLanguage.Flee).Cached,
17 | new DynamicExpression("1", ExpressionLanguage.Flee).Cached
18 | );
19 | }
20 |
21 | [Test]
22 | public void SameTypes()
23 | {
24 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.Flee);
25 |
26 | var context = new ExpressionContext();
27 |
28 | context.Variables.Add(new Variable("Variable") { Value = 1 });
29 |
30 | Assert.AreSame(
31 | dynamicExpression.Bind(context),
32 | dynamicExpression.Bind(context)
33 | );
34 | }
35 |
36 | [Test]
37 | public void DifferentTypesDifferentCache()
38 | {
39 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.Flee);
40 |
41 | var context1 = new ExpressionContext();
42 |
43 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
44 |
45 | var context2 = new ExpressionContext();
46 |
47 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
48 |
49 | Assert.AreNotSame(
50 | dynamicExpression.Bind(context1),
51 | dynamicExpression.Bind(context2)
52 | );
53 | }
54 |
55 | [Test]
56 | public void UnusedDifferentTypesAreSame()
57 | {
58 | var dynamicExpression = new DynamicExpression("1", ExpressionLanguage.Flee);
59 |
60 | var context1 = new ExpressionContext();
61 |
62 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
63 |
64 | var context2 = new ExpressionContext();
65 |
66 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
67 |
68 | Assert.AreSame(
69 | dynamicExpression.Bind(context1),
70 | dynamicExpression.Bind(context2)
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/Caching.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class Caching : TestBase
11 | {
12 | [Test]
13 | public void SameExpressionReuses()
14 | {
15 | Assert.AreSame(
16 | new DynamicExpression("1", ExpressionLanguage.Csharp).Cached,
17 | new DynamicExpression("1", ExpressionLanguage.Csharp).Cached
18 | );
19 | }
20 |
21 | [Test]
22 | public void SameTypes()
23 | {
24 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.Csharp);
25 |
26 | var context = new ExpressionContext();
27 |
28 | context.Variables.Add(new Variable("Variable") { Value = 1 });
29 |
30 | Assert.AreSame(
31 | dynamicExpression.Bind(context),
32 | dynamicExpression.Bind(context)
33 | );
34 | }
35 |
36 | [Test]
37 | public void DifferentTypesDifferentCache()
38 | {
39 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.Csharp);
40 |
41 | var context1 = new ExpressionContext();
42 |
43 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
44 |
45 | var context2 = new ExpressionContext();
46 |
47 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
48 |
49 | Assert.AreNotSame(
50 | dynamicExpression.Bind(context1),
51 | dynamicExpression.Bind(context2)
52 | );
53 | }
54 |
55 | [Test]
56 | public void UnusedDifferentTypesAreSame()
57 | {
58 | var dynamicExpression = new DynamicExpression("1", ExpressionLanguage.Csharp);
59 |
60 | var context1 = new ExpressionContext();
61 |
62 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
63 |
64 | var context2 = new ExpressionContext();
65 |
66 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
67 |
68 | Assert.AreSame(
69 | dynamicExpression.Bind(context1),
70 | dynamicExpression.Bind(context2)
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/EmitIssues.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Test.FleeLanguage.BulkTests;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class EmitIssues : TestBase
11 | {
12 | [Test]
13 | public void LongBranch()
14 | {
15 | Resolve("true or (1.0+2.0+3.0+4.0+5.0+6.0+7.0+8.0+9.0+10.0+11.0+12.0+13.0+14.0+15.0 > 10.0)", true);
16 | }
17 |
18 | [Test]
19 | public void SpecialLoadOfStructFields()
20 | {
21 | Resolve(
22 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }),
23 | "Mouse.shareddt.year",
24 | 1
25 | );
26 | }
27 |
28 | [Test]
29 | public void ReadOnlyStaticAccess()
30 | {
31 | Resolve(
32 | new ExpressionContext(new[] { new Import("DateTime", typeof(DateTime)) }),
33 | "DateTime.MinValue.Year",
34 | DateTime.MinValue.Year
35 | );
36 | }
37 |
38 | [Test]
39 | public void ReadOnlyInstanceAccess()
40 | {
41 | Resolve(
42 | new ExpressionContext(null, new Owner()),
43 | "MinValue.Year",
44 | DateTime.MinValue.Year
45 | );
46 | }
47 |
48 | [Test]
49 | public void ReadOnlyFieldAsReturn()
50 | {
51 | Resolve(
52 | new ExpressionContext(new[] { new Import("string", typeof(string)) }),
53 | "string.empty",
54 | String.Empty
55 | );
56 | }
57 |
58 | [Test]
59 | public void Issue()
60 | {
61 | Resolve(
62 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }, new ExpressionOwner()),
63 | "DateTimeA.GetType().Name",
64 | "DateTime",
65 | new BoundExpressionOptions
66 | {
67 | AllowPrivateAccess = true
68 | }
69 | );
70 | }
71 |
72 | public class Owner
73 | {
74 | public readonly DateTime MinValue;
75 |
76 | public Owner()
77 | {
78 | MinValue = DateTime.MinValue;
79 | }
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/EmitIssues.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Test.CsharpLanguage.BulkTests;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.CsharpLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class EmitIssues : TestBase
11 | {
12 | [Test]
13 | public void LongBranch()
14 | {
15 | Resolve("true || (1.0+2.0+3.0+4.0+5.0+6.0+7.0+8.0+9.0+10.0+11.0+12.0+13.0+14.0+15.0 > 10.0)", true);
16 | }
17 |
18 | [Test]
19 | public void SpecialLoadOfStructFields()
20 | {
21 | Resolve(
22 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }),
23 | "Mouse.SharedDT.Year",
24 | 1
25 | );
26 | }
27 |
28 | [Test]
29 | public void ReadOnlyStaticAccess()
30 | {
31 | Resolve(
32 | new ExpressionContext(new[] { new Import("DateTime", typeof(DateTime)) }),
33 | "DateTime.MinValue.Year",
34 | DateTime.MinValue.Year
35 | );
36 | }
37 |
38 | [Test]
39 | public void ReadOnlyInstanceAccess()
40 | {
41 | Resolve(
42 | new ExpressionContext(null, new Owner()),
43 | "MinValue.Year",
44 | DateTime.MinValue.Year
45 | );
46 | }
47 |
48 | [Test]
49 | public void ReadOnlyFieldAsReturn()
50 | {
51 | Resolve(
52 | new ExpressionContext(new[] { new Import("string", typeof(string)) }),
53 | "string.Empty",
54 | String.Empty
55 | );
56 | }
57 |
58 | [Test]
59 | public void Issue()
60 | {
61 | Resolve(
62 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }, new ExpressionOwner()),
63 | "DateTimeA.GetType().Name",
64 | "DateTime",
65 | new BoundExpressionOptions
66 | {
67 | AllowPrivateAccess = true
68 | }
69 | );
70 | }
71 |
72 | public class Owner
73 | {
74 | public readonly DateTime MinValue;
75 |
76 | public Owner()
77 | {
78 | MinValue = DateTime.MinValue;
79 | }
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/Caching.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Text;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class Caching : TestBase
11 | {
12 | [Test]
13 | public void SameExpressionReuses()
14 | {
15 | Assert.AreSame(
16 | new DynamicExpression("1", ExpressionLanguage.VisualBasic).Cached,
17 | new DynamicExpression("1", ExpressionLanguage.VisualBasic).Cached
18 | );
19 | }
20 |
21 | [Test]
22 | public void SameTypes()
23 | {
24 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.VisualBasic);
25 |
26 | var context = new ExpressionContext();
27 |
28 | context.Variables.Add(new Variable("Variable") { Value = 1 });
29 |
30 | Assert.AreSame(
31 | dynamicExpression.Bind(context),
32 | dynamicExpression.Bind(context)
33 | );
34 | }
35 |
36 | [Test]
37 | public void DifferentTypesDifferentCache()
38 | {
39 | var dynamicExpression = new DynamicExpression("Variable", ExpressionLanguage.VisualBasic);
40 |
41 | var context1 = new ExpressionContext();
42 |
43 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
44 |
45 | var context2 = new ExpressionContext();
46 |
47 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
48 |
49 | Assert.AreNotSame(
50 | dynamicExpression.Bind(context1),
51 | dynamicExpression.Bind(context2)
52 | );
53 | }
54 |
55 | [Test]
56 | public void UnusedDifferentTypesAreSame()
57 | {
58 | var dynamicExpression = new DynamicExpression("1", ExpressionLanguage.VisualBasic);
59 |
60 | var context1 = new ExpressionContext();
61 |
62 | context1.Variables.Add(new Variable("Variable") { Value = 1 });
63 |
64 | var context2 = new ExpressionContext();
65 |
66 | context2.Variables.Add(new Variable("Variable") { Value = 1d });
67 |
68 | Assert.AreSame(
69 | dynamicExpression.Bind(context1),
70 | dynamicExpression.Bind(context2)
71 | );
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Codegen/Templates/Python/ASTDbg.stg:
--------------------------------------------------------------------------------
1 | /*
2 | [The "BSD license"]
3 | Copyright (c) 2005-2009 Terence Parr
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions
8 | are met:
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | 3. The name of the author may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | /** Template overrides to add debugging to AST stuff. Dynamic inheritance
30 | * hierarchy is set up as ASTDbg : AST : Dbg : Python by code generator.
31 | */
32 | group ASTDbg;
33 |
34 | astAccessor() ::= <<
35 | def setTreeAdaptor(self, adaptor):
36 |
37 | self._adaptor = DebugTreeAdaptor(self.dbg, adaptor)
38 |
39 | self._adaptor = adaptor # delegator sends dbg adaptor
40 |
41 | .setTreeAdaptor(self._adaptor)}>
42 |
43 | def getTreeAdaptor(self):
44 | return self._adaptor
45 |
46 | adaptor = property(getTreeAdaptor, setTreeAdaptor)<\n>
47 | >>
48 |
49 | createListenerAndHandshake() ::= <<
50 | proxy = DebugEventSocketProxy(self, adaptor=self.input.getTreeAdaptor()self._adaptor,
51 | debug=debug_socket, port=port)
52 | self.setDebugListener(proxy)
53 | self.adaptor.setDebugListener(proxy)
54 | self.input.setDebugListener(proxy)
55 | #self.set(Debug(self.input, proxy))
56 | proxy.handshake()
57 | >>
58 |
59 | @rewriteElement.pregen() ::= "self._dbg.location(, )"
60 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/EmitIssues.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Test.VisualBasicLanguage.BulkTests;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.Compilation
8 | {
9 | [TestFixture]
10 | internal class EmitIssues : TestBase
11 | {
12 | [Test]
13 | public void LongBranch()
14 | {
15 | Resolve("true or (1.0+2.0+3.0+4.0+5.0+6.0+7.0+8.0+9.0+10.0+11.0+12.0+13.0+14.0+15.0 > 10.0)", true);
16 | }
17 |
18 | [Test]
19 | public void SpecialLoadOfStructFields()
20 | {
21 | Resolve(
22 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }),
23 | "Mouse.shareddt.year",
24 | 1
25 | );
26 | }
27 |
28 | [Test]
29 | public void ReadOnlyStaticAccess()
30 | {
31 | Resolve(
32 | new ExpressionContext(new[] { new Import("DateTime", typeof(DateTime)) }),
33 | "DateTime.MinValue.Year",
34 | DateTime.MinValue.Year
35 | );
36 | }
37 |
38 | [Test]
39 | public void ReadOnlyInstanceAccess()
40 | {
41 | Resolve(
42 | new ExpressionContext(null, new Owner()),
43 | "MinValue.Year",
44 | DateTime.MinValue.Year
45 | );
46 | }
47 |
48 | [Test]
49 | public void ReadOnlyFieldAsReturn()
50 | {
51 | Resolve(
52 | new ExpressionContext(new[] { new Import("string", typeof(string)) }),
53 | "string.empty",
54 | String.Empty
55 | );
56 | }
57 |
58 | [Test]
59 | public void Issue1()
60 | {
61 | Resolve(
62 | new ExpressionContext(new[] { new Import("Mouse", typeof(Mouse)) }, new ExpressionOwner()),
63 | "DateTimeA.GetType().Name",
64 | "DateTime",
65 | new BoundExpressionOptions
66 | {
67 | AllowPrivateAccess = true
68 | }
69 | );
70 | }
71 |
72 | [Test]
73 | public void Issue2()
74 | {
75 | Resolve(
76 | "(100 < 0) or (not (\"a\" = \"a\"))",
77 | false
78 | );
79 | }
80 |
81 | public class Owner
82 | {
83 | public readonly DateTime MinValue;
84 |
85 | public Owner()
86 | {
87 | MinValue = DateTime.MinValue;
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/Expressions/Require.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 | using JetBrains.Annotations;
6 |
7 | namespace Expressions
8 | {
9 | [DebuggerStepThrough]
10 | internal static class Require
11 | {
12 | [AssertionMethod]
13 | public static void NotNull([AssertionCondition(AssertionConditionType.IS_NOT_NULL)] object param, [InvokerParameterName] string paramName)
14 | {
15 | if (param == null)
16 | throw new ArgumentNullException(paramName);
17 | }
18 |
19 | [AssertionMethod]
20 | public static void NotEmpty([AssertionCondition(AssertionConditionType.IS_NOT_NULL)] string param, [InvokerParameterName] string paramName)
21 | {
22 | if (String.IsNullOrEmpty(param))
23 | throw new ArgumentException("Value cannot be null or empty.", paramName);
24 | }
25 |
26 | [AssertionMethod]
27 | public static void ValidEnum(T param, [InvokerParameterName] string paramName)
28 | {
29 | if (!Enum.IsDefined(typeof(T), param))
30 | throw new ArgumentOutOfRangeException(paramName);
31 | }
32 |
33 | [AssertionMethod]
34 | public static void That([AssertionCondition(AssertionConditionType.IS_TRUE)] bool condition, string error)
35 | {
36 | if (!condition)
37 | throw new ArgumentException(error);
38 | }
39 |
40 | [AssertionMethod]
41 | public static void That([AssertionCondition(AssertionConditionType.IS_TRUE)] bool condition, string error, string paramName)
42 | {
43 | if (!condition)
44 | throw new ArgumentException(error, paramName);
45 | }
46 | }
47 | }
48 |
49 | namespace JetBrains.Annotations
50 | {
51 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
52 | internal sealed class InvokerParameterNameAttribute : Attribute { }
53 |
54 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
55 | internal sealed class AssertionMethodAttribute : Attribute { }
56 |
57 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
58 | internal sealed class AssertionConditionAttribute : Attribute
59 | {
60 | public AssertionConditionAttribute(AssertionConditionType conditionType)
61 | {
62 | ConditionType = conditionType;
63 | }
64 |
65 | public AssertionConditionType ConditionType { get; private set; }
66 | }
67 |
68 | internal enum AssertionConditionType
69 | {
70 | IS_TRUE,
71 | IS_FALSE,
72 | IS_NULL,
73 | IS_NOT_NULL
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/ExpressionTests/Conversions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.FleeLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Conversions : TestBase
11 | {
12 | [Test]
13 | public void StringConcat()
14 | {
15 | Resolve(
16 | "\"a\" + \"a\"",
17 | new MethodCall(
18 | new TypeAccess(typeof(string)),
19 | typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }),
20 | new IExpression[]
21 | {
22 | new Constant("a"),
23 | new Constant("a")
24 | }
25 | )
26 | );
27 | }
28 |
29 | [Test]
30 | public void MultipleConcat()
31 | {
32 | Resolve(
33 | "\"a\" + \"a\" + \"a\" + \"a\" + \"a\" + \"a\"",
34 | new MethodCall(
35 | new TypeAccess(typeof(string)),
36 | typeof(string).GetMethod("Concat", new[] { typeof(string[]) }),
37 | new IExpression[]
38 | {
39 | new Constant("a"),
40 | new Constant("a"),
41 | new Constant("a"),
42 | new Constant("a"),
43 | new Constant("a"),
44 | new Constant("a")
45 | }
46 | )
47 | );
48 | }
49 |
50 | [Test]
51 | public void ConcatWithBoxing()
52 | {
53 | Resolve(
54 | "\"a\" + 1",
55 | new MethodCall(
56 | new TypeAccess(typeof(string)),
57 | typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
58 | new IExpression[]
59 | {
60 | new Constant("a"),
61 | new Constant(1)
62 | }
63 | )
64 | );
65 | }
66 |
67 | [Test]
68 | public void Power()
69 | {
70 | Resolve(
71 | "1 ^ 2",
72 | new MethodCall(
73 | new TypeAccess(typeof(Math)),
74 | typeof(Math).GetMethod("Pow"),
75 | new IExpression[]
76 | {
77 | new Constant(1),
78 | new Constant(2)
79 | }
80 | )
81 | );
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/ExpressionTests/Conversions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Expressions.Expressions;
5 | using NUnit.Framework;
6 |
7 | namespace Expressions.Test.VisualBasicLanguage.ExpressionTests
8 | {
9 | [TestFixture]
10 | internal class Conversions : TestBase
11 | {
12 | [Test]
13 | public void StringConcat()
14 | {
15 | Resolve(
16 | "\"a\" + \"a\"",
17 | new MethodCall(
18 | new TypeAccess(typeof(string)),
19 | typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }),
20 | new IExpression[]
21 | {
22 | new Constant("a"),
23 | new Constant("a")
24 | }
25 | )
26 | );
27 | }
28 |
29 | [Test]
30 | public void MultipleConcat()
31 | {
32 | Resolve(
33 | "\"a\" + \"a\" + \"a\" + \"a\" + \"a\" + \"a\"",
34 | new MethodCall(
35 | new TypeAccess(typeof(string)),
36 | typeof(string).GetMethod("Concat", new[] { typeof(string[]) }),
37 | new IExpression[]
38 | {
39 | new Constant("a"),
40 | new Constant("a"),
41 | new Constant("a"),
42 | new Constant("a"),
43 | new Constant("a"),
44 | new Constant("a")
45 | }
46 | )
47 | );
48 | }
49 |
50 | [Test]
51 | public void ConcatWithBoxing()
52 | {
53 | Resolve(
54 | "\"a\" + 1",
55 | new MethodCall(
56 | new TypeAccess(typeof(string)),
57 | typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
58 | new IExpression[]
59 | {
60 | new Constant("a"),
61 | new Constant(1)
62 | }
63 | )
64 | );
65 | }
66 |
67 | [Test]
68 | public void Power()
69 | {
70 | Resolve(
71 | "1 ^ 2",
72 | new MethodCall(
73 | new TypeAccess(typeof(Math)),
74 | typeof(Math).GetMethod("Pow"),
75 | new IExpression[]
76 | {
77 | new Constant(1),
78 | new Constant(2)
79 | }
80 | )
81 | );
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Expressions.Test/FleeLanguage/Compilation/Imports.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.FleeLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Imports : TestBase
10 | {
11 | [Test]
12 | public void RootImport()
13 | {
14 | Resolve(
15 | new ExpressionContext(new[] { new Import(typeof(Math)) }),
16 | "Abs(-1)",
17 | 1
18 | );
19 | }
20 |
21 | [Test]
22 | public void NamespaceImport()
23 | {
24 | Resolve(
25 | new ExpressionContext(new[] { new Import("ns1", typeof(Math)) }),
26 | "ns1.Abs(-1)",
27 | 1
28 | );
29 | }
30 |
31 | [Test]
32 | public void NestedNamespaceImport()
33 | {
34 | Resolve(
35 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", typeof(Math))) }),
36 | "ns1.ns2.Abs(-1)",
37 | 1
38 | );
39 | }
40 |
41 | [Test]
42 | public void DoubleNestedNamespaceImport()
43 | {
44 | Resolve(
45 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", new Import("ns3", typeof(Math)))) }),
46 | "ns1.ns2.ns3.Abs(-1)",
47 | 1
48 | );
49 | }
50 |
51 | [Test]
52 | public void NestedImportOnNamespace()
53 | {
54 | Resolve(
55 | new ExpressionContext(
56 | new[]
57 | {
58 | new Import(
59 | "ns",
60 | new Import(typeof(Math)),
61 | new Import(typeof(int))
62 | )
63 | }
64 | ),
65 | "ns.Abs(ns.MinValue + 10)",
66 | int.MaxValue - 9
67 | );
68 | }
69 |
70 | [Test]
71 | public void NestedImportOnNestedNamespace()
72 | {
73 | Resolve(
74 | new ExpressionContext(
75 | new[]
76 | {
77 | new Import(
78 | "ns1",
79 | new Import(typeof(Math)),
80 | new Import(
81 | "ns2",
82 | new Import(typeof(int))
83 | )
84 | )
85 | }
86 | ),
87 | "ns1.Abs(ns1.ns2.MinValue + 10)",
88 | int.MaxValue - 9
89 | );
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Expressions.Test/CsharpLanguage/Compilation/Imports.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.CsharpLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Imports : TestBase
10 | {
11 | [Test]
12 | public void RootImport()
13 | {
14 | Resolve(
15 | new ExpressionContext(new[] { new Import(typeof(Math)) }),
16 | "Abs(-1)",
17 | 1
18 | );
19 | }
20 |
21 | [Test]
22 | public void NamespaceImport()
23 | {
24 | Resolve(
25 | new ExpressionContext(new[] { new Import("ns1", typeof(Math)) }),
26 | "ns1.Abs(-1)",
27 | 1
28 | );
29 | }
30 |
31 | [Test]
32 | public void NestedNamespaceImport()
33 | {
34 | Resolve(
35 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", typeof(Math))) }),
36 | "ns1.ns2.Abs(-1)",
37 | 1
38 | );
39 | }
40 |
41 | [Test]
42 | public void DoubleNestedNamespaceImport()
43 | {
44 | Resolve(
45 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", new Import("ns3", typeof(Math)))) }),
46 | "ns1.ns2.ns3.Abs(-1)",
47 | 1
48 | );
49 | }
50 |
51 | [Test]
52 | public void NestedImportOnNamespace()
53 | {
54 | Resolve(
55 | new ExpressionContext(
56 | new[]
57 | {
58 | new Import(
59 | "ns",
60 | new Import(typeof(Math)),
61 | new Import(typeof(int))
62 | )
63 | }
64 | ),
65 | "ns.Abs(ns.MinValue + 10)",
66 | int.MaxValue - 9
67 | );
68 | }
69 |
70 | [Test]
71 | public void NestedImportOnNestedNamespace()
72 | {
73 | Resolve(
74 | new ExpressionContext(
75 | new[]
76 | {
77 | new Import(
78 | "ns1",
79 | new Import(typeof(Math)),
80 | new Import(
81 | "ns2",
82 | new Import(typeof(int))
83 | )
84 | )
85 | }
86 | ),
87 | "ns1.Abs(ns1.ns2.MinValue + 10)",
88 | int.MaxValue - 9
89 | );
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/Imports.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class Imports : TestBase
10 | {
11 | [Test]
12 | public void RootImport()
13 | {
14 | Resolve(
15 | new ExpressionContext(new[] { new Import(typeof(Math)) }),
16 | "Abs(-1)",
17 | 1
18 | );
19 | }
20 |
21 | [Test]
22 | public void NamespaceImport()
23 | {
24 | Resolve(
25 | new ExpressionContext(new[] { new Import("ns1", typeof(Math)) }),
26 | "ns1.Abs(-1)",
27 | 1
28 | );
29 | }
30 |
31 | [Test]
32 | public void NestedNamespaceImport()
33 | {
34 | Resolve(
35 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", typeof(Math))) }),
36 | "ns1.ns2.Abs(-1)",
37 | 1
38 | );
39 | }
40 |
41 | [Test]
42 | public void DoubleNestedNamespaceImport()
43 | {
44 | Resolve(
45 | new ExpressionContext(new[] { new Import("ns1", new Import("ns2", new Import("ns3", typeof(Math)))) }),
46 | "ns1.ns2.ns3.Abs(-1)",
47 | 1
48 | );
49 | }
50 |
51 | [Test]
52 | public void NestedImportOnNamespace()
53 | {
54 | Resolve(
55 | new ExpressionContext(
56 | new[]
57 | {
58 | new Import(
59 | "ns",
60 | new Import(typeof(Math)),
61 | new Import(typeof(int))
62 | )
63 | }
64 | ),
65 | "ns.Abs(ns.MinValue + 10)",
66 | int.MaxValue - 9
67 | );
68 | }
69 |
70 | [Test]
71 | public void NestedImportOnNestedNamespace()
72 | {
73 | Resolve(
74 | new ExpressionContext(
75 | new[]
76 | {
77 | new Import(
78 | "ns1",
79 | new Import(typeof(Math)),
80 | new Import(
81 | "ns2",
82 | new Import(typeof(int))
83 | )
84 | )
85 | }
86 | ),
87 | "ns1.Abs(ns1.ns2.MinValue + 10)",
88 | int.MaxValue - 9
89 | );
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Expressions.Test/VisualBasicLanguage/Compilation/BinaryExpressions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using NUnit.Framework;
5 |
6 | namespace Expressions.Test.VisualBasicLanguage.Compilation
7 | {
8 | [TestFixture]
9 | internal class BinaryExpressions : TestBase
10 | {
11 | [Test]
12 | public void Constants()
13 | {
14 | Resolve("1 + 1", 2);
15 | Resolve("1 + 1.1", 2.1);
16 | Resolve("\"hi\"", "hi");
17 | }
18 |
19 | [Test]
20 | public void ConstantAndVariable()
21 | {
22 | var context = new ExpressionContext();
23 |
24 | context.Variables.Add(new Variable("Variable1") { Value = 1 });
25 | context.Variables.Add(new Variable("Variable2") { Value = 1.1 });
26 |
27 | Resolve(context, "Variable1 + 1", 2);
28 | Resolve(context, "Variable2 + 1", 2.1);
29 | }
30 |
31 | [Test]
32 | public void Logicals()
33 | {
34 | Resolve("true and true", true);
35 | Resolve("true and false", false);
36 | Resolve("false and true", false);
37 | Resolve("false and false", false);
38 | Resolve("true or true", true);
39 | Resolve("true or false", true);
40 | Resolve("false or true", true);
41 | Resolve("false or false", false);
42 | Resolve("true xor true", false);
43 | Resolve("true xor false", true);
44 | Resolve("false xor true", true);
45 | Resolve("false xor false", false);
46 | }
47 |
48 | [Test]
49 | public void Calculation()
50 | {
51 | Resolve("2147483648Ui / 2ui", 1073741824u);
52 | }
53 |
54 | [Test]
55 | public void Remainder()
56 | {
57 | Resolve("2147483648Ui % 5Ui", 3);
58 | }
59 |
60 | [Test]
61 | public void GreaterEquals()
62 | {
63 | Resolve("100>=1", true);
64 | }
65 |
66 | [Test]
67 | public void UnsignedLessThan()
68 | {
69 | Resolve(
70 | new ExpressionContext(new[] { new Import("uint", typeof(uint)) }),
71 | "uint.minvalue < uint.maxvalue",
72 | true
73 | );
74 | }
75 |
76 | [Test]
77 | public void CompareString()
78 | {
79 | var context = new ExpressionContext();
80 |
81 | context.Variables.Add(new Variable("Variable") { Value = "ab" });
82 |
83 | Resolve(
84 | context,
85 | "Variable = \"a\" + \"b\"",
86 | true
87 | );
88 | }
89 |
90 | [Test]
91 | public void HexConstant()
92 | {
93 | Resolve("&h80000000.GetType()", typeof(uint));
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Libraries/AntlrTools/Tool/Templates/dot/dot.stg:
--------------------------------------------------------------------------------
1 | /*
2 | * [The "BSD license"]
3 | * Copyright (c) 2011 Terence Parr
4 | * All rights reserved.
5 | *
6 | * Conversion to C#:
7 | * Copyright (c) 2011 Sam Harwell, Tunnel Vision Laboratories, LLC.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 |
33 | dfa(decisionRanks,states,edges,rankdir,startState,useBox) ::= <<
34 | digraph NFA {
35 | rankdir=;
36 |
37 |
38 |
39 | }
40 | >>
41 |
42 | nfa(decisionRanks,states,edges,rankdir,startState) ::= <<
43 | digraph NFA {
44 | rankdir=LR;
45 |
46 |
47 |
48 | }
49 | >>
50 |
51 | decision_rank(states) ::= <<
52 | {rank=same; rankdir=TB; }
53 | >>
54 |
55 | edge(src,target,label,arrowhead) ::= <<
56 | -> [fontsize=11, fontname="Courier", arrowsize=.7, label = "