Пример #1
0
		public static string node(syntax_tree_node tn)
		{
			string_ref sr=new string_ref();
			get_node_info gni=new get_node_info(sr);
			tn.visit(gni);
			return sr.s;
		}
Пример #2
0
        protected bool visitNode = true; // в OnEnter можно сделать false

        public virtual void ProcessNode(syntax_tree_node Node)
        {
            if (Node != null)
            {
                if (OnEnter != null)
                    OnEnter(Node);

                if (visitNode)
                    Node.visit(this);
                else visitNode = true;

                if (OnLeave != null)
                    OnLeave(Node);
            }
        }
 public override void Exit(syntax_tree_node st)
 {
     if (st is procedure_definition)
     {
         if (mids.vars.Count>0)
         {
             d[st as procedure_definition] = new HashSet<string>(mids.vars);
         }
         var fld = new FindLocalDefsVisitor();
         st.visit(fld);
         fld.Print();
         var t = fld.ids.Intersect(mids.vars); // идентификаторы, захваченные из локального контекста
         
     }
     base.Exit(st);
 }
Пример #4
0
        private void prepare_node_with_text(syntax_tree_node subnode, string text)
		{
			if (subnode==null)
			{
				return;
			}
			TreeNode tn=new TreeNode();
			tn.Text=text;
			tn.Tag=subnode;
			string s=get_node_info.node(subnode);
			if (s!=null)
			{
				tn.Text+="     "+s;
			}
			//tn.Nodes.Clear();
			visualizator vs=new visualizator(tn.Nodes);
			subnode.visit(vs);
			nodes.Add(tn);
		}
        public syntax_tree_node Convert(syntax_tree_node root)
        {
            root.visit(new MarkMethodHasYieldAndCheckSomeErrorsVisitor());
            ProcessYieldCapturedVarsVisitor.New.ProcessNode(root);
            //root.visit(py); - пропускал корень

#if DEBUG
            try
            {
               //root.visit(new SimplePrettyPrinterVisitor(@"d:\\zzz1.txt"));
            }
            catch 
            {

            }
            
#endif

            return root;
        }
 private void visit_node(syntax_tree_node sn)
 {
     if (sn != null && !(sn is empty_statement))
     {
         if (!caret_syn_node_found && sn.source_context != null && GetPosition(sn.source_context.begin_position.line_num, sn.source_context.begin_position.column_num) >= caret_pos)
         {
             caret_syn_node_found = true;
             if (GetPosition(sn.source_context.begin_position.line_num, sn.source_context.begin_position.column_num) == caret_pos)
             {
                 output_caret_line = sn.source_context.begin_position.line_num;
                 output_caret_col = sn.source_context.begin_position.column_num;
             }
             else
             if (prev_sn != null && prev_sn.source_context != null)
             {
                 output_caret_line = prev_sn.source_context.begin_position.line_num;
                 output_caret_col = prev_sn.source_context.begin_position.column_num;
             }
             else if (sn.source_context != null)
             {
                 output_caret_line = sn.source_context.begin_position.line_num;
                 output_caret_col = sn.source_context.begin_position.column_num;
             }
         }
         if (!(sn is block) && !(sn is declarations) && !(sn is class_body && has_members(sn as class_body)) && 
             !(sn is class_members) && !(sn is procedure_attributes_list) && !(sn is property_accessors) &&
             !(sn is exception_block) && !(sn is exception_handler_list))
         {
             if (sn.source_context != null)
                 WritePossibleCommentBefore(sn);
             if (sn.source_context != null)
                 prev_sn = sn;
             if (sn is variable_definitions || sn is array_type || sn is set_type_definition
                 || sn is repeat_node || sn is if_node || sn is while_node || sn is for_node
                 || sn is foreach_stmt || sn is var_statement || sn is try_stmt || sn is goto_statement
                 || sn is with_statement || sn is case_node || sn is function_header || sn is procedure_header
                 || sn is constructor || sn is destructor || sn is type_declarations || sn is consts_definitions_list
                 || sn is label_definitions || sn is class_definition || sn is uses_list || sn is unit_name || sn is program_name ||
                 sn is new_expr || sn is raise_stmt || sn is interface_node || sn is implementation_node
                 || sn is lock_stmt || sn is simple_property || sn is read_accessor_name || sn is write_accessor_name
                 || sn is formal_parameters || sn is bracket_expr || sn is record_const || sn is array_const || sn is exception_handler
                 || sn is try_handler_finally || sn is try_handler_except || sn is external_directive || sn is where_definition
                 || (sn is simple_const_definition && in_class && !in_procedure) || (sn is typed_const_definition && in_class && !in_procedure))
                 read_from_beg_pos = true;
         }
         sn.visit(this);
         if (!(sn is block) && !(sn is declarations) && !(sn is class_body) && !(sn is class_members))
         {
             if (sn.source_context != null)
                 WritePossibleCommentAfter(sn);
             if (sn.source_context != null /*&& !(sn is exception_handler)*/)
                 prev_sn = sn;
         }
     }
 }
 public void Change(syntax_tree_node sn)
 {
     //sn.visit(new CalcConstExprs());
     sn.visit(new LoweringVisitor());
     sn.visit(new ProcessYieldCapturedVarsVisitor());
 }
 public syntax_tree_node Convert(syntax_tree_node root)
 {
     root.visit(new ProcessYieldCapturedVarsVisitor());
     return root;
 }
 public override void ProcessNode(syntax_tree_node Node)
 {
     if (Node == null)
         return;
     if (Node.source_context == null)
         return;
     if (FindContextIn(Node))
         Node.visit(this);
     else
     {
         if (ContextInRightOrder(_findContext, Node.source_context))
         {
             if (_findResult == null)
                 _findResult = Node;
             else
                 if (ContextStartsInRightOrder(Node.source_context, _findResult.source_context))
                     _findResult = Node;
         }
     }
 }
 void visit_node(syntax_tree_node node)
 {
     if (node != null)
         node.visit(this);
 }