Files
acceptance-tests
data
docs
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Profiler.Log
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
SMDiagnostics
System
System.Activities
System.Activities.Core.Presentation
System.Activities.DurableInstancing
System.Activities.Presentation
System.ComponentModel.DataAnnotations
System.Configuration
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.IdentityModel
System.IdentityModel.Selectors
System.Net
System.Numerics
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.Serialization
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DataVisualization
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Workflow.Activities
Common
Designers
Executors
LocalService
Role
Rules
Design
Parser
ArithmeticLiteral.cs.REMOVED.git-id
CodeDomDecompiler.cs
ConditionChanges.cs
DeclarativeConditionsCollection.cs
DeclarativeExpressionConditionDeclaration.cs
Exceptions.cs
Executor.cs
Expressions.cs.REMOVED.git-id
Helpers.cs
Literal.cs.REMOVED.git-id
References.cs
Rule.cs
RuleAction.cs
RuleAttributes.cs
RuleDefinitions.cs
RuleEngine.cs
RuleSet.cs
RuleSetCollection.cs
RuleSetReference.cs
RuleValidation.cs.REMOVED.git-id
Statements.cs
Tracer.cs
UserDataKeys.cs
Walker.cs
ActivityTrace.cs
AssemblyInfo.cs
Code.cs
CodeExpressionRuleDeclaration.cs
CompensatableSequenceActivity.cs
Conditional.cs
ConditionalBranch.cs
ConstrainedGroup.cs
CorrelationValidator.cs
Delay.cs
EventDriven.cs
EventHandlers.cs
EventHandlingScope.cs
EventSinkActivity.cs
Interfaces.cs
InvokeMethodActivity.cs
InvokeSchedule.cs
InvokeWebService.cs
Listen.cs
Parallel.cs
Policy.cs
SR.cs
Schedule.cs
Scope.cs
Sequence.cs
SetState.cs
SetStateEventArgs.cs
State.cs
StateFinalizationActivity.cs
StateInitialization.cs
StateMachineAction.cs
StateMachineExecutionState.cs
StateMachineHelpers.cs
StateMachineSubscription.cs
StateMachineSubscriptionManager.cs
StateMachineWorkflow.cs
StateMachineWorkflowInstance.cs
StateValidator.cs
Task.cs
WebServiceFault.cs
WebServiceReceive.cs
WebServiceResponse.cs
While.cs
System.Workflow.ComponentModel
System.Workflow.Runtime
System.WorkflowServices
System.Xaml.Hosting
System.Xml
System.Xml.Linq
XamlBuildTask
mscorlib
LICENSE.txt
PATENTS.TXT
README.Mono.md
README.md
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

241 lines
9.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;
using System.Reflection;
using System.Globalization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.Activities.Common;
namespace System.Workflow.Activities.Rules
{
internal abstract class RuleCodeDomStatement
{
internal abstract bool Validate(RuleValidation validation);
internal abstract void Execute(RuleExecution execution);
internal abstract void AnalyzeUsage(RuleAnalysis analysis);
internal abstract void Decompile(StringBuilder decompilation);
internal abstract bool Match(CodeStatement expression);
internal abstract CodeStatement Clone();
}
internal class ExpressionStatement : RuleCodeDomStatement
{
private CodeExpressionStatement exprStatement;
private ExpressionStatement(CodeExpressionStatement exprStatement)
{
this.exprStatement = exprStatement;
}
internal static RuleCodeDomStatement Create(CodeStatement statement)
{
return new ExpressionStatement((CodeExpressionStatement)statement);
}
internal override bool Validate(RuleValidation validation)
{
bool success = false;
if (exprStatement.Expression == null)
{
ValidationError error = new ValidationError(Messages.NullInvokeStatementExpression, ErrorNumbers.Error_ParameterNotSet);
error.UserData[RuleUserDataKeys.ErrorObject] = exprStatement;
validation.Errors.Add(error);
}
else if (exprStatement.Expression is CodeMethodInvokeExpression)
{
RuleExpressionInfo exprInfo = RuleExpressionWalker.Validate(validation, exprStatement.Expression, false);
success = (exprInfo != null);
}
else
{
ValidationError error = new ValidationError(Messages.InvokeNotHandled, ErrorNumbers.Error_CodeExpressionNotHandled);
error.UserData[RuleUserDataKeys.ErrorObject] = exprStatement;
validation.Errors.Add(error);
}
return success;
}
internal override void AnalyzeUsage(RuleAnalysis analysis)
{
RuleExpressionWalker.AnalyzeUsage(analysis, exprStatement.Expression, false, false, null);
}
internal override void Execute(RuleExecution execution)
{
RuleExpressionWalker.Evaluate(execution, exprStatement.Expression);
}
internal override void Decompile(StringBuilder decompilation)
{
if (exprStatement.Expression == null)
{
RuleEvaluationException exception = new RuleEvaluationException(Messages.InvokeStatementNull);
exception.Data[RuleUserDataKeys.ErrorObject] = exprStatement;
throw exception;
}
RuleExpressionWalker.Decompile(decompilation, exprStatement.Expression, null);
}
internal override bool Match(CodeStatement comperand)
{
CodeExpressionStatement comperandStatement = comperand as CodeExpressionStatement;
return ((comperandStatement != null)
&& RuleExpressionWalker.Match(exprStatement.Expression, comperandStatement.Expression));
}
internal override CodeStatement Clone()
{
CodeExpressionStatement newStatement = new CodeExpressionStatement();
newStatement.Expression = RuleExpressionWalker.Clone(exprStatement.Expression);
return newStatement;
}
}
internal class AssignmentStatement : RuleCodeDomStatement
{
private CodeAssignStatement assignStatement;
private AssignmentStatement(CodeAssignStatement assignStatement)
{
this.assignStatement = assignStatement;
}
internal static RuleCodeDomStatement Create(CodeStatement statement)
{
return new AssignmentStatement((CodeAssignStatement)statement);
}
internal override bool Validate(RuleValidation validation)
{
bool success = false;
string message;
RuleExpressionInfo lhsExprInfo = null;
if (assignStatement.Left == null)
{
ValidationError error = new ValidationError(Messages.NullAssignLeft, ErrorNumbers.Error_LeftOperandMissing);
error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
validation.Errors.Add(error);
}
else
{
lhsExprInfo = validation.ExpressionInfo(assignStatement.Left);
if (lhsExprInfo == null)
lhsExprInfo = RuleExpressionWalker.Validate(validation, assignStatement.Left, true);
}
RuleExpressionInfo rhsExprInfo = null;
if (assignStatement.Right == null)
{
ValidationError error = new ValidationError(Messages.NullAssignRight, ErrorNumbers.Error_RightOperandMissing);
error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
validation.Errors.Add(error);
}
else
{
rhsExprInfo = RuleExpressionWalker.Validate(validation, assignStatement.Right, false);
}
if (lhsExprInfo != null && rhsExprInfo != null)
{
Type expressionType = rhsExprInfo.ExpressionType;
Type assignmentType = lhsExprInfo.ExpressionType;
if (assignmentType == typeof(NullLiteral))
{
// Can't assign to a null literal.
ValidationError error = new ValidationError(Messages.NullAssignLeft, ErrorNumbers.Error_LeftOperandInvalidType);
error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
validation.Errors.Add(error);
success = false;
}
else if (assignmentType == expressionType)
{
// Easy case, they're both the same type.
success = true;
}
else
{
// The types aren't the same, but it still might be a legal assignment.
ValidationError error = null;
if (!RuleValidation.TypesAreAssignable(expressionType, assignmentType, assignStatement.Right, out error))
{
if (error == null)
{
message = string.Format(CultureInfo.CurrentCulture, Messages.AssignNotAllowed, RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(assignmentType));
error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
}
error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
validation.Errors.Add(error);
}
else
{
success = true;
}
}
}
return success;
}
internal override void AnalyzeUsage(RuleAnalysis analysis)
{
// The left side of the assignment is modified.
RuleExpressionWalker.AnalyzeUsage(analysis, assignStatement.Left, false, true, null);
// The right side of the assignment is read.
RuleExpressionWalker.AnalyzeUsage(analysis, assignStatement.Right, true, false, null);
}
internal override void Execute(RuleExecution execution)
{
Type leftType = execution.Validation.ExpressionInfo(assignStatement.Left).ExpressionType;
Type rightType = execution.Validation.ExpressionInfo(assignStatement.Right).ExpressionType;
RuleExpressionResult leftResult = RuleExpressionWalker.Evaluate(execution, assignStatement.Left);
RuleExpressionResult rightResult = RuleExpressionWalker.Evaluate(execution, assignStatement.Right);
leftResult.Value = Executor.AdjustType(rightType, rightResult.Value, leftType);
}
internal override void Decompile(StringBuilder decompilation)
{
if (assignStatement.Right == null)
{
RuleEvaluationException exception = new RuleEvaluationException(Messages.AssignRightNull);
exception.Data[RuleUserDataKeys.ErrorObject] = assignStatement;
throw exception;
}
if (assignStatement.Left == null)
{
RuleEvaluationException exception = new RuleEvaluationException(Messages.AssignLeftNull);
exception.Data[RuleUserDataKeys.ErrorObject] = assignStatement;
throw exception;
}
RuleExpressionWalker.Decompile(decompilation, assignStatement.Left, null);
decompilation.Append(" = ");
RuleExpressionWalker.Decompile(decompilation, assignStatement.Right, null);
}
internal override bool Match(CodeStatement comperand)
{
CodeAssignStatement comperandStatement = comperand as CodeAssignStatement;
return ((comperandStatement != null)
&& RuleExpressionWalker.Match(assignStatement.Left, comperandStatement.Left)
&& RuleExpressionWalker.Match(assignStatement.Right, comperandStatement.Right));
}
internal override CodeStatement Clone()
{
CodeAssignStatement newStatement = new CodeAssignStatement();
newStatement.Left = RuleExpressionWalker.Clone(assignStatement.Left);
newStatement.Right = RuleExpressionWalker.Clone(assignStatement.Right);
return newStatement;
}
}
}