当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.Expression类代码示例

本文整理汇总了C#中System.Compiler.Expression的典型用法代码示例。如果您正苦于以下问题:C# Expression类的具体用法?C# Expression怎么用?C# Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Expression类属于System.Compiler命名空间,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImplicitCoercionFromTo

        //
        // We add an implicit conversion from "object" to any of our heap-allocated
        // types.
        //
        // We also permit implicit conversions between "int" and "byte".
        //
        // TODO: We may need to construct a more elaborate expression here for the
        // conversion to permit the runtime to make the appropriate checks.
        //
        public override bool ImplicitCoercionFromTo(Expression source, TypeNode t1, TypeNode t2)
        {
            if (t1 == SystemTypes.Object)
            {
                if (t2 is Chan || t2 is Set || t2 is ZArray || t2 is Class)
                    return true;
                else
                    return false;
            }

            if (t2 == SystemTypes.Object)
            {
                if (t1 is Chan || t1 is Set || t1 is ZArray || t1 is Class)
                    return true;
                else
                    return false;
            }

            if (t1 == SystemTypes.Int32 && t2 == SystemTypes.UInt8)
                return true;

            if (t1 == SystemTypes.UInt8 && t2 == SystemTypes.Int32)
                return true;

            return base.ImplicitCoercionFromTo(source, t1, t2);
        }
开发者ID:ZingModelChecker,项目名称:Zing,代码行数:35,代码来源:TypeSystem.cs

示例2: CheckMethodSpecAdmissibility

 public void CheckMethodSpecAdmissibility(Expression exp, Method method, bool reportWFonly, bool dontReport) {
   DeclaringMethod = method;
   ReportWFErrorOnly = reportWFonly; // true for Pure methods: we only want to enforce well-foundedness on them
   DontReportError = dontReport;     
   StateStack = new System.Collections.Stack();
   ResetCurrentState();
   this.VisitExpression(exp);
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:8,代码来源:AdmissibilityChecker.cs

示例3: VisitExpression

        public override void VisitExpression(Expression expression)
        {
            if (expression == null) return;

            if (expression.NodeType == NodeType.Pop)
                PopOccurrences++;

            base.VisitExpression(expression);
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:9,代码来源:CountPopExpressions.cs

示例4: AbbreviationDuplicator

        public AbbreviationDuplicator(Method sourceMethod, Method targetMethod, ContractNodes contractNodes,
            Method abbreviation, Expression targetObject, ExpressionList actuals)
            : base(targetMethod.DeclaringType.DeclaringModule, sourceMethod, targetMethod, contractNodes, false)
        {
            this.targetObject = targetObject;
            this.abbreviation = abbreviation;
            this.actuals = actuals;

            this.localsInActuals = new TrivialHashtable();

            PopulateLocalsInActuals();
        }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:12,代码来源:AbbreviationDuplicator.cs

示例5: ImplicitCoercion

        public override Expression ImplicitCoercion(Expression source, TypeNode targetType, TypeViewer typeViewer)
        {
            // LJW: added third parameter "typeViewer" so we override the correct thing
            if (source == null || source.Type == null || targetType == null)
                return null;

            if (source.Type is EnumNode && targetType == SystemTypes.Int32)
            {
                return source;
            }

            if (source.Type == SystemTypes.Object)
            {
                if (targetType is Chan || targetType is Set || targetType is ZArray || targetType is Class)
                    return source;
                else
                {
                    this.HandleError(source, System.Compiler.Error.NoImplicitCoercion, "object", targetType.FullName);
                    return null;
                }
            }

            if (targetType == SystemTypes.Object)
            {
                if (!(source.Type is Chan || source.Type is Set || source.Type is ZArray || source.Type is Class))
                {
                    this.HandleError(source, System.Compiler.Error.NoImplicitCoercion, source.Type.FullName, "object");
                    return null;
                }
            }

            if (source.Type == SystemTypes.Int32 && targetType == SystemTypes.UInt8)
            {
                BinaryExpression binExpr = new BinaryExpression(source, new MemberBinding(null, SystemTypes.UInt8),
                    NodeType.Castclass, source.SourceContext);

                binExpr.Type = SystemTypes.UInt8;

                return binExpr;
            }

            if (source.Type == SystemTypes.UInt8 && targetType == SystemTypes.Int32)
            {
                BinaryExpression binExpr = new BinaryExpression(source, new MemberBinding(null, SystemTypes.Int32),
                    NodeType.Castclass, source.SourceContext);

                binExpr.Type = SystemTypes.Int32;

                return binExpr;
            }

            return base.ImplicitCoercion(source, targetType, typeViewer);
        }
开发者ID:ZingModelChecker,项目名称:Zing,代码行数:53,代码来源:TypeSystem.cs

示例6: GenerateForLoop

        internal static Statement GenerateForLoop(Variable loopVariable, Expression lowerBound, Expression upperBound, Statement body)
        {
            Block bodyAsBlock = body as Block ?? new Block(new StatementList(body));
            Block init = new Block(new StatementList(2));
            Block increment = new Block(new StatementList(1));
            Block test = new Block(new StatementList(new Branch(
              new BinaryExpression(loopVariable, upperBound, NodeType.Lt), bodyAsBlock))); //, false, true, false)));

            init.Statements.Add(new AssignmentStatement(loopVariable, lowerBound));
            init.Statements.Add(new Branch(null, test));

            increment.Statements.Add(new AssignmentStatement(loopVariable, new BinaryExpression(loopVariable, Literal.Int32One, NodeType.Add)));

            Block forLoop = new Block(new StatementList(4));
            forLoop.Statements.Add(init);
            forLoop.Statements.Add(bodyAsBlock);
            forLoop.Statements.Add(increment);
            forLoop.Statements.Add(test);
            return forLoop;
        }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:20,代码来源:RewriteUtils.cs

示例7: VisitPop

            public void VisitPop(Expression expression)
            {
                if (expression == null)
                {
                    VisitPop();
                    return;
                }

                // a pop where we know what we pop.

                this.VisitPop();
            }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:12,代码来源:PostExtractorChecker.cs

示例8: VisitExpression

 public override Expression VisitExpression(Expression expression)
 {
     Expression result = base.VisitExpression(expression);
     return result;
 }
开发者ID:ZingModelChecker,项目名称:Zing,代码行数:5,代码来源:ZDecompiler.cs

示例9: AddReadAllGroup

    void AddReadAllGroup(Class serializer, Block block, TypeNode type, StatementList statements, Identifier reader, 
      Expression target, Expression required, Expression result, ArrayList members, Member mixedMember) {

      // todo: keep track of which members have been read and report error on duplicates
      MethodCall read = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Read")), new ExpressionList());

      Local sb = new Local(SystemTypes.StringBuilder);
      bool isMixed = mixedMember != null;
      if (isMixed) {
        statements.Add(new AssignmentStatement(sb,
          new Construct(new MemberBinding(null, SystemTypes.StringBuilder), new ExpressionList(), SystemTypes.StringBuilder)));
      }

      Block whileBody = new Block(new StatementList());
      BinaryExpression notEndTag = new BinaryExpression(
        new QualifiedIdentifier(reader, Identifier.For("NodeType")) ,
        new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("EndElement")), NodeType.Ne);
      BinaryExpression notEOF = new BinaryExpression(
        new QualifiedIdentifier(reader, Identifier.For("EOF")), Literal.True, NodeType.Ne);
      While w = new While(new BinaryExpression(notEndTag, notEOF, NodeType.And), whileBody);
      statements.Add(w);

      Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String,block);
      Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String,block);
      Local nodeType = new Local(Identifier.For("nodeType"),Runtime.XmlNodeType,block);

      whileBody.Statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
      whileBody.Statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
      whileBody.Statements.Add(new AssignmentStatement(nodeType, new QualifiedIdentifier(reader, Identifier.For("NodeType"))));
      
      Block childBlock = whileBody;

      if (isMixed) {
        // Append the text node to the current StringBuilder contents.
        childBlock = new Block(new StatementList());
        If ifText = new If(IsTextNode(nodeType), new Block(new StatementList()), childBlock);

        whileBody.Statements.Add(ifText);
        ExpressionList args = new ExpressionList();
        args.Add(new QualifiedIdentifier(reader, Identifier.For("Value")));
        ifText.TrueBlock.Statements.Add(new ExpressionStatement(new MethodCall(
          new QualifiedIdentifier(sb, Identifier.For("Append")), args)));
        ifText.TrueBlock.Statements.Add(new ExpressionStatement(read)); // advance to next node
      }      

      If ifElement = new If(new BinaryExpression(nodeType,
        new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("Element")), NodeType.Eq),
        new Block(new StatementList()), new Block(new StatementList()));
      childBlock.Statements.Add(ifElement);
      childBlock = ifElement.TrueBlock;

      //AddConsoleWrite(statements, new Literal("name=",SystemTypes.String));
      //AddConsoleWriteLine(statements, nameLocal);
      //AddConsoleWrite(statements, new Literal("nodeType=",SystemTypes.String));
      //AddConsoleWriteLine(statements, nodeType);

      foreach (NamedNode childNode in members) {
        if (!(childNode.Member is Field || childNode.Member is Property)) {
          AddError(statements, reader, RuntimeError.SerializationOfTypeNotSupported, 
            new Literal(childNode.Member.GetType().FullName, SystemTypes.String));
        } else {
          Expression mb = GetMemberBinding(target, childNode.Member);
          childBlock = AddReadChild(block, childBlock.Statements, childNode.Name, childNode.TypeNode, mb, reader, result, true, false).FalseBlock;
          // todo: throw error if child is required. (e.g. NonEmptyIEnumerable...)
        }
      }
      // if it isn't any of the expected elements then throw an error.
      AddError(childBlock.Statements, reader, RuntimeError.NoSuchMember,
        new Expression[2]{new Literal(tempChecker.GetTypeName(type),SystemTypes.String), nameLocal});

      // If it's not an element then consume it anyway to keep the reader advancing.
      // Probably a comment or PI or something.
      ifElement.FalseBlock.Statements.Add(new ExpressionStatement(new MethodCall(
        new QualifiedIdentifier(reader, Identifier.For("Skip")), new ExpressionList())));

      if (isMixed) {
        statements.Add(new AssignmentStatement(GetMemberBinding(target, mixedMember), 
          new MethodCall(new QualifiedIdentifier(sb, Identifier.For("ToString")), new ExpressionList())));         
      }
      statements.Add(new AssignmentStatement(result, Literal.True));

    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:82,代码来源:Serializer.cs

示例10: AddReadContent

    void AddReadContent(Class serializer, Block block, TypeNode type, StatementList statements, Identifier reader, 
      Expression target, Expression required, Expression result, SchemaValidator validator) {
    
      // position us in the content.
      statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
      Local elementName = new Local(Identifier.Empty,SystemTypes.String);
      statements.Add(new AssignmentStatement(elementName, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
      
      // make sure the element is not empty.
      If isEmpty = AddEmptyElementCheck(statements, reader);

      // Read the contents.
      statements = isEmpty.FalseBlock.Statements;
      statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Read")), new ExpressionList())));
      statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));

      ValidationState context = new ValidationState();
      context.ErrorHandler = this.errorHandler;
      validator.validator.InitValidation(context);
      ArrayList members = null;
      if (validator.validator is AllElementsContentValidator) {
        members = validator.validator.ExpectedElements(context, false, false);
        AddReadAllGroup(serializer, block, type, statements, reader, target, required, result, members, validator.validator.MixedMember);
      } else {

        // There should be one root level anonymous Item0 member.
        SequenceNode seq = (SequenceNode)validator.RootNode; // this is a wrapper node.
        if (seq == null) {
          // perhaps it is ContentType.Empty or Mixed.
          if (validator.validator.ContentType == XmlSchemaContentType.Mixed ||
            validator.validator.ContentType == XmlSchemaContentType.TextOnly){
            Debug.Assert(validator.validator.MixedMember != null);
            statements.Add(new AssignmentStatement(GetMemberBinding(target, validator.validator.MixedMember), 
              new MethodCall(new QualifiedIdentifier(reader, Identifier.For("ReadStringElement")), new ExpressionList())));         
          }
          return;
        } else {
          ContentNode n = seq.LeftChild;
          AddReadContentNode(n, block, statements, reader, target, required, result, validator);
        }
      }    

      // consume final end tag
      statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("ReadEndTag")), new ExpressionList(elementName))));
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:45,代码来源:Serializer.cs

示例11: GetNameAndNamespace

 void GetNameAndNamespace(TypeNode type, out Expression name, out Expression ns) {
   name = Literal.Null;
   ns = Literal.Null;
   if (!IsStructuralType(type)) {
     Identifier id = Checker.GetDefaultElementName(type);
     name = new Literal(id.Name, SystemTypes.String);
     if (id.Prefix != null) {
       ns = new Literal(id.Prefix.Name, SystemTypes.String);
     }
   }
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:11,代码来源:Serializer.cs

示例12: AddWriteChoice

    void AddWriteChoice(TypeUnion tu, StatementList statements, TypeNode referringType, Expression src, Identifier writer) {
      // generate the following code:
      //    Type srcType = src.GetType();
      //    if (choiceType.IsAssignableFrom(srcType)){ 
      //      XxxxSerializer s = new XxxxSerializer();
      //      s.Serialize((runtimeType)src, writer);
      //    } else if (...) {
      //      // and so on.
      //    }
      // What we cannot do here is by creating nested XmlSerializers
      // based on runtime type because this could cause infinite recurrsion.
      // So we cannot serialize a type union where one of the choices is "object".

      TypeNodeList choices = tu.Types;

      MethodCall call = new MethodCall();
      call.Callee = new QualifiedIdentifier(src, Identifier.For("GetType"));
      call.Operands = new ExpressionList();

      Local local = new Local(SystemTypes.Type);
      statements.Add(new AssignmentStatement(local, call));

      for (int i = 0, n = choices.Length; i < n; i++) {
        TypeNode choiceType = choices[i];
        if (choiceType == null) continue; // type resolution error.

        // if (choiceType.IsAssignableFrom(srcType)){ 
        BinaryExpression condition = new BinaryExpression(
          new MethodCall(
            new QualifiedIdentifier(new UnaryExpression(new MemberBinding(null, choiceType), NodeType.Typeof), Identifier.For("IsAssignableFrom")),
            new ExpressionList(new Expression[] { local })),
          Literal.True,
          NodeType.Eq);

        Block block = new Block();
        block.Statements = new StatementList();
        BinaryExpression cast = CastTo(src, choiceType);

        Expression name = null, ns = null;
        GetNameAndNamespace(choiceType, out name, out ns);
        Expression simplename = name, simplens = ns;

        // Check for choice of type: [string] and match this with XmlTextNode.
        TypeNode unwrapped = UnwrapSingletonTuple(choiceType, true);
        if (unwrapped == null) unwrapped = choiceType;
        if (unwrapped != null && unwrapped.IsPrimitive) {
          simplename = simplens = null;
          choiceType = unwrapped;
        }

        if (!AddWriteSimpleType(choiceType, block.Statements, referringType, writer, cast, simplename, simplens)) {
          AddCallSerializer(choiceType, block.Statements, cast, writer, name, ns);
        }
        If ifStatement = new If(condition, block, null);
        statements.Add(ifStatement);
      } 
    }
开发者ID:hesam,项目名称:SketchSharp,代码行数:57,代码来源:Serializer.cs

示例13: AddWriteAttributes

 void AddWriteAttributes(StatementList statements, TypeNode referringType, Identifier writer, Expression source, SchemaValidator validator) {
   if (validator.Attributes != null) {
     foreach (SchemaAttDef ad in validator.Attributes) {
       Identifier name = ad.Name;
       Expression src = GetMemberBinding(source, ad.Member);
       if (src.Type == null) continue; // type resolution error.
       if (!AddWriteSimpleAttribute(src.Type, name, statements, referringType, writer, src)) {
         // throw exception, attribute has complex type!
       }
     }
   }
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:12,代码来源:Serializer.cs

示例14: AddCheckForNull

 StatementList AddCheckForNull(StatementList statements, Expression src, TypeNode type) {
   if (type.Template == SystemTypes.GenericBoxed) {
     If checknull = new If(new BinaryExpression(
       new MethodCall(new MemberBinding(src, type.GetMethod(Identifier.For("IsNull"),null)), new ExpressionList()),
       Literal.True, NodeType.Ne), 
       new Block(new StatementList()), null);
     statements.Add(checknull);
     return checknull.TrueBlock.Statements;        
   }
   else if (type is TypeAlias) {
     // cast to underlying type and check that for null.
     TypeNode atype = ((TypeAlias)type).AliasedType;
     return AddCheckForNull(statements, CastTo(src, atype), atype); 
   }
   else if (type is ConstrainedType) {
     // cast to underlying type and check that for null.
     TypeNode atype = ((ConstrainedType)type).UnderlyingType;
     return AddCheckForNull(statements, CastTo(src, atype), atype); 
   }
   else if (!IsStream(type) && !type.IsValueType) { //stream types are doing weird things to the null check?
     if (type == SystemTypes.String || IsStream(type))
       src = CastTo(src, SystemTypes.Object);
     If checknull = new If(new BinaryExpression(src, Literal.Null, NodeType.Ne), 
       new Block(new StatementList()), null);
     statements.Add(checknull);
     return checknull.TrueBlock.Statements;        
   }
   return statements;
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:29,代码来源:Serializer.cs

示例15: Duplicate

 Expression Duplicate(Expression e, TypeNode referringType) {
   Duplicator dup = new Duplicator(this.module, referringType);
   return dup.VisitExpression(e);
 }
开发者ID:hesam,项目名称:SketchSharp,代码行数:4,代码来源:Serializer.cs


注:本文中的System.Compiler.Expression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。