Exemplo n.º 1
0
 public override void write(CCodeWriter writer)
 {
     if (!writer.bol)
     {
         writer.write_newline();
     }
     writer.write_string("#line %d \"%s\"".printf(line_number, filename));
     writer.write_newline();
 }
Exemplo n.º 2
0
 public override void write(CCodeWriter writer)
 {
     writer.write_string("G_GNUC_BEGIN_");
     writer.write_string(section_type.ToString());
     writer.write_newline();
     foreach (CCodeNode node in get_children())
     {
         node.write_combined(writer);
     }
     writer.write_string("G_GNUC_END_");
     writer.write_string(section_type.ToString());
     writer.write_newline();
 }
Exemplo n.º 3
0
 public override void write(CCodeWriter writer)
 {
     writer.write_indent();
     writer.write_string(name);
     writer.write_string(":");
     writer.write_newline();
 }
Exemplo n.º 4
0
 public override void write(CCodeWriter writer)
 {
     writer.write_indent();
     writer.write_string("#ifndef ");
     writer.write_string(define);
     writer.write_newline();
     writer.write_string("#define ");
     writer.write_string(define);
     writer.write_newline();
     foreach (CCodeNode node in get_children())
     {
         node.write_combined(writer);
     }
     writer.write_indent();
     writer.write_string("#endif");
     writer.write_newline();
 }
Exemplo n.º 5
0
        public override void write(CCodeWriter writer)
        {
            writer.write_string("struct ");
            writer.write_string(name);
            writer.write_begin_block();
            foreach (CCodeDeclaration decl in declarations)
            {
                decl.write_declaration(writer);
            }

            writer.write_end_block();
            if (modifiers.HasFlag(CCodeModifiers.DEPRECATED))
            {
                writer.write_string(" G_GNUC_DEPRECATED");
            }
            writer.write_string(";");
            writer.write_newline();
            writer.write_newline();
        }
Exemplo n.º 6
0
        public override void write_initialization(CCodeWriter writer)
        {
            if (initializer != null && !init0)
            {
                writer.write_indent(line);

                writer.write_string(name);
                writer.write_string(" = ");
                initializer.write(writer);

                writer.write_string(";");
                writer.write_newline();
            }
        }
Exemplo n.º 7
0
 public override void write(CCodeWriter writer)
 {
     writer.write_indent();
     writer.write_string("#define ");
     writer.write_string(name);
     writer.write_string(" ");
     if (replacement != null)
     {
         writer.write_string(replacement);
     }
     else
     {
         replacement_expression.write_inner(writer);
     }
     writer.write_newline();
 }
Exemplo n.º 8
0
 public override void write(CCodeWriter writer)
 {
     writer.write_indent();
     writer.write_string("#include ");
     if (local)
     {
         writer.write_string("\"");
         writer.write_string(filename);
         writer.write_string("\"");
     }
     else
     {
         writer.write_string("<");
         writer.write_string(filename);
         writer.write_string(">");
     }
     writer.write_newline();
 }
Exemplo n.º 9
0
        public override void write_declaration(CCodeWriter writer)
        {
            writer.write_indent();
            writer.write_string("typedef ");

            writer.write_string(type_name);

            writer.write_string(" ");

            declarator.write_declaration(writer);

            if (modifiers.HasFlag(CCodeModifiers.DEPRECATED))
            {
                writer.write_string(" G_GNUC_DEPRECATED");
            }

            writer.write_string(";");
            writer.write_newline();
        }
Exemplo n.º 10
0
        public override void write(CCodeWriter writer)
        {
            // the last reachable statement
            CCodeNode last_statement = null;

            writer.write_begin_block();
            foreach (CCodeNode statement in statements)
            {
                statement.write_declaration(writer);

                // determine last reachable statement
                if (statement is CCodeLabel || statement is CCodeCaseStatement)
                {
                    last_statement = null;
                }
                else if (statement is CCodeReturnStatement || statement is CCodeGotoStatement ||
                         statement is CCodeContinueStatement || statement is CCodeBreakStatement)
                {
                    last_statement = statement;
                }
            }

            foreach (CCodeNode statement in statements)
            {
                statement.write(writer);

                // only output reachable code
                if (statement == last_statement)
                {
                    break;
                }
            }

            writer.write_end_block();

            if (!suppress_newline)
            {
                writer.write_newline();
            }
        }
Exemplo n.º 11
0
        public override void write(CCodeWriter writer)
        {
            writer.write_indent(line);
            if (modifiers.HasFlag(CCodeModifiers.INTERNAL))
            {
                writer.write_string("G_GNUC_INTERNAL ");
            }
            if (modifiers.HasFlag(CCodeModifiers.STATIC))
            {
                writer.write_string("static ");
            }
            if (modifiers.HasFlag(CCodeModifiers.INLINE))
            {
                writer.write_string("inline ");
            }
            writer.write_string(return_type);
            writer.write_string(" ");
            writer.write_string(name);
            writer.write_string(" (");

            bool has_args         = (modifiers.HasFlag(CCodeModifiers.PRINTF) || modifiers.HasFlag(CCodeModifiers.SCANF));
            int  i                = 0;
            int  format_arg_index = -1;
            int  args_index       = -1;

            foreach (CCodeParameter param in parameters)
            {
                if (i > 0)
                {
                    writer.write_string(", ");
                }
                param.write(writer);
                if (param.modifiers.HasFlag(CCodeModifiers.FORMAT_ARG))
                {
                    format_arg_index = i;
                }
                if (has_args && param.ellipsis)
                {
                    args_index = i;
                }
                else if (has_args && param.type_name == "va_list" && format_arg_index < 0)
                {
                    format_arg_index = i - 1;
                }
                i++;
            }
            if (i == 0)
            {
                writer.write_string("void");
            }

            writer.write_string(")");

            if (is_declaration)
            {
                if (modifiers.HasFlag(CCodeModifiers.DEPRECATED))
                {
                    writer.write_string(" G_GNUC_DEPRECATED");
                }

                if (modifiers.HasFlag(CCodeModifiers.PRINTF))
                {
                    format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
                    writer.write_string(" G_GNUC_PRINTF(%d,%d)".printf(format_arg_index, args_index + 1));
                }
                else if (modifiers.HasFlag(CCodeModifiers.SCANF))
                {
                    format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
                    writer.write_string(" G_GNUC_SCANF(%d,%d)".printf(format_arg_index, args_index + 1));
                }
                else if (format_arg_index >= 0)
                {
                    writer.write_string(" G_GNUC_FORMAT(%d)".printf(format_arg_index + 1));
                }

                if (modifiers.HasFlag(CCodeModifiers.CONST))
                {
                    writer.write_string(" G_GNUC_CONST");
                }
                if (modifiers.HasFlag(CCodeModifiers.UNUSED))
                {
                    writer.write_string(" G_GNUC_UNUSED");
                }

                if (modifiers.HasFlag(CCodeModifiers.CONSTRUCTOR))
                {
                    writer.write_string(" __attribute__((constructor))");
                }
                else if (modifiers.HasFlag(CCodeModifiers.DESTRUCTOR))
                {
                    writer.write_string(" __attribute__((destructor))");
                }

                writer.write_string(";");
            }
            else
            {
                block.write(writer);
                writer.write_newline();
            }
            writer.write_newline();
        }
Exemplo n.º 12
0
 public override void write(CCodeWriter writer)
 {
     writer.write_newline();
 }
Exemplo n.º 13
0
        public override void write_declaration(CCodeWriter writer)
        {
            if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.INTERNAL | CCodeModifiers.EXTERN)) != 0)
            {
                // combined declaration and initialization for static and extern variables
                writer.write_indent(line);
                if ((modifiers & CCodeModifiers.INTERNAL) != 0)
                {
                    writer.write_string("G_GNUC_INTERNAL ");
                }
                if ((modifiers & CCodeModifiers.STATIC) != 0)
                {
                    writer.write_string("static ");
                }
                if ((modifiers & CCodeModifiers.VOLATILE) != 0)
                {
                    writer.write_string("volatile ");
                }
                if ((modifiers & CCodeModifiers.EXTERN) != 0 && !has_initializer())
                {
                    writer.write_string("extern ");
                }
                if ((modifiers & CCodeModifiers.THREAD_LOCAL) != 0)
                {
                    writer.write_string("thread_local ");
                }
                writer.write_string(type_name);
                writer.write_string(" ");

                bool _first = true;
                foreach (CCodeDeclarator decl in declarators)
                {
                    if (!_first)
                    {
                        writer.write_string(", ");
                    }
                    else
                    {
                        _first = false;
                    }
                    decl.write(writer);
                }

                writer.write_string(";");
                writer.write_newline();
                return;
            }

            writer.write_indent();
            if ((modifiers & CCodeModifiers.REGISTER) == CCodeModifiers.REGISTER)
            {
                writer.write_string("register ");
            }
            if ((modifiers & CCodeModifiers.VOLATILE) != 0)
            {
                writer.write_string("volatile ");
            }
            writer.write_string(type_name);
            writer.write_string(" ");

            bool first = true;

            foreach (CCodeDeclarator decl in declarators)
            {
                if (!first)
                {
                    writer.write_string(", ");
                }
                else
                {
                    first = false;
                }
                decl.write_declaration(writer);
            }

            if (modifiers.HasFlag(CCodeModifiers.DEPRECATED))
            {
                writer.write_string(" G_GNUC_DEPRECATED");
            }

            writer.write_string(";");
            writer.write_newline();
        }
Exemplo n.º 14
0
        public bool store(string filename, string source_filename, bool write_version, bool line_directives, string begin_decls = null, string end_decls = null)
        {
            var writer = new CCodeWriter(filename, source_filename);

            if (!writer.open(write_version))
            {
                return(false);
            }

            if (!is_header)
            {
                writer.line_directives = line_directives;

                comments.write(writer);
                writer.write_newline();
                include_directives.write(writer);
                writer.write_newline();
                type_declaration.write_combined(writer);
                writer.write_newline();
                type_definition.write_combined(writer);
                writer.write_newline();
                type_member_declaration.write_declaration(writer);
                writer.write_newline();
                type_member_declaration.write(writer);
                writer.write_newline();
                constant_declaration.write_combined(writer);
                writer.write_newline();
                type_member_definition.write(writer);
                writer.write_newline();
            }
            else
            {
                writer.write_newline();

                var once = new CCodeOnceSection(get_define_for_filename(writer.filename));
                once.append(new CCodeNewline());
                once.append(include_directives);
                once.append(new CCodeNewline());

                if (begin_decls != null)
                {
                    once.append(new CCodeIdentifier(begin_decls));
                    once.append(new CCodeNewline());
                }

                once.append(new CCodeNewline());
                once.append(type_declaration);
                once.append(new CCodeNewline());
                once.append(type_definition);
                once.append(new CCodeNewline());
                once.append(type_member_declaration);
                once.append(new CCodeNewline());
                once.append(constant_declaration);
                once.append(new CCodeNewline());

                if (begin_decls != null)
                {
                    once.append(new CCodeIdentifier(end_decls));
                    once.append(new CCodeNewline());
                }

                once.append(new CCodeNewline());
                once.write(writer);
            }

            writer.close();

            return(true);
        }