Logo Search packages:      
Sourcecode: uncrustify version File versions

static void uncrustify_file ( const char *  data,
int  data_len,
FILE *  pfout,
const char *  parsed_file 
) [static]

Parse the text into chunks

Change certain token types based on simple sequence. Example: change '[' + ']' to '[]' Note that level info is not yet available, so it is OK to do all processing that doesn't need to know level info. (that's very little!)

Detect the brace and paren levels and insert virtual braces. This handles all that nasty preprocessor stuff

At this point, the level information is available and accurate.

Re-type chunks, combine chunks

Look at all colons ':' and mark labels, :? sequences, etc.

Change virtual braces into real braces...

Add parens

Insert line breaks as needed

Add balanced spaces around nested params

Fix same-line inter-chunk spacing

Do any aligning of preprocessors

Indent the text

Aligning everything else and reindent

And finally, align the backslash newline stuff

Now render it all to the output file

Definition at line 678 of file uncrustify.cpp.

References align_backslash_newline(), align_preprocessor(), brace_cleanup(), combine_labels(), do_blank_lines(), do_code_width(), fix_symbols(), mark_comments(), newlines_bool_pos(), newlines_class_colon_pos(), newlines_cleanup_braces(), newlines_insert_blank_lines(), pawn_prescan(), space_text(), space_text_balance_nested_parens(), tokenize(), and tokenize_cleanup().

Referenced by do_source_file().

{
   /**
    * Parse the text into chunks
    */
   tokenize(data, data_len);

   /**
    * Change certain token types based on simple sequence.
    * Example: change '[' + ']' to '[]'
    * Note that level info is not yet available, so it is OK to do all
    * processing that doesn't need to know level info. (that's very little!)
    */
   tokenize_cleanup();

   /**
    * Detect the brace and paren levels and insert virtual braces.
    * This handles all that nasty preprocessor stuff
    */
   brace_cleanup();

   /**
    * At this point, the level information is available and accurate.
    */

   if ((cpd.lang_flags & LANG_PAWN) != 0)
   {
      pawn_prescan();
   }

   /**
    * Re-type chunks, combine chunks
    */
   fix_symbols();

   /**
    * Look at all colons ':' and mark labels, :? sequences, etc.
    */
   combine_labels();

   /**
    * Change virtual braces into real braces...
    */
   do_braces();

   /**
    * Add parens
    */
   do_parens();

   /**
    * Insert line breaks as needed
    */
   do_blank_lines();
   newlines_cleanup_braces();
   newlines_insert_blank_lines();
   if (cpd.settings[UO_nl_ds_struct_enum_cmt].b)
   {
      newlines_double_space_struct_enum_union();
   }
   if (cpd.settings[UO_nl_squeeze_ifdef].b)
   {
      newlines_squeeze_ifdef();
   }
   if (cpd.settings[UO_pos_bool].tp != TP_IGNORE)
   {
      newlines_bool_pos();
   }
   newlines_class_colon_pos();
   newlines_eat_start_end();
   newlines_cleanup_dup();

   mark_comments();

   /**
    * Add balanced spaces around nested params
    */
   if (cpd.settings[UO_sp_balance_nested_parens].b)
   {
      space_text_balance_nested_parens();
   }

   /**
    * Fix same-line inter-chunk spacing
    */
   space_text();

   /**
    * Do any aligning of preprocessors
    */
   if (cpd.settings[UO_align_pp_define_span].n > 0)
   {
      align_preprocessor();
   }

   /**
    * Indent the text
    */
   indent_text();
   indent_preproc();

   /**
    * Aligning everything else and reindent
    */
   align_all();
   indent_text();

   if (cpd.settings[UO_code_width].n > 0)
   {
      int max_passes = 3;
      int prev_changes;
      do
      {
         prev_changes = cpd.changes;
         do_code_width();
         if (prev_changes != cpd.changes)
         {
            indent_text();
         }
      } while ((prev_changes != cpd.changes) && (--max_passes > 0));
   }

   /**
    * And finally, align the backslash newline stuff
    */
   align_right_comments();
   if (cpd.settings[UO_align_nl_cont].b)
   {
      align_backslash_newline();
   }

   /**
    * Now render it all to the output file
    */
   output_text(pfout);

   /* Special hook for dumping parsed data for debugging */
   if (parsed_file != NULL)
   {
      FILE *p_file = fopen(parsed_file, "w");
      if (p_file != NULL)
      {
         output_parsed(p_file);
         fclose(p_file);
      }
   }

   /* Free all the memory */
   chunk_t *pc;
   while ((pc = chunk_get_head()) != NULL)
   {
      chunk_del(pc);
   }
}


Generated by  Doxygen 1.6.0   Back to index