c_builder 1.0.0+6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 66

c_builder

Pub

An API for generating C code in Dart. Especially helpful for compiler development. Supports generating every possible unit of C code.

Example

import 'package:c_builder/c_builder.dart';
import 'package:code_buffer/code_buffer.dart';

/// Generates a simple "Hello, world"
main() {
  var unit = new CompilationUnit()
    ..body.addAll([
      new Include.system('stdio.h'),
      new CFunction(new FunctionSignature(CType.int, 'main')
        ..parameters.addAll([
          new Parameter(CType.int, 'argc'),
          new Parameter(CType.char.pointer().pointer(), 'argv'),
        ]))
        ..comments.addAll([
          'This is the entry point.',
          'The system calls this function when starting the program.'
        ])
        ..body.addAll([
          new Expression.value(0).asReturn(),
        ]),
    ]);
  var buf = new CodeBuffer();
  unit.generate(buf);
  print(buf);
}

1.0.0+5

  • Fixed a bug that caused Fields to generate incorrect code.
  • Added suffix, asFloat, asDouble, and asByte to Expression.
  • Expression.asThrow now returns an Expression.
  • Added CType.auto.

1.0.0+4

  • Added pointerType to FunctionSignature.

1.0.0+3

  • Add size_t, ptrdiff_t.
  • Add invoke to Expression.

1.0.0+2

  • Allow the creation of Enums.
  • Add extern, inline, and enum$ prefixes to CType.
  • Added to _escapeQuotes.

1.0.0+1

  • Fixed a tiny bug where integers would be printed with quotes.

1.0.0

Initial version.

example/main.dart

import 'package:c_builder/c_builder.dart';
import 'package:code_buffer/code_buffer.dart';

/// Generates a simple "Hello, world"
main() {
  var unit = new CompilationUnit()
    ..body.addAll([
      new Include.system('stdio.h'),
      new CFunction(new FunctionSignature(CType.int, 'main')
        ..parameters.addAll([
          new Parameter(CType.int, 'argc'),
          new Parameter(CType.char.pointer().pointer(), 'argv'),
        ]))
        ..comments.addAll([
          'This is the entry point.',
          'The system calls this function when starting the program.'
        ])
        ..body.addAll([
          new Field(
              CType.float, 'myFloat', new Expression.value(32.5).asFloat()),
          new Expression.value(0).asReturn(),
        ]),
    ]);
  var buf = new CodeBuffer();
  unit.generate(buf);
  print(buf);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  c_builder: "^1.0.0+6"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:c_builder/c_builder.dart';
  
Version Uploaded Documentation Archive
1.0.0+6 Mar 14, 2018 Go to the documentation of c_builder 1.0.0+6 Download c_builder 1.0.0+6 archive
1.0.0+5 Mar 14, 2018 Go to the documentation of c_builder 1.0.0+5 Download c_builder 1.0.0+5 archive
1.0.0+4 Mar 10, 2018 Go to the documentation of c_builder 1.0.0+4 Download c_builder 1.0.0+4 archive
1.0.0+3 Mar 10, 2018 Go to the documentation of c_builder 1.0.0+3 Download c_builder 1.0.0+3 archive
1.0.0+2 Mar 10, 2018 Go to the documentation of c_builder 1.0.0+2 Download c_builder 1.0.0+2 archive
1.0.0+1 Mar 10, 2018 Go to the documentation of c_builder 1.0.0+1 Download c_builder 1.0.0+1 archive
1.0.0 Mar 10, 2018 Go to the documentation of c_builder 1.0.0 Download c_builder 1.0.0 archive

Analysis

We analyzed this package on Jul 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
32 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
66
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:c_builder/c_builder.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
code_buffer ^1.0.0 1.0.1
meta ^1.0.0 1.1.5
Transitive dependencies
charcode 1.1.2
path 1.6.1
source_span 1.4.0
Dev dependencies
test ^0.12.0