コード例 #1
0
        public static bool Has(syntax_tree_node node)
        {
            HasStatementWithBarrierVisitor <T, Barrier> vis = new HasStatementWithBarrierVisitor <T, Barrier>();

            vis.ProcessNode(node);

            return(vis.foundT);
        }
コード例 #2
0
        public override void visit(procedure_definition pd)
        {
            //this.CurrentMethod = pd;

            MethodsStack.Push(pd);

            HasYields = false;

            base.visit(pd);
            pd.has_yield = HasYields;

            if (pd.has_yield) // SSM bug fix #219
            {
                var ee = pd.proc_body as block;
                if (ee != null)
                {
                    var FirstTypeDeclaration = ee.defs.DescendantNodes().OfType <type_declarations>();
                    if (FirstTypeDeclaration.Count() > 0)
                    {
                        throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_LOCAL_TYPE_DEFINITIONS", FirstTypeDeclaration.First().source_context);
                    }
                    var FirstInheritedIdent = ee.DescendantNodes().OfType <inherited_ident>(); // SSM bug fix #1440
                    if (FirstInheritedIdent.Count() > 0)
                    {
                        throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_INHERITED_CALLS", FirstInheritedIdent.First().source_context);
                    }
                }

                CheckArrayRecordInitializersVisitor.New.ProcessNode(pd);
            }

            /*if (pd.has_yield)
             * {
             *  var dn = pd.DescendantNodes().OfType<ident>().Where(id => id.name.ToLower() == "result").FirstOrDefault();
             *  if (dn != null)
             *      throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_RESULT", dn);
             * }*/

            if (pd.has_yield)
            {
                if (IdResult != null)
                {
                    throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_RESULT", IdResult);
                }
            }

            var innerPds = pd.DescendantNodes().OfType <procedure_definition>();

            if (pd.has_yield && innerPds.Count() > 0 ||
                innerPds.Where(npd => npd.has_yield).Count() > 0)
            {
                // Есть yield и вложенные - плохо
                // Или нет yield но есть вложенные с yield
                throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_NESTED_SUBROUTINES", pd.source_context);
            }

            if (pd.has_yield && HasStatementWithBarrierVisitor <try_stmt, function_lambda_definition> .Has(pd))
            //pd.DescendantNodes().OfType<try_stmt>().Count() > 0)
            {
                throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_TRY_EXCEPT_FINALLY", pd.source_context);
            }

            if (pd.has_yield && HasStatementWithBarrierVisitor <lock_stmt, function_lambda_definition> .Has(pd))
            //pd.DescendantNodes().OfType<lock_stmt>().Count() > 0)
            {
                throw new SyntaxVisitorError("FUNCTIONS_WITH_YIELDS_CANNOT_CONTAIN_LOCK", pd.source_context);
            }

            HasYields = false;
            IdResult  = null;

            MethodsStack.Pop();

            //this.CurrentMethod = null;
        }