code stringlengths 1 2.06M | language stringclasses 1 value |
|---|---|
// Copyright 2011 Shannon Weyrick <weyrick@mozek.us>
#ifndef _builder_llvm_SourceDigest_h_
#define _builder_llvm_SourceDigest_h_
#include <string>
#include "md5.h"
namespace builder {
/**
* Class for creating MD5 digests.
*/
class SourceDigest {
// MD5
typedef md5_byte_t digest_byte_t;
static const int digest_size = 16;
SourceDigest::digest_byte_t digest[SourceDigest::digest_size];
public:
SourceDigest(void);
static SourceDigest fromFile(const std::string &path);
static SourceDigest fromHex(const std::string &d);
/**
* Create a source digest of a string.
*/
static SourceDigest fromStr(const std::string &d);
std::string asHex() const;
bool operator==(const SourceDigest &other) const;
bool operator!=(const SourceDigest &other) const;
};
} // end namespace builder
#endif
| C++ |
// Copyright 2011 Shannon Weyrick <weyrick@mozek.us>
#include "CacheFiles.h"
#include "builder/BuilderOptions.h"
#include "spug/StringFmt.h"
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <libgen.h>
using namespace model;
using namespace std;
namespace builder {
namespace {
// recursive mkdir - i.e. ensure the path exists and is readable, and if
// necessary create the path and all parent paths
// returns true if the path can be used successfully
// originally based on idea from
// http://nion.modprobe.de/blog/archives/357-Recursive-directory-creation.html
bool r_mkdir(const char *path) {
char opath[PATH_MAX];
char *p;
size_t len;
if (access(path, R_OK|W_OK) == 0)
return true;
strncpy(opath, path, sizeof(opath));
len = strlen(opath);
if (opath[len - 1] == '/')
opath[len - 1] = '\0';
p = opath;
if (*p == '/')
p++;
for (; *p; p++) {
if (*p == '/') {
*p = '\0';
if (access(opath, F_OK)) {
if (mkdir(opath, S_IRWXU))
return false;
};
*p = '/';
}
}
if (access(opath, F_OK))
mkdir(opath, S_IRWXU);
return (access(opath, R_OK|W_OK) == 0);
}
}
bool initCacheDirectory(BuilderOptions *options) {
string path;
// if the user didn't specify a cache directory, use the default
BuilderOptions::StringMap::const_iterator i =
options->optionMap.find("cachePath");
if (i != options->optionMap.end()) {
// explicit path
path = i->second;
}
if (path.empty()) {
// default path is home dir
// XXX maybe pull out ModulePath from construct for use?
path = getenv("HOME");
if (path.empty()) {
if (options->verbosity)
cerr << "unable to set default cache path, caching disabled\n";
options->cacheMode = false;
return false;
}
if (path.at(path.size()-1) != '/')
path.push_back('/');
path.append(".crack/cache/");
}
// at this point we have some string they specified on the command line
// OR the value of the HOME env variable
if (path.at(path.size()-1) != '/')
path.push_back('/');
if (r_mkdir(path.c_str()))
options->optionMap["cachePath"] = path;
else {
if (options->verbosity)
cerr << "no access to create/use cache path, caching disabled: " <<
path << "\n";
options->cacheMode = false;
return false;
}
return true;
}
string getCacheFilePath(BuilderOptions* options,
const std::string &canonicalName,
const std::string &destExt) {
// at this point, initCacheDirectory should have ensured we have a path
BuilderOptions::StringMap::const_iterator i =
options->optionMap.find("cachePath");
// if we didn't find the cache path, try initializing the cache directory
// before failing.
if (i == options->optionMap.end()) {
if (!initCacheDirectory(options))
return string();
else
i = options->optionMap.find("cachePath");
}
return SPUG_FSTR(i->second << "/" << canonicalName << '.' << destExt);
#if 0
// get the canonicalized path - if that doesn't work, we have to assume
// that this is a path to a nonexistent file.
char rpath[PATH_MAX + 1];
if (!realpath(path.c_str(), rpath))
strcpy(rpath, path.c_str());
assert(*rpath == '/' && "not absolute");
char *rpathd = strdup(rpath);
char *rpathf = strdup(rpath);
assert(rpathd); assert(rpathf);
char *rpathdir = dirname(rpathd);
char *rpathfile = basename(rpathf);
finalPath.append(rpathdir+1);
finalPath.push_back('/');
if (!r_mkdir(finalPath.c_str())) {
if (options->verbosity)
cerr << "unable to create cache path for: " <<
finalPath << "\n";
return NULL;
}
finalPath.append(rpathfile);
finalPath.push_back('.');
finalPath.append(destExt);
free(rpathd);
free(rpathf);
// XXX add in opt level?
return finalPath;
#endif
}
}
| C++ |
// Copyright 2011 Shannon Weyrick <weyrick@mozek.us>
#include "SourceDigest.h"
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace builder;
using namespace std;
namespace {
void md5_hashSourceText(istream &src, md5_byte_t digest[16]) {
md5_state_t state;
#define MD5_SOURCE_PAGE_SIZE 1024
char buf[MD5_SOURCE_PAGE_SIZE];
md5_init(&state);
// XXX do we want to skip whitespace and comments?
while (!src.eof()) {
src.read(buf, MD5_SOURCE_PAGE_SIZE);
md5_append(&state, (const md5_byte_t *)buf, src.gcount());
}
md5_finish(&state, digest);
}
}
SourceDigest::SourceDigest() {
memset(&digest, 0, SourceDigest::digest_size);
}
SourceDigest SourceDigest::fromFile(const std::string &path) {
ifstream src;
src.open(path.c_str());
if (!src.good())
return SourceDigest();
// MD5
SourceDigest d;
md5_hashSourceText(src, d.digest);
return d;
}
SourceDigest SourceDigest::fromStr(const string &str) {
SourceDigest d;
istringstream src(str);
md5_hashSourceText(src, d.digest);
return d;
}
SourceDigest SourceDigest::fromHex(const std::string &d) {
SourceDigest result;
if (d.length() != SourceDigest::digest_size*2)
return result;
const char *buf = d.c_str();
char pos[3];
pos[2] = 0;
for (int di = 0; di < SourceDigest::digest_size; ++di) {
pos[0] = *(buf+di*2);
pos[1] = *((buf+di*2)+1);
result.digest[di] = (digest_byte_t)strtol((const char*)&pos, NULL, 16);
}
return result;
}
string SourceDigest::asHex() const {
char buf[SourceDigest::digest_size*2];
for (int di = 0; di < SourceDigest::digest_size; ++di)
sprintf(buf + di * 2, "%02x", digest[di]);
return string(buf, SourceDigest::digest_size*2);
}
bool SourceDigest::operator==(const SourceDigest &other) const {
return (memcmp(digest, other.digest, SourceDigest::digest_size) == 0);
}
bool SourceDigest::operator!=(const SourceDigest &other) const {
return (memcmp(digest, other.digest, SourceDigest::digest_size) != 0);
}
| C++ |
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-ps.h>
#include <cairo/cairo-svg.h>
#include <cairo/cairo-xlib.h>
#include <stdio.h>
#include <cairo/cairo-features.h>
#include <X11/Xlib.h>
#ifndef CAIRO_HAS_FC_FONT
# define CAIRO_HAS_FC_FONT 0
#endif
#ifndef CAIRO_HAS_FT_FONT
# define CAIRO_HAS_FT_FONT 0
#endif
#ifndef CAIRO_HAS_GOBJECT_FUNCTIONS
# define CAIRO_HAS_GOBJECT_FUNCTIONS 0
#endif
#ifndef CAIRO_HAS_IMAGE_SURFACE
# define CAIRO_HAS_IMAGE_SURFACE 0
#endif
#ifndef CAIRO_HAS_PDF_SURFACE
# define CAIRO_HAS_PDF_SURFACE 0
#endif
#ifndef CAIRO_HAS_PNG_FUNCTIONS
# define CAIRO_HAS_PNG_FUNCTIONS 0
#endif
#ifndef CAIRO_HAS_PS_SURFACE
# define CAIRO_HAS_PS_SURFACE 0
#endif
#ifndef CAIRO_HAS_RECORDING_SURFACE
# define CAIRO_HAS_RECORDING_SURFACE 0
#endif
#ifndef CAIRO_HAS_SVG_SURFACE
# define CAIRO_HAS_SVG_SURFACE 0
#endif
#ifndef CAIRO_HAS_USER_FONT
# define CAIRO_HAS_USER_FONT 0
#endif
#ifndef CAIRO_HAS_XCB_SHM_FUNCTIONS
# define CAIRO_HAS_XCB_SHM_FUNCTIONS 0
#endif
#ifndef CAIRO_HAS_XCB_SURFACE
# define CAIRO_HAS_XCB_SURFACE 0
#endif
#ifndef CAIRO_HAS_XLIB_SURFACE
# define CAIRO_HAS_XLIB_SURFACE 0
#endif
#ifndef CAIRO_HAS_XLIB_XRENDER_SURFACE
# define CAIRO_HAS_XLIB_XRENDER_SURFACE 0
#endif
typedef int Undef;
cairo_matrix_t *cairo_matrix_new() { return new cairo_matrix_t; }
cairo_rectangle_t *cairo_rectangle_new() { return new cairo_rectangle_t; }
cairo_rectangle_list_t *cairo_rectangle_list_new() { return new cairo_rectangle_list_t; }
cairo_text_extents_t *cairo_text_extents_new() { return new cairo_text_extents_t; }
cairo_font_extents_t *cairo_font_extents_new() { return new cairo_font_extents_t; }
cairo_surface_t *cairo_surface_new(cairo_surface_t *existing_surface) {
return existing_surface;
}
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__cairo_rinit() {
return;
}
extern "C"
void crack_ext__cairo_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int16 = mod->getInt16Type();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint16 = mod->getUint16Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_cairo_t = mod->addType("cairo_t", sizeof(Undef));
type_cairo_t->finish();
crack::ext::Type *type_cairo_surface_t = mod->addType("cairo_surface_t", sizeof(Undef));
type_cairo_surface_t->finish();
crack::ext::Type *type_cairo_device_t = mod->addType("cairo_device_t", sizeof(Undef));
type_cairo_device_t->finish();
crack::ext::Type *type_cairo_matrix_t = mod->addType("cairo_matrix_t", sizeof(cairo_matrix_t));
type_cairo_matrix_t->addInstVar(type_float64, "xx",
CRACK_OFFSET(cairo_matrix_t, xx));
type_cairo_matrix_t->addInstVar(type_float64, "yx",
CRACK_OFFSET(cairo_matrix_t, yx));
type_cairo_matrix_t->addInstVar(type_float64, "xy",
CRACK_OFFSET(cairo_matrix_t, xy));
type_cairo_matrix_t->addInstVar(type_float64, "yy",
CRACK_OFFSET(cairo_matrix_t, yy));
type_cairo_matrix_t->addInstVar(type_float64, "x0",
CRACK_OFFSET(cairo_matrix_t, x0));
type_cairo_matrix_t->addInstVar(type_float64, "y0",
CRACK_OFFSET(cairo_matrix_t, y0));
type_cairo_matrix_t->finish();
crack::ext::Type *type_cairo_user_data_key_t = mod->addType("cairo_user_data_key_t", sizeof(cairo_user_data_key_t));
type_cairo_user_data_key_t->finish();
crack::ext::Type *type_cairo_pattern_t = mod->addType("cairo_pattern_t", sizeof(Undef));
type_cairo_pattern_t->finish();
crack::ext::Type *type_cairo_rectangle_t = mod->addType("cairo_rectangle_t", sizeof(cairo_rectangle_t));
type_cairo_rectangle_t->addInstVar(type_float64, "x",
CRACK_OFFSET(cairo_rectangle_t, x));
type_cairo_rectangle_t->addInstVar(type_float64, "y",
CRACK_OFFSET(cairo_rectangle_t, y));
type_cairo_rectangle_t->addInstVar(type_float64, "width",
CRACK_OFFSET(cairo_rectangle_t, width));
type_cairo_rectangle_t->addInstVar(type_float64, "height",
CRACK_OFFSET(cairo_rectangle_t, height));
type_cairo_rectangle_t->finish();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pcairo__rectangle__t_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_cairo_rectangle_t;
array_pcairo__rectangle__t_q = array->getSpecialization(params);
}
crack::ext::Type *type_cairo_rectangle_list_t = mod->addType("cairo_rectangle_list_t", sizeof(cairo_rectangle_list_t));
type_cairo_rectangle_list_t->addInstVar(type_uint, "status",
CRACK_OFFSET(cairo_rectangle_list_t, status));
type_cairo_rectangle_list_t->addInstVar(array_pcairo__rectangle__t_q, "rectangles",
CRACK_OFFSET(cairo_rectangle_list_t, rectangles));
type_cairo_rectangle_list_t->addInstVar(type_int, "num_rectangles",
CRACK_OFFSET(cairo_rectangle_list_t, num_rectangles));
f = type_cairo_rectangle_list_t->addConstructor("init",
(void *)cairo_rectangle_list_destroy
);
f->addArg(type_cairo_rectangle_list_t, "rectangle_list");
type_cairo_rectangle_list_t->finish();
crack::ext::Type *type_cairo_scaled_font_t = mod->addType("cairo_scaled_font_t", sizeof(Undef));
type_cairo_scaled_font_t->finish();
crack::ext::Type *type_cairo_font_face_t = mod->addType("cairo_font_face_t", sizeof(Undef));
type_cairo_font_face_t->finish();
crack::ext::Type *type_cairo_operator_t = mod->addType("cairo_operator_t", sizeof(uint));
type_cairo_operator_t->finish();
crack::ext::Type *type_cairo_glyph_t = mod->addType("cairo_glyph_t", sizeof(cairo_glyph_t));
type_cairo_glyph_t->finish();
crack::ext::Type *type_cairo_text_cluster_t = mod->addType("cairo_text_cluster_t", sizeof(cairo_text_cluster_t));
type_cairo_text_cluster_t->finish();
crack::ext::Type *type_cairo_text_extents_t = mod->addType("cairo_text_extents_t", sizeof(cairo_text_extents_t));
type_cairo_text_extents_t->addInstVar(type_float64, "x_bearing",
CRACK_OFFSET(cairo_text_extents_t, x_bearing));
type_cairo_text_extents_t->addInstVar(type_float64, "y_bearing",
CRACK_OFFSET(cairo_text_extents_t, y_bearing));
type_cairo_text_extents_t->addInstVar(type_float64, "width",
CRACK_OFFSET(cairo_text_extents_t, width));
type_cairo_text_extents_t->addInstVar(type_float64, "height",
CRACK_OFFSET(cairo_text_extents_t, height));
type_cairo_text_extents_t->addInstVar(type_float64, "x_advance",
CRACK_OFFSET(cairo_text_extents_t, x_advance));
type_cairo_text_extents_t->addInstVar(type_float64, "y_advance",
CRACK_OFFSET(cairo_text_extents_t, y_advance));
type_cairo_text_extents_t->finish();
crack::ext::Type *type_cairo_font_extents_t = mod->addType("cairo_font_extents_t", sizeof(cairo_font_extents_t));
type_cairo_font_extents_t->addInstVar(type_float64, "ascent",
CRACK_OFFSET(cairo_font_extents_t, ascent));
type_cairo_font_extents_t->addInstVar(type_float64, "descent",
CRACK_OFFSET(cairo_font_extents_t, descent));
type_cairo_font_extents_t->addInstVar(type_float64, "height",
CRACK_OFFSET(cairo_font_extents_t, height));
type_cairo_font_extents_t->addInstVar(type_float64, "max_x_advance",
CRACK_OFFSET(cairo_font_extents_t, max_x_advance));
type_cairo_font_extents_t->addInstVar(type_float64, "max_y_advance",
CRACK_OFFSET(cairo_font_extents_t, max_y_advance));
type_cairo_font_extents_t->finish();
crack::ext::Type *type_cairo_font_options_t = mod->addType("cairo_font_options_t", sizeof(Undef));
type_cairo_font_options_t->finish();
crack::ext::Type *type_cairo_path_data_t = mod->addType("cairo_path_data_t", sizeof(cairo_path_data_t));
type_cairo_path_data_t->finish();
crack::ext::Type *type_cairo_path_t = mod->addType("cairo_path_t", sizeof(cairo_path_t));
type_cairo_path_t->finish();
crack::ext::Type *type_cairo_rectangle_int_t = mod->addType("cairo_rectangle_int_t", sizeof(cairo_rectangle_int_t));
type_cairo_rectangle_int_t->finish();
crack::ext::Type *type_cairo_region_t = mod->addType("cairo_region_t", sizeof(Undef));
type_cairo_region_t->finish();
crack::ext::Type *array_pfloat64_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_float64;
array_pfloat64_q = array->getSpecialization(params);
}
crack::ext::Type *array_puint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_uint;
array_puint_q = array->getSpecialization(params);
}
crack::ext::Type *array_pcairo__glyph__t_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_cairo_glyph_t;
array_pcairo__glyph__t_q = array->getSpecialization(params);
}
crack::ext::Type *function = mod->getType("function");
crack::ext::Type *function_pvoid_c_svoidptr_q;
{
std::vector<crack::ext::Type *> params(2);
params[0] = type_void;
params[1] = type_voidptr;
function_pvoid_c_svoidptr_q = function->getSpecialization(params);
}
crack::ext::Type *array_pcairo__text__cluster__t_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_cairo_text_cluster_t;
array_pcairo__text__cluster__t_q = array->getSpecialization(params);
}
#ifdef CAIRO_HAS_PNG_FUNCTIONS
crack::ext::Type *function_puint_c_svoidptr_c_sbyteptr_c_suint_q;
{
std::vector<crack::ext::Type *> params(4);
params[0] = type_uint;
params[1] = type_voidptr;
params[2] = type_byteptr;
params[3] = type_uint;
function_puint_c_svoidptr_c_sbyteptr_c_suint_q = function->getSpecialization(params);
}
#endif // CAIRO_HAS_PNG_FUNCTIONS
crack::ext::Type *array_pbyteptr_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_byteptr;
array_pbyteptr_q = array->getSpecialization(params);
}
crack::ext::Type *array_puint64_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_uint64;
array_puint64_q = array->getSpecialization(params);
}
crack::ext::Type *array_pint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_int;
array_pint_q = array->getSpecialization(params);
}
crack::ext::Type *type_Display = mod->addType("Display", sizeof(Undef));
type_Display->finish();
crack::ext::Type *type_Drawable = mod->addType("Drawable", sizeof(Drawable));
type_Drawable->finish();
crack::ext::Type *type_Visual = mod->addType("Visual", sizeof(Visual));
type_Visual->finish();
crack::ext::Type *type_Pixmap = mod->addType("Pixmap", sizeof(Pixmap));
type_Pixmap->finish();
crack::ext::Type *type_Screen = mod->addType("Screen", sizeof(Screen));
type_Screen->finish();
f = mod->addFunc(type_cairo_matrix_t, "cairo_matrix_new",
(void *)cairo_matrix_new
);
f = mod->addFunc(type_cairo_rectangle_t, "cairo_rectangle_new",
(void *)cairo_rectangle_new
);
f = mod->addFunc(type_cairo_rectangle_list_t, "cairo_rectangle_list_new",
(void *)cairo_rectangle_list_new
);
f = mod->addFunc(type_cairo_text_extents_t, "cairo_text_extents_new",
(void *)cairo_text_extents_new
);
f = mod->addFunc(type_cairo_font_extents_t, "cairo_font_extents_new",
(void *)cairo_font_extents_new
);
f = mod->addFunc(type_cairo_t, "cairo_create",
(void *)cairo_create
);
f->addArg(type_cairo_surface_t, "target");
f = mod->addFunc(type_cairo_t, "cairo_reference",
(void *)cairo_reference
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_destroy",
(void *)cairo_destroy
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_uint, "cairo_get_reference_count",
(void *)cairo_get_reference_count
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_save",
(void *)cairo_save
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_restore",
(void *)cairo_restore
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_push_group",
(void *)cairo_push_group
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pop_group",
(void *)cairo_pop_group
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_pop_group_to_source",
(void *)cairo_pop_group_to_source
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_set_operator",
(void *)cairo_set_operator
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_uint, "op");
f = mod->addFunc(type_void, "cairo_set_source",
(void *)cairo_set_source
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_pattern_t, "source");
f = mod->addFunc(type_void, "cairo_set_source_rgb",
(void *)cairo_set_source_rgb
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f = mod->addFunc(type_void, "cairo_set_source_rgba",
(void *)cairo_set_source_rgba
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f->addArg(type_float64, "alpha");
f = mod->addFunc(type_void, "cairo_set_source_surface",
(void *)cairo_set_source_surface
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_void, "cairo_set_tolerance",
(void *)cairo_set_tolerance
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "tolerance");
f = mod->addFunc(type_void, "cairo_set_antialias",
(void *)cairo_set_antialias
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_uint, "antialias");
f = mod->addFunc(type_void, "cairo_set_fill_rule",
(void *)cairo_set_fill_rule
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_uint, "fill_rule");
f = mod->addFunc(type_void, "cairo_set_line_width",
(void *)cairo_set_line_width
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "width");
f = mod->addFunc(type_void, "cairo_set_line_cap",
(void *)cairo_set_line_cap
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_uint, "line_cap");
f = mod->addFunc(type_void, "cairo_set_line_join",
(void *)cairo_set_line_join
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_uint, "line_join");
f = mod->addFunc(type_void, "cairo_set_dash",
(void *)cairo_set_dash
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "dashes");
f->addArg(type_int, "num_dashes");
f->addArg(type_float64, "offset");
f = mod->addFunc(type_void, "cairo_set_miter_limit",
(void *)cairo_set_miter_limit
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "limit");
f = mod->addFunc(type_void, "cairo_translate",
(void *)cairo_translate
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "tx");
f->addArg(type_float64, "ty");
f = mod->addFunc(type_void, "cairo_scale",
(void *)cairo_scale
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "sx");
f->addArg(type_float64, "sy");
f = mod->addFunc(type_void, "cairo_rotate",
(void *)cairo_rotate
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "angle");
f = mod->addFunc(type_void, "cairo_transform",
(void *)cairo_transform
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_set_matrix",
(void *)cairo_set_matrix
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_identity_matrix",
(void *)cairo_identity_matrix
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_user_to_device",
(void *)cairo_user_to_device
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x");
f->addArg(array_pfloat64_q, "y");
f = mod->addFunc(type_void, "cairo_user_to_device_distance",
(void *)cairo_user_to_device_distance
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "dx");
f->addArg(array_pfloat64_q, "dy");
f = mod->addFunc(type_void, "cairo_device_to_user",
(void *)cairo_device_to_user
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x");
f->addArg(array_pfloat64_q, "y");
f = mod->addFunc(type_void, "cairo_device_to_user_distance",
(void *)cairo_device_to_user_distance
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "dx");
f->addArg(array_pfloat64_q, "dy");
f = mod->addFunc(type_void, "cairo_new_path",
(void *)cairo_new_path
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_move_to",
(void *)cairo_move_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_void, "cairo_new_sub_path",
(void *)cairo_new_sub_path
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_line_to",
(void *)cairo_line_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_void, "cairo_curve_to",
(void *)cairo_curve_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x1");
f->addArg(type_float64, "y1");
f->addArg(type_float64, "x2");
f->addArg(type_float64, "y2");
f->addArg(type_float64, "x3");
f->addArg(type_float64, "y3");
f = mod->addFunc(type_void, "cairo_arc",
(void *)cairo_arc
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "xc");
f->addArg(type_float64, "yc");
f->addArg(type_float64, "radius");
f->addArg(type_float64, "angle1");
f->addArg(type_float64, "angle2");
f = mod->addFunc(type_void, "cairo_arc_negative",
(void *)cairo_arc_negative
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "xc");
f->addArg(type_float64, "yc");
f->addArg(type_float64, "radius");
f->addArg(type_float64, "angle1");
f->addArg(type_float64, "angle2");
f = mod->addFunc(type_void, "cairo_rel_move_to",
(void *)cairo_rel_move_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "dx");
f->addArg(type_float64, "dy");
f = mod->addFunc(type_void, "cairo_rel_line_to",
(void *)cairo_rel_line_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "dx");
f->addArg(type_float64, "dy");
f = mod->addFunc(type_void, "cairo_rel_curve_to",
(void *)cairo_rel_curve_to
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "dx1");
f->addArg(type_float64, "dy1");
f->addArg(type_float64, "dx2");
f->addArg(type_float64, "dy2");
f->addArg(type_float64, "dx3");
f->addArg(type_float64, "dy3");
f = mod->addFunc(type_void, "cairo_rectangle",
(void *)cairo_rectangle
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_float64, "width");
f->addArg(type_float64, "height");
f = mod->addFunc(type_void, "cairo_close_path",
(void *)cairo_close_path
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_path_extents",
(void *)cairo_path_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f->addArg(array_pfloat64_q, "x2");
f->addArg(array_pfloat64_q, "y2");
f = mod->addFunc(type_void, "cairo_paint",
(void *)cairo_paint
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_paint_with_alpha",
(void *)cairo_paint_with_alpha
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "alpha");
f = mod->addFunc(type_void, "cairo_mask",
(void *)cairo_mask
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_void, "cairo_mask_surface",
(void *)cairo_mask_surface
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "surface_x");
f->addArg(type_float64, "surface_y");
f = mod->addFunc(type_void, "cairo_stroke",
(void *)cairo_stroke
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_stroke_preserve",
(void *)cairo_stroke_preserve
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_fill",
(void *)cairo_fill
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_fill_preserve",
(void *)cairo_fill_preserve
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_copy_page",
(void *)cairo_copy_page
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_show_page",
(void *)cairo_show_page
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_bool, "cairo_in_stroke",
(void *)cairo_in_stroke
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_bool, "cairo_in_fill",
(void *)cairo_in_fill
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_bool, "cairo_in_clip",
(void *)cairo_in_clip
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_void, "cairo_stroke_extents",
(void *)cairo_stroke_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f->addArg(array_pfloat64_q, "x2");
f->addArg(array_pfloat64_q, "y2");
f = mod->addFunc(type_void, "cairo_fill_extents",
(void *)cairo_fill_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f->addArg(array_pfloat64_q, "x2");
f->addArg(array_pfloat64_q, "y2");
f = mod->addFunc(type_void, "cairo_reset_clip",
(void *)cairo_reset_clip
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_clip",
(void *)cairo_clip
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_clip_preserve",
(void *)cairo_clip_preserve
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_clip_extents",
(void *)cairo_clip_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f->addArg(array_pfloat64_q, "x2");
f->addArg(array_pfloat64_q, "y2");
f = mod->addFunc(type_cairo_rectangle_list_t, "cairo_copy_clip_rectangle_list",
(void *)cairo_copy_clip_rectangle_list
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_rectangle_list_destroy",
(void *)cairo_rectangle_list_destroy
);
f->addArg(type_cairo_rectangle_list_t, "rectangle_list");
f = mod->addFunc(type_cairo_glyph_t, "cairo_glyph_allocate",
(void *)cairo_glyph_allocate
);
f->addArg(type_int, "num_glyphs");
f = mod->addFunc(type_void, "cairo_glyph_free",
(void *)cairo_glyph_free
);
f->addArg(type_cairo_glyph_t, "glyphs");
f = mod->addFunc(type_cairo_text_cluster_t, "cairo_text_cluster_allocate",
(void *)cairo_text_cluster_allocate
);
f->addArg(type_int, "num_clusters");
f = mod->addFunc(type_void, "cairo_text_cluster_free",
(void *)cairo_text_cluster_free
);
f->addArg(type_cairo_text_cluster_t, "clusters");
f = mod->addFunc(type_cairo_font_options_t, "cairo_font_options_create",
(void *)cairo_font_options_create
);
f = mod->addFunc(type_cairo_font_options_t, "cairo_font_options_copy",
(void *)cairo_font_options_copy
);
f->addArg(type_cairo_font_options_t, "original");
f = mod->addFunc(type_void, "cairo_font_options_destroy",
(void *)cairo_font_options_destroy
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_uint, "cairo_font_options_status",
(void *)cairo_font_options_status
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_font_options_merge",
(void *)cairo_font_options_merge
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_cairo_font_options_t, "other");
f = mod->addFunc(type_bool, "cairo_font_options_equal",
(void *)cairo_font_options_equal
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_cairo_font_options_t, "other");
f = mod->addFunc(type_uint64, "cairo_font_options_hash",
(void *)cairo_font_options_hash
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_font_options_set_antialias",
(void *)cairo_font_options_set_antialias
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_uint, "antialias");
f = mod->addFunc(type_uint, "cairo_font_options_get_antialias",
(void *)cairo_font_options_get_antialias
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_font_options_set_subpixel_order",
(void *)cairo_font_options_set_subpixel_order
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_uint, "subpixel_order");
f = mod->addFunc(type_uint, "cairo_font_options_get_subpixel_order",
(void *)cairo_font_options_get_subpixel_order
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_font_options_set_hint_style",
(void *)cairo_font_options_set_hint_style
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_uint, "hint_style");
f = mod->addFunc(type_uint, "cairo_font_options_get_hint_style",
(void *)cairo_font_options_get_hint_style
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_font_options_set_hint_metrics",
(void *)cairo_font_options_set_hint_metrics
);
f->addArg(type_cairo_font_options_t, "options");
f->addArg(type_uint, "hint_metrics");
f = mod->addFunc(type_uint, "cairo_font_options_get_hint_metrics",
(void *)cairo_font_options_get_hint_metrics
);
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_select_font_face",
(void *)cairo_select_font_face
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_byteptr, "family");
f->addArg(type_uint, "slant");
f->addArg(type_uint, "weight");
f = mod->addFunc(type_void, "cairo_set_font_size",
(void *)cairo_set_font_size
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_float64, "size");
f = mod->addFunc(type_void, "cairo_set_font_matrix",
(void *)cairo_set_font_matrix
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_get_font_matrix",
(void *)cairo_get_font_matrix
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_set_font_options",
(void *)cairo_set_font_options
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_get_font_options",
(void *)cairo_get_font_options
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_set_font_face",
(void *)cairo_set_font_face
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_cairo_font_face_t, "cairo_get_font_face",
(void *)cairo_get_font_face
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_set_scaled_font",
(void *)cairo_set_scaled_font
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_cairo_scaled_font_t, "cairo_get_scaled_font",
(void *)cairo_get_scaled_font
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_show_text",
(void *)cairo_show_text
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_byteptr, "utf8");
f = mod->addFunc(type_void, "cairo_show_glyphs",
(void *)cairo_show_glyphs
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_glyph_t, "glyphs");
f->addArg(type_int, "num_glyphs");
f = mod->addFunc(type_void, "cairo_show_text_glyphs",
(void *)cairo_show_text_glyphs
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_byteptr, "utf8");
f->addArg(type_int, "utf8_len");
f->addArg(type_cairo_glyph_t, "glyphs");
f->addArg(type_int, "num_glyphs");
f->addArg(type_cairo_text_cluster_t, "clusters");
f->addArg(type_int, "num_clusters");
f->addArg(array_puint_q, "cluster_flags");
f = mod->addFunc(type_void, "cairo_text_path",
(void *)cairo_text_path
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_byteptr, "utf8");
f = mod->addFunc(type_void, "cairo_glyph_path",
(void *)cairo_glyph_path
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_glyph_t, "glyphs");
f->addArg(type_int, "num_glyphs");
f = mod->addFunc(type_void, "cairo_text_extents",
(void *)cairo_text_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_byteptr, "utf8");
f->addArg(type_cairo_text_extents_t, "extents");
f = mod->addFunc(type_void, "cairo_glyph_extents",
(void *)cairo_glyph_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pcairo__glyph__t_q, "glyphs");
f->addArg(type_int, "num_glyphs");
f->addArg(type_cairo_text_extents_t, "extents");
f = mod->addFunc(type_void, "cairo_font_extents",
(void *)cairo_font_extents
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_font_extents_t, "extents");
f = mod->addFunc(type_cairo_font_face_t, "cairo_font_face_reference",
(void *)cairo_font_face_reference
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_void, "cairo_font_face_destroy",
(void *)cairo_font_face_destroy
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_uint, "cairo_font_face_get_reference_count",
(void *)cairo_font_face_get_reference_count
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_uint, "cairo_font_face_status",
(void *)cairo_font_face_status
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_uint, "cairo_font_face_get_type",
(void *)cairo_font_face_get_type
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_void, "cairo_font_face_get_user_data",
(void *)cairo_font_face_get_user_data
);
f->addArg(type_cairo_font_face_t, "font_face");
f->addArg(type_cairo_user_data_key_t, "key");
f = mod->addFunc(type_uint, "cairo_font_face_set_user_data",
(void *)cairo_font_face_set_user_data
);
f->addArg(type_cairo_font_face_t, "font_face");
f->addArg(type_cairo_user_data_key_t, "key");
f->addArg(type_voidptr, "user_data");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f = mod->addFunc(type_cairo_scaled_font_t, "cairo_scaled_font_create",
(void *)cairo_scaled_font_create
);
f->addArg(type_cairo_font_face_t, "font_face");
f->addArg(type_cairo_matrix_t, "font_matrix");
f->addArg(type_cairo_matrix_t, "ctm");
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_cairo_scaled_font_t, "cairo_scaled_font_reference",
(void *)cairo_scaled_font_reference
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_void, "cairo_scaled_font_destroy",
(void *)cairo_scaled_font_destroy
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_uint, "cairo_scaled_font_get_reference_count",
(void *)cairo_scaled_font_get_reference_count
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_uint, "cairo_scaled_font_status",
(void *)cairo_scaled_font_status
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_uint, "cairo_scaled_font_get_type",
(void *)cairo_scaled_font_get_type
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_void, "cairo_scaled_font_get_user_data",
(void *)cairo_scaled_font_get_user_data
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_user_data_key_t, "key");
f = mod->addFunc(type_uint, "cairo_scaled_font_set_user_data",
(void *)cairo_scaled_font_set_user_data
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_user_data_key_t, "key");
f->addArg(type_voidptr, "user_data");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f = mod->addFunc(type_void, "cairo_scaled_font_extents",
(void *)cairo_scaled_font_extents
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_font_extents_t, "extents");
f = mod->addFunc(type_void, "cairo_scaled_font_text_extents",
(void *)cairo_scaled_font_text_extents
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_byteptr, "utf8");
f->addArg(type_cairo_text_extents_t, "extents");
f = mod->addFunc(type_void, "cairo_scaled_font_glyph_extents",
(void *)cairo_scaled_font_glyph_extents
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(array_pcairo__glyph__t_q, "glyphs");
f->addArg(type_int, "num_glyphs");
f->addArg(type_cairo_text_extents_t, "extents");
f = mod->addFunc(type_uint, "cairo_scaled_font_text_to_glyphs",
(void *)cairo_scaled_font_text_to_glyphs
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_byteptr, "utf8");
f->addArg(type_int, "utf8_len");
f->addArg(array_pcairo__glyph__t_q, "glyphs");
f->addArg(type_int, "num_glyphs");
f->addArg(array_pcairo__text__cluster__t_q, "clusters");
f->addArg(type_int, "num_clusters");
f->addArg(array_puint_q, "cluster_flags");
f = mod->addFunc(type_cairo_font_face_t, "cairo_scaled_font_get_font_face",
(void *)cairo_scaled_font_get_font_face
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f = mod->addFunc(type_void, "cairo_scaled_font_get_font_matrix",
(void *)cairo_scaled_font_get_font_matrix
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_matrix_t, "font_matrix");
f = mod->addFunc(type_void, "cairo_scaled_font_get_ctm",
(void *)cairo_scaled_font_get_ctm
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_matrix_t, "ctm");
f = mod->addFunc(type_void, "cairo_scaled_font_get_scale_matrix",
(void *)cairo_scaled_font_get_scale_matrix
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_matrix_t, "scale_matrix");
f = mod->addFunc(type_void, "cairo_scaled_font_get_font_options",
(void *)cairo_scaled_font_get_font_options
);
f->addArg(type_cairo_scaled_font_t, "scaled_font");
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_cairo_font_face_t, "cairo_toy_font_face_create",
(void *)cairo_toy_font_face_create
);
f->addArg(type_byteptr, "family");
f->addArg(type_uint, "slant");
f->addArg(type_uint, "weight");
f = mod->addFunc(type_byteptr, "cairo_toy_font_face_get_family",
(void *)cairo_toy_font_face_get_family
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_uint, "cairo_toy_font_face_get_slant",
(void *)cairo_toy_font_face_get_slant
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_uint, "cairo_toy_font_face_get_weight",
(void *)cairo_toy_font_face_get_weight
);
f->addArg(type_cairo_font_face_t, "font_face");
f = mod->addFunc(type_cairo_font_face_t, "cairo_user_font_face_create",
(void *)cairo_user_font_face_create
);
f = mod->addFunc(type_uint, "cairo_get_operator",
(void *)cairo_get_operator
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_cairo_pattern_t, "cairo_get_source",
(void *)cairo_get_source
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_float64, "cairo_get_tolerance",
(void *)cairo_get_tolerance
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_uint, "cairo_get_antialias",
(void *)cairo_get_antialias
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_bool, "cairo_has_current_point",
(void *)cairo_has_current_point
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_get_current_point",
(void *)cairo_get_current_point
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "x");
f->addArg(array_pfloat64_q, "y");
f = mod->addFunc(type_uint, "cairo_get_fill_rule",
(void *)cairo_get_fill_rule
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_float64, "cairo_get_line_width",
(void *)cairo_get_line_width
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_uint, "cairo_get_line_cap",
(void *)cairo_get_line_cap
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_uint, "cairo_get_line_join",
(void *)cairo_get_line_join
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_float64, "cairo_get_miter_limit",
(void *)cairo_get_miter_limit
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_int, "cairo_get_dash_count",
(void *)cairo_get_dash_count
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_get_dash",
(void *)cairo_get_dash
);
f->addArg(type_cairo_t, "cr");
f->addArg(array_pfloat64_q, "dashes");
f->addArg(array_pfloat64_q, "offset");
f = mod->addFunc(type_void, "cairo_get_matrix",
(void *)cairo_get_matrix
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_cairo_surface_t, "cairo_get_target",
(void *)cairo_get_target
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_cairo_surface_t, "cairo_get_group_target",
(void *)cairo_get_group_target
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_cairo_path_t, "cairo_copy_path",
(void *)cairo_copy_path
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_cairo_path_t, "cairo_copy_path_flat",
(void *)cairo_copy_path_flat
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairo_append_path",
(void *)cairo_append_path
);
f->addArg(type_cairo_t, "cr");
f->addArg(type_cairo_path_t, "path");
f = mod->addFunc(type_void, "cairo_path_destroy",
(void *)cairo_path_destroy
);
f->addArg(type_cairo_path_t, "path");
f = mod->addFunc(type_uint, "cairo_status",
(void *)cairo_status
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_byteptr, "cairo_status_to_string",
(void *)cairo_status_to_string
);
f->addArg(type_uint, "status");
f = mod->addFunc(type_cairo_device_t, "cairo_device_reference",
(void *)cairo_device_reference
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_uint, "cairo_device_get_type",
(void *)cairo_device_get_type
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_uint, "cairo_device_status",
(void *)cairo_device_status
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_uint, "cairo_device_acquire",
(void *)cairo_device_acquire
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_void, "cairo_device_release",
(void *)cairo_device_release
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_void, "cairo_device_flush",
(void *)cairo_device_flush
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_void, "cairo_device_finish",
(void *)cairo_device_finish
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_void, "cairo_device_destroy",
(void *)cairo_device_destroy
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_uint, "cairo_device_get_reference_count",
(void *)cairo_device_get_reference_count
);
f->addArg(type_cairo_device_t, "device");
f = mod->addFunc(type_voidptr, "cairo_device_get_user_data",
(void *)cairo_device_get_user_data
);
f->addArg(type_cairo_device_t, "device");
f->addArg(type_cairo_user_data_key_t, "key");
f = mod->addFunc(type_uint, "cairo_device_set_user_data",
(void *)cairo_device_set_user_data
);
f->addArg(type_cairo_device_t, "device");
f->addArg(type_cairo_user_data_key_t, "key");
f->addArg(type_voidptr, "user_data");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f = mod->addFunc(type_cairo_surface_t, "cairo_surface_create_similar",
(void *)cairo_surface_create_similar
);
f->addArg(type_cairo_surface_t, "other");
f->addArg(type_uint, "content");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_cairo_surface_t, "cairo_surface_create_for_rectangle",
(void *)cairo_surface_create_for_rectangle
);
f->addArg(type_cairo_surface_t, "target");
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_float64, "width");
f->addArg(type_float64, "height");
f = mod->addFunc(type_cairo_surface_t, "cairo_surface_reference",
(void *)cairo_surface_reference
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_surface_finish",
(void *)cairo_surface_finish
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_surface_destroy",
(void *)cairo_surface_destroy
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_cairo_device_t, "cairo_surface_get_device",
(void *)cairo_surface_get_device
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_surface_get_reference_count",
(void *)cairo_surface_get_reference_count
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_surface_status",
(void *)cairo_surface_status
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_surface_get_type",
(void *)cairo_surface_get_type
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_surface_get_content",
(void *)cairo_surface_get_content
);
f->addArg(type_cairo_surface_t, "surface");
#ifdef CAIRO_HAS_PNG_FUNCTIONS
f = mod->addFunc(type_uint, "cairo_surface_write_to_png",
(void *)cairo_surface_write_to_png
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_byteptr, "filename");
f = mod->addFunc(type_uint, "cairo_surface_write_to_png_stream",
(void *)cairo_surface_write_to_png_stream
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(function_puint_c_svoidptr_c_sbyteptr_c_suint_q, "write_func");
f->addArg(type_voidptr, "closure");
#endif // CAIRO_HAS_PNG_FUNCTIONS
f = mod->addFunc(type_voidptr, "cairo_surface_get_user_data",
(void *)cairo_surface_get_user_data
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_cairo_user_data_key_t, "key");
f = mod->addFunc(type_uint, "cairo_surface_set_user_data",
(void *)cairo_surface_set_user_data
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_cairo_user_data_key_t, "key");
f->addArg(type_voidptr, "user_data");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f = mod->addFunc(type_void, "cairo_surface_get_mime_data",
(void *)cairo_surface_get_mime_data
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_byteptr, "mime_type");
f->addArg(array_pbyteptr_q, "data");
f->addArg(array_puint64_q, "length");
f = mod->addFunc(type_uint, "cairo_surface_set_mime_data",
(void *)cairo_surface_set_mime_data
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_byteptr, "mime_type");
f->addArg(type_byteptr, "data");
f->addArg(type_uint64, "length");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f->addArg(type_voidptr, "closure");
f = mod->addFunc(type_void, "cairo_surface_get_font_options",
(void *)cairo_surface_get_font_options
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_cairo_font_options_t, "options");
f = mod->addFunc(type_void, "cairo_surface_flush",
(void *)cairo_surface_flush
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_surface_mark_dirty",
(void *)cairo_surface_mark_dirty
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_surface_mark_dirty_rectangle",
(void *)cairo_surface_mark_dirty_rectangle
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "cairo_surface_set_device_offset",
(void *)cairo_surface_set_device_offset
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "x_offset");
f->addArg(type_float64, "y_offset");
f = mod->addFunc(type_void, "cairo_surface_get_device_offset",
(void *)cairo_surface_get_device_offset
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(array_pfloat64_q, "x_offset");
f->addArg(array_pfloat64_q, "y_offset");
f = mod->addFunc(type_void, "cairo_surface_set_fallback_resolution",
(void *)cairo_surface_set_fallback_resolution
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "x_pixels_per_inch");
f->addArg(type_float64, "y_pixels_per_inch");
f = mod->addFunc(type_void, "cairo_surface_get_fallback_resolution",
(void *)cairo_surface_get_fallback_resolution
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(array_pfloat64_q, "x_pixels_per_inch");
f->addArg(array_pfloat64_q, "y_pixels_per_inch");
f = mod->addFunc(type_void, "cairo_surface_copy_page",
(void *)cairo_surface_copy_page
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_surface_show_page",
(void *)cairo_surface_show_page
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_bool, "cairo_surface_has_show_text_glyphs",
(void *)cairo_surface_has_show_text_glyphs
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_cairo_surface_t, "cairo_image_surface_create",
(void *)cairo_image_surface_create
);
f->addArg(type_uint, "format");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_int, "cairo_format_stride_for_width",
(void *)cairo_format_stride_for_width
);
f->addArg(type_uint, "format");
f->addArg(type_int, "width");
f = mod->addFunc(type_cairo_surface_t, "cairo_image_surface_create_for_data",
(void *)cairo_image_surface_create_for_data
);
f->addArg(type_byteptr, "data");
f->addArg(type_uint, "format");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f->addArg(type_int, "stride");
f = mod->addFunc(type_byteptr, "cairo_image_surface_get_data",
(void *)cairo_image_surface_get_data
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_image_surface_get_format",
(void *)cairo_image_surface_get_format
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_image_surface_get_width",
(void *)cairo_image_surface_get_width
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_image_surface_get_height",
(void *)cairo_image_surface_get_height
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_image_surface_get_stride",
(void *)cairo_image_surface_get_stride
);
f->addArg(type_cairo_surface_t, "surface");
#ifdef CAIRO_HAS_PNG_FUNCTIONS
f = mod->addFunc(type_cairo_surface_t, "cairo_image_surface_create_from_png",
(void *)cairo_image_surface_create_from_png
);
f->addArg(type_byteptr, "filename");
#endif // CAIRO_HAS_PNG_FUNCTIONS
f = mod->addFunc(type_cairo_surface_t, "cairo_recording_surface_create",
(void *)cairo_recording_surface_create
);
f->addArg(type_uint, "content");
f->addArg(type_cairo_rectangle_t, "extents");
f = mod->addFunc(type_void, "cairo_recording_surface_ink_extents",
(void *)cairo_recording_surface_ink_extents
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(array_pfloat64_q, "x0");
f->addArg(array_pfloat64_q, "y0");
f->addArg(array_pfloat64_q, "width");
f->addArg(array_pfloat64_q, "height");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_create_rgb",
(void *)cairo_pattern_create_rgb
);
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_create_rgba",
(void *)cairo_pattern_create_rgba
);
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f->addArg(type_float64, "alpha");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_create_for_surface",
(void *)cairo_pattern_create_for_surface
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_create_linear",
(void *)cairo_pattern_create_linear
);
f->addArg(type_float64, "x0");
f->addArg(type_float64, "y0");
f->addArg(type_float64, "x1");
f->addArg(type_float64, "y1");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_create_radial",
(void *)cairo_pattern_create_radial
);
f->addArg(type_float64, "cx0");
f->addArg(type_float64, "cy0");
f->addArg(type_float64, "radius0");
f->addArg(type_float64, "cx1");
f->addArg(type_float64, "cy1");
f->addArg(type_float64, "radius1");
f = mod->addFunc(type_cairo_pattern_t, "cairo_pattern_reference",
(void *)cairo_pattern_reference
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_void, "cairo_pattern_destroy",
(void *)cairo_pattern_destroy
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_uint, "cairo_pattern_get_reference_count",
(void *)cairo_pattern_get_reference_count
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_uint, "cairo_pattern_status",
(void *)cairo_pattern_status
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_voidptr, "cairo_pattern_get_user_data",
(void *)cairo_pattern_get_user_data
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_cairo_user_data_key_t, "key");
f = mod->addFunc(type_uint, "cairo_pattern_set_user_data",
(void *)cairo_pattern_set_user_data
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_cairo_user_data_key_t, "key");
f->addArg(type_voidptr, "user_data");
f->addArg(function_pvoid_c_svoidptr_q, "destroy");
f = mod->addFunc(type_uint, "cairo_pattern_get_type",
(void *)cairo_pattern_get_type
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_void, "cairo_pattern_add_color_stop_rgb",
(void *)cairo_pattern_add_color_stop_rgb
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_float64, "offset");
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f = mod->addFunc(type_void, "cairo_pattern_add_color_stop_rgba",
(void *)cairo_pattern_add_color_stop_rgba
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_float64, "offset");
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f->addArg(type_float64, "alpha");
f = mod->addFunc(type_void, "cairo_pattern_set_matrix",
(void *)cairo_pattern_set_matrix
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_pattern_get_matrix",
(void *)cairo_pattern_get_matrix
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_pattern_set_extend",
(void *)cairo_pattern_set_extend
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_uint, "extend");
f = mod->addFunc(type_uint, "cairo_pattern_get_extend",
(void *)cairo_pattern_get_extend
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_void, "cairo_pattern_set_filter",
(void *)cairo_pattern_set_filter
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_uint, "filter");
f = mod->addFunc(type_uint, "cairo_pattern_get_filter",
(void *)cairo_pattern_get_filter
);
f->addArg(type_cairo_pattern_t, "pattern");
f = mod->addFunc(type_uint, "cairo_pattern_get_rgba",
(void *)cairo_pattern_get_rgba
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(array_pfloat64_q, "red");
f->addArg(array_pfloat64_q, "green");
f->addArg(array_pfloat64_q, "blue");
f->addArg(array_pfloat64_q, "alpha");
f = mod->addFunc(type_uint, "cairo_pattern_get_surface",
(void *)cairo_pattern_get_surface
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_uint, "cairo_pattern_get_color_stop_rgba",
(void *)cairo_pattern_get_color_stop_rgba
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(type_int, "index");
f->addArg(array_pfloat64_q, "offset");
f->addArg(array_pfloat64_q, "red");
f->addArg(array_pfloat64_q, "green");
f->addArg(array_pfloat64_q, "blue");
f->addArg(array_pfloat64_q, "alpha");
f = mod->addFunc(type_uint, "cairo_pattern_get_color_stop_count",
(void *)cairo_pattern_get_color_stop_count
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(array_pint_q, "count");
f = mod->addFunc(type_uint, "cairo_pattern_get_linear_points",
(void *)cairo_pattern_get_linear_points
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(array_pfloat64_q, "x0");
f->addArg(array_pfloat64_q, "y0");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f = mod->addFunc(type_uint, "cairo_pattern_get_radial_circles",
(void *)cairo_pattern_get_radial_circles
);
f->addArg(type_cairo_pattern_t, "pattern");
f->addArg(array_pfloat64_q, "x0");
f->addArg(array_pfloat64_q, "y0");
f->addArg(array_pfloat64_q, "r0");
f->addArg(array_pfloat64_q, "x1");
f->addArg(array_pfloat64_q, "y1");
f->addArg(array_pfloat64_q, "r1");
f = mod->addFunc(type_void, "cairo_matrix_init",
(void *)cairo_matrix_init
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "xx");
f->addArg(type_float64, "yx");
f->addArg(type_float64, "xy");
f->addArg(type_float64, "yy");
f->addArg(type_float64, "x0");
f->addArg(type_float64, "y0");
f = mod->addFunc(type_void, "cairo_matrix_init_identity",
(void *)cairo_matrix_init_identity
);
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_matrix_init_translate",
(void *)cairo_matrix_init_translate
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "tx");
f->addArg(type_float64, "ty");
f = mod->addFunc(type_void, "cairo_matrix_init_scale",
(void *)cairo_matrix_init_scale
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "sx");
f->addArg(type_float64, "sy");
f = mod->addFunc(type_void, "cairo_matrix_init_rotate",
(void *)cairo_matrix_init_rotate
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "radians");
f = mod->addFunc(type_void, "cairo_matrix_translate",
(void *)cairo_matrix_translate
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "tx");
f->addArg(type_float64, "ty");
f = mod->addFunc(type_void, "cairo_matrix_scale",
(void *)cairo_matrix_scale
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "sx");
f->addArg(type_float64, "sy");
f = mod->addFunc(type_void, "cairo_matrix_rotate",
(void *)cairo_matrix_rotate
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(type_float64, "radians");
f = mod->addFunc(type_uint, "cairo_matrix_invert",
(void *)cairo_matrix_invert
);
f->addArg(type_cairo_matrix_t, "matrix");
f = mod->addFunc(type_void, "cairo_matrix_multiply",
(void *)cairo_matrix_multiply
);
f->addArg(type_cairo_matrix_t, "result");
f->addArg(type_cairo_matrix_t, "a");
f->addArg(type_cairo_matrix_t, "b");
f = mod->addFunc(type_void, "cairo_matrix_transform_distance",
(void *)cairo_matrix_transform_distance
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(array_pfloat64_q, "dx");
f->addArg(array_pfloat64_q, "dy");
f = mod->addFunc(type_void, "cairo_matrix_transform_point",
(void *)cairo_matrix_transform_point
);
f->addArg(type_cairo_matrix_t, "matrix");
f->addArg(array_pfloat64_q, "x");
f->addArg(array_pfloat64_q, "y");
f = mod->addFunc(type_cairo_region_t, "cairo_region_create",
(void *)cairo_region_create
);
f = mod->addFunc(type_cairo_region_t, "cairo_region_create_rectangle",
(void *)cairo_region_create_rectangle
);
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_cairo_region_t, "cairo_region_create_rectangles",
(void *)cairo_region_create_rectangles
);
f->addArg(type_cairo_rectangle_int_t, "rects");
f->addArg(type_int, "count");
f = mod->addFunc(type_cairo_region_t, "cairo_region_copy",
(void *)cairo_region_copy
);
f->addArg(type_cairo_region_t, "original");
f = mod->addFunc(type_cairo_region_t, "cairo_region_reference",
(void *)cairo_region_reference
);
f->addArg(type_cairo_region_t, "region");
f = mod->addFunc(type_void, "cairo_region_destroy",
(void *)cairo_region_destroy
);
f->addArg(type_cairo_region_t, "region");
f = mod->addFunc(type_bool, "cairo_region_equal",
(void *)cairo_region_equal
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_region_t, "b");
f = mod->addFunc(type_uint, "cairo_region_status",
(void *)cairo_region_status
);
f->addArg(type_cairo_region_t, "region");
f = mod->addFunc(type_void, "cairo_region_get_extents",
(void *)cairo_region_get_extents
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "extents");
f = mod->addFunc(type_int, "cairo_region_num_rectangles",
(void *)cairo_region_num_rectangles
);
f->addArg(type_cairo_region_t, "region");
f = mod->addFunc(type_void, "cairo_region_get_rectangle",
(void *)cairo_region_get_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_int, "nth");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_bool, "cairo_region_is_empty",
(void *)cairo_region_is_empty
);
f->addArg(type_cairo_region_t, "region");
f = mod->addFunc(type_uint, "cairo_region_contains_rectangle",
(void *)cairo_region_contains_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_bool, "cairo_region_contains_point",
(void *)cairo_region_contains_point
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f = mod->addFunc(type_void, "cairo_region_translate",
(void *)cairo_region_translate
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_int, "dx");
f->addArg(type_int, "dy");
f = mod->addFunc(type_uint, "cairo_region_subtract",
(void *)cairo_region_subtract
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_region_t, "other");
f = mod->addFunc(type_uint, "cairo_region_subtract_rectangle",
(void *)cairo_region_subtract_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_uint, "cairo_region_intersect",
(void *)cairo_region_intersect
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_region_t, "other");
f = mod->addFunc(type_uint, "cairo_region_intersect_rectangle",
(void *)cairo_region_intersect_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_uint, "cairo_region_union",
(void *)cairo_region_union
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_region_t, "other");
f = mod->addFunc(type_uint, "cairo_region_union_rectangle",
(void *)cairo_region_union_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_uint, "cairo_region_xor",
(void *)cairo_region_xor
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_region_t, "other");
f = mod->addFunc(type_uint, "cairo_region_xor_rectangle",
(void *)cairo_region_xor_rectangle
);
f->addArg(type_cairo_region_t, "region");
f->addArg(type_cairo_rectangle_int_t, "rectangle");
f = mod->addFunc(type_void, "cairo_debug_reset_static_data",
(void *)cairo_debug_reset_static_data
);
f = mod->addFunc(type_cairo_surface_t, "cairo_pdf_surface_create",
(void *)cairo_pdf_surface_create
);
f->addArg(type_byteptr, "filename");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_cairo_surface_t, "cairo_pdf_surface_create_for_stream",
(void *)cairo_pdf_surface_create_for_stream
);
f->addArg(function_puint_c_svoidptr_c_sbyteptr_c_suint_q, "write_func");
f->addArg(type_voidptr, "closure");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_void, "cairo_pdf_surface_restrict_to_version",
(void *)cairo_pdf_surface_restrict_to_version
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_uint, "version");
f = mod->addFunc(type_void, "cairo_pdf_get_versions",
(void *)cairo_pdf_get_versions
);
f->addArg(array_puint_q, "versions");
f->addArg(array_pint_q, "num_versions");
f = mod->addFunc(type_byteptr, "cairo_pdf_version_to_string",
(void *)cairo_pdf_version_to_string
);
f->addArg(type_uint, "version");
f = mod->addFunc(type_void, "cairo_pdf_surface_set_size",
(void *)cairo_pdf_surface_set_size
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_cairo_surface_t, "cairo_svg_surface_create",
(void *)cairo_svg_surface_create
);
f->addArg(type_byteptr, "filename");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_cairo_surface_t, "cairo_svg_surface_create_for_stream",
(void *)cairo_svg_surface_create_for_stream
);
f->addArg(function_puint_c_svoidptr_c_sbyteptr_c_suint_q, "write_func");
f->addArg(type_voidptr, "closure");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_void, "cairo_svg_surface_restrict_to_version",
(void *)cairo_svg_surface_restrict_to_version
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_uint, "version");
f = mod->addFunc(type_void, "cairo_svg_get_versions",
(void *)cairo_svg_get_versions
);
f->addArg(array_puint_q, "versions");
f->addArg(array_pint_q, "num_versions");
f = mod->addFunc(type_byteptr, "cairo_svg_version_to_string",
(void *)cairo_svg_version_to_string
);
f->addArg(type_uint, "version");
f = mod->addFunc(type_cairo_surface_t, "cairo_xlib_surface_create",
(void *)cairo_xlib_surface_create
);
f->addArg(type_Display, "dpy");
f->addArg(type_Drawable, "drawable");
f->addArg(type_Visual, "visual");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_cairo_surface_t, "cairo_xlib_surface_create_for_bitmap",
(void *)cairo_xlib_surface_create_for_bitmap
);
f->addArg(type_Display, "dpy");
f->addArg(type_Pixmap, "bitmap");
f->addArg(type_Screen, "screen");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "cairo_xlib_surface_set_size",
(void *)cairo_xlib_surface_set_size
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "cairo_xlib_surface_set_drawable",
(void *)cairo_xlib_surface_set_drawable
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_Drawable, "drawable");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_Display, "cairo_xlib_surface_get_display",
(void *)cairo_xlib_surface_get_display
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_Drawable, "cairo_xlib_surface_get_drawable",
(void *)cairo_xlib_surface_get_drawable
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_Screen, "cairo_xlib_surface_get_screen",
(void *)cairo_xlib_surface_get_screen
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_Visual, "cairo_xlib_surface_get_visual",
(void *)cairo_xlib_surface_get_visual
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_xlib_surface_get_depth",
(void *)cairo_xlib_surface_get_depth
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_xlib_surface_get_width",
(void *)cairo_xlib_surface_get_width
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_int, "cairo_xlib_surface_get_height",
(void *)cairo_xlib_surface_get_height
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_cairo_surface_t, "cairo_ps_surface_create",
(void *)cairo_ps_surface_create
);
f->addArg(type_byteptr, "filename");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_cairo_surface_t, "cairo_ps_surface_create_for_stream",
(void *)cairo_ps_surface_create_for_stream
);
f->addArg(function_puint_c_svoidptr_c_sbyteptr_c_suint_q, "write_func");
f->addArg(type_voidptr, "closure");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_void, "cairo_ps_surface_restrict_to_level",
(void *)cairo_ps_surface_restrict_to_level
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_uint, "level");
f = mod->addFunc(type_void, "cairo_ps_get_levels",
(void *)cairo_ps_get_levels
);
f->addArg(array_puint_q, "levels");
f->addArg(type_int, "num_levels");
f = mod->addFunc(type_byteptr, "cairo_ps_level_to_string",
(void *)cairo_ps_level_to_string
);
f->addArg(type_uint, "level");
f = mod->addFunc(type_void, "cairo_ps_surface_set_eps",
(void *)cairo_ps_surface_set_eps
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_bool, "eps");
f = mod->addFunc(type_bool, "cairo_ps_surface_get_eps",
(void *)cairo_ps_surface_get_eps
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_ps_surface_set_size",
(void *)cairo_ps_surface_set_size
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_float64, "width_in_points");
f->addArg(type_float64, "height_in_points");
f = mod->addFunc(type_void, "cairo_ps_surface_dsc_comment",
(void *)cairo_ps_surface_dsc_comment
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_byteptr, "comment");
f = mod->addFunc(type_void, "cairo_ps_surface_dsc_begin_setup",
(void *)cairo_ps_surface_dsc_begin_setup
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairo_ps_surface_dsc_begin_page_setup",
(void *)cairo_ps_surface_dsc_begin_page_setup
);
f->addArg(type_cairo_surface_t, "surface");
mod->addConstant(type_uint, "CAIRO_HAS_FC_FONT",
static_cast<int>(CAIRO_HAS_FC_FONT)
);
mod->addConstant(type_uint, "CAIRO_HAS_FT_FONT",
static_cast<int>(CAIRO_HAS_FT_FONT)
);
mod->addConstant(type_uint, "CAIRO_HAS_GOBJECT_FUNCTIONS",
static_cast<int>(CAIRO_HAS_GOBJECT_FUNCTIONS)
);
mod->addConstant(type_uint, "CAIRO_HAS_IMAGE_SURFACE",
static_cast<int>(CAIRO_HAS_IMAGE_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_PDF_SURFACE",
static_cast<int>(CAIRO_HAS_PDF_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_PNG_FUNCTIONS",
static_cast<int>(CAIRO_HAS_PNG_FUNCTIONS)
);
mod->addConstant(type_uint, "CAIRO_HAS_PS_SURFACE",
static_cast<int>(CAIRO_HAS_PS_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_RECORDING_SURFACE",
static_cast<int>(CAIRO_HAS_RECORDING_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_SVG_SURFACE",
static_cast<int>(CAIRO_HAS_SVG_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_USER_FONT",
static_cast<int>(CAIRO_HAS_USER_FONT)
);
mod->addConstant(type_uint, "CAIRO_HAS_XCB_SHM_FUNCTIONS",
static_cast<int>(CAIRO_HAS_XCB_SHM_FUNCTIONS)
);
mod->addConstant(type_uint, "CAIRO_HAS_XCB_SURFACE",
static_cast<int>(CAIRO_HAS_XCB_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_XLIB_SURFACE",
static_cast<int>(CAIRO_HAS_XLIB_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_HAS_XLIB_XRENDER_SURFACE",
static_cast<int>(CAIRO_HAS_XLIB_XRENDER_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_SUCCESS",
static_cast<int>(CAIRO_STATUS_SUCCESS)
);
mod->addConstant(type_uint, "CAIRO_STATUS_NO_MEMORY",
static_cast<int>(CAIRO_STATUS_NO_MEMORY)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_RESTORE",
static_cast<int>(CAIRO_STATUS_INVALID_RESTORE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_POP_GROUP",
static_cast<int>(CAIRO_STATUS_INVALID_POP_GROUP)
);
mod->addConstant(type_uint, "CAIRO_STATUS_NO_CURRENT_POINT",
static_cast<int>(CAIRO_STATUS_NO_CURRENT_POINT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_MATRIX",
static_cast<int>(CAIRO_STATUS_INVALID_MATRIX)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_STATUS",
static_cast<int>(CAIRO_STATUS_INVALID_STATUS)
);
mod->addConstant(type_uint, "CAIRO_STATUS_NULL_POINTER",
static_cast<int>(CAIRO_STATUS_NULL_POINTER)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_STRING",
static_cast<int>(CAIRO_STATUS_INVALID_STRING)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_PATH_DATA",
static_cast<int>(CAIRO_STATUS_INVALID_PATH_DATA)
);
mod->addConstant(type_uint, "CAIRO_STATUS_READ_ERROR",
static_cast<int>(CAIRO_STATUS_READ_ERROR)
);
mod->addConstant(type_uint, "CAIRO_STATUS_WRITE_ERROR",
static_cast<int>(CAIRO_STATUS_WRITE_ERROR)
);
mod->addConstant(type_uint, "CAIRO_STATUS_SURFACE_FINISHED",
static_cast<int>(CAIRO_STATUS_SURFACE_FINISHED)
);
mod->addConstant(type_uint, "CAIRO_STATUS_SURFACE_TYPE_MISMATCH",
static_cast<int>(CAIRO_STATUS_SURFACE_TYPE_MISMATCH)
);
mod->addConstant(type_uint, "CAIRO_STATUS_PATTERN_TYPE_MISMATCH",
static_cast<int>(CAIRO_STATUS_PATTERN_TYPE_MISMATCH)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_CONTENT",
static_cast<int>(CAIRO_STATUS_INVALID_CONTENT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_FORMAT",
static_cast<int>(CAIRO_STATUS_INVALID_FORMAT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_VISUAL",
static_cast<int>(CAIRO_STATUS_INVALID_VISUAL)
);
mod->addConstant(type_uint, "CAIRO_STATUS_FILE_NOT_FOUND",
static_cast<int>(CAIRO_STATUS_FILE_NOT_FOUND)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_DASH",
static_cast<int>(CAIRO_STATUS_INVALID_DASH)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_DSC_COMMENT",
static_cast<int>(CAIRO_STATUS_INVALID_DSC_COMMENT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_INDEX",
static_cast<int>(CAIRO_STATUS_INVALID_INDEX)
);
mod->addConstant(type_uint, "CAIRO_STATUS_CLIP_NOT_REPRESENTABLE",
static_cast<int>(CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_TEMP_FILE_ERROR",
static_cast<int>(CAIRO_STATUS_TEMP_FILE_ERROR)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_STRIDE",
static_cast<int>(CAIRO_STATUS_INVALID_STRIDE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_FONT_TYPE_MISMATCH",
static_cast<int>(CAIRO_STATUS_FONT_TYPE_MISMATCH)
);
mod->addConstant(type_uint, "CAIRO_STATUS_USER_FONT_IMMUTABLE",
static_cast<int>(CAIRO_STATUS_USER_FONT_IMMUTABLE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_USER_FONT_ERROR",
static_cast<int>(CAIRO_STATUS_USER_FONT_ERROR)
);
mod->addConstant(type_uint, "CAIRO_STATUS_NEGATIVE_COUNT",
static_cast<int>(CAIRO_STATUS_NEGATIVE_COUNT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_CLUSTERS",
static_cast<int>(CAIRO_STATUS_INVALID_CLUSTERS)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_SLANT",
static_cast<int>(CAIRO_STATUS_INVALID_SLANT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_WEIGHT",
static_cast<int>(CAIRO_STATUS_INVALID_WEIGHT)
);
mod->addConstant(type_uint, "CAIRO_STATUS_INVALID_SIZE",
static_cast<int>(CAIRO_STATUS_INVALID_SIZE)
);
mod->addConstant(type_uint, "CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED",
static_cast<int>(CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED)
);
mod->addConstant(type_uint, "CAIRO_STATUS_DEVICE_TYPE_MISMATCH",
static_cast<int>(CAIRO_STATUS_DEVICE_TYPE_MISMATCH)
);
mod->addConstant(type_uint, "CAIRO_STATUS_DEVICE_ERROR",
static_cast<int>(CAIRO_STATUS_DEVICE_ERROR)
);
mod->addConstant(type_uint, "CAIRO_STATUS_LAST_STATUS",
static_cast<int>(CAIRO_STATUS_LAST_STATUS)
);
mod->addConstant(type_uint, "CAIRO_CONTENT_COLOR",
static_cast<int>(CAIRO_CONTENT_COLOR)
);
mod->addConstant(type_uint, "CAIRO_CONTENT_ALPHA",
static_cast<int>(CAIRO_CONTENT_ALPHA)
);
mod->addConstant(type_uint, "CAIRO_CONTENT_COLOR_ALPHA",
static_cast<int>(CAIRO_CONTENT_COLOR_ALPHA)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_CLEAR",
static_cast<int>(CAIRO_OPERATOR_CLEAR)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_SOURCE",
static_cast<int>(CAIRO_OPERATOR_SOURCE)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_OVER",
static_cast<int>(CAIRO_OPERATOR_OVER)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_IN",
static_cast<int>(CAIRO_OPERATOR_IN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_OUT",
static_cast<int>(CAIRO_OPERATOR_OUT)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_ATOP",
static_cast<int>(CAIRO_OPERATOR_ATOP)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DEST",
static_cast<int>(CAIRO_OPERATOR_DEST)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DEST_OVER",
static_cast<int>(CAIRO_OPERATOR_DEST_OVER)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DEST_IN",
static_cast<int>(CAIRO_OPERATOR_DEST_IN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DEST_OUT",
static_cast<int>(CAIRO_OPERATOR_DEST_OUT)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DEST_ATOP",
static_cast<int>(CAIRO_OPERATOR_DEST_ATOP)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_XOR",
static_cast<int>(CAIRO_OPERATOR_XOR)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_ADD",
static_cast<int>(CAIRO_OPERATOR_ADD)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_SATURATE",
static_cast<int>(CAIRO_OPERATOR_SATURATE)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_MULTIPLY",
static_cast<int>(CAIRO_OPERATOR_MULTIPLY)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_SCREEN",
static_cast<int>(CAIRO_OPERATOR_SCREEN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_OVERLAY",
static_cast<int>(CAIRO_OPERATOR_OVERLAY)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DARKEN",
static_cast<int>(CAIRO_OPERATOR_DARKEN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_LIGHTEN",
static_cast<int>(CAIRO_OPERATOR_LIGHTEN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_COLOR_DODGE",
static_cast<int>(CAIRO_OPERATOR_COLOR_DODGE)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_COLOR_BURN",
static_cast<int>(CAIRO_OPERATOR_COLOR_BURN)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_HARD_LIGHT",
static_cast<int>(CAIRO_OPERATOR_HARD_LIGHT)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_SOFT_LIGHT",
static_cast<int>(CAIRO_OPERATOR_SOFT_LIGHT)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_DIFFERENCE",
static_cast<int>(CAIRO_OPERATOR_DIFFERENCE)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_EXCLUSION",
static_cast<int>(CAIRO_OPERATOR_EXCLUSION)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_HSL_HUE",
static_cast<int>(CAIRO_OPERATOR_HSL_HUE)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_HSL_SATURATION",
static_cast<int>(CAIRO_OPERATOR_HSL_SATURATION)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_HSL_COLOR",
static_cast<int>(CAIRO_OPERATOR_HSL_COLOR)
);
mod->addConstant(type_uint, "CAIRO_OPERATOR_HSL_LUMINOSITY",
static_cast<int>(CAIRO_OPERATOR_HSL_LUMINOSITY)
);
mod->addConstant(type_uint, "CAIRO_ANTIALIAS_DEFAULT",
static_cast<int>(CAIRO_ANTIALIAS_DEFAULT)
);
mod->addConstant(type_uint, "CAIRO_ANTIALIAS_NONE",
static_cast<int>(CAIRO_ANTIALIAS_NONE)
);
mod->addConstant(type_uint, "CAIRO_ANTIALIAS_GRAY",
static_cast<int>(CAIRO_ANTIALIAS_GRAY)
);
mod->addConstant(type_uint, "CAIRO_ANTIALIAS_SUBPIXEL",
static_cast<int>(CAIRO_ANTIALIAS_SUBPIXEL)
);
mod->addConstant(type_uint, "CAIRO_FILL_RULE_WINDING",
static_cast<int>(CAIRO_FILL_RULE_WINDING)
);
mod->addConstant(type_uint, "CAIRO_FILL_RULE_EVEN_ODD",
static_cast<int>(CAIRO_FILL_RULE_EVEN_ODD)
);
mod->addConstant(type_uint, "CAIRO_LINE_CAP_BUTT",
static_cast<int>(CAIRO_LINE_CAP_BUTT)
);
mod->addConstant(type_uint, "CAIRO_LINE_CAP_ROUND",
static_cast<int>(CAIRO_LINE_CAP_ROUND)
);
mod->addConstant(type_uint, "CAIRO_LINE_CAP_SQUARE",
static_cast<int>(CAIRO_LINE_CAP_SQUARE)
);
mod->addConstant(type_uint, "CAIRO_LINE_JOIN_MITER",
static_cast<int>(CAIRO_LINE_JOIN_MITER)
);
mod->addConstant(type_uint, "CAIRO_LINE_JOIN_ROUND",
static_cast<int>(CAIRO_LINE_JOIN_ROUND)
);
mod->addConstant(type_uint, "CAIRO_LINE_JOIN_BEVEL",
static_cast<int>(CAIRO_LINE_JOIN_BEVEL)
);
mod->addConstant(type_uint, "CAIRO_TEXT_CLUSTER_FLAG_BACKWARD",
static_cast<int>(CAIRO_TEXT_CLUSTER_FLAG_BACKWARD)
);
mod->addConstant(type_uint, "CAIRO_FONT_SLANT_NORMAL",
static_cast<int>(CAIRO_FONT_SLANT_NORMAL)
);
mod->addConstant(type_uint, "CAIRO_FONT_SLANT_ITALIC",
static_cast<int>(CAIRO_FONT_SLANT_ITALIC)
);
mod->addConstant(type_uint, "CAIRO_FONT_SLANT_OBLIQUE",
static_cast<int>(CAIRO_FONT_SLANT_OBLIQUE)
);
mod->addConstant(type_uint, "CAIRO_FONT_WEIGHT_NORMAL",
static_cast<int>(CAIRO_FONT_WEIGHT_NORMAL)
);
mod->addConstant(type_uint, "CAIRO_FONT_WEIGHT_BOLD",
static_cast<int>(CAIRO_FONT_WEIGHT_BOLD)
);
mod->addConstant(type_uint, "CAIRO_SUBPIXEL_ORDER_DEFAULT",
static_cast<int>(CAIRO_SUBPIXEL_ORDER_DEFAULT)
);
mod->addConstant(type_uint, "CAIRO_SUBPIXEL_ORDER_RGB",
static_cast<int>(CAIRO_SUBPIXEL_ORDER_RGB)
);
mod->addConstant(type_uint, "CAIRO_SUBPIXEL_ORDER_BGR",
static_cast<int>(CAIRO_SUBPIXEL_ORDER_BGR)
);
mod->addConstant(type_uint, "CAIRO_SUBPIXEL_ORDER_VRGB",
static_cast<int>(CAIRO_SUBPIXEL_ORDER_VRGB)
);
mod->addConstant(type_uint, "CAIRO_SUBPIXEL_ORDER_VBGR",
static_cast<int>(CAIRO_SUBPIXEL_ORDER_VBGR)
);
mod->addConstant(type_uint, "CAIRO_HINT_STYLE_DEFAULT",
static_cast<int>(CAIRO_HINT_STYLE_DEFAULT)
);
mod->addConstant(type_uint, "CAIRO_HINT_STYLE_NONE",
static_cast<int>(CAIRO_HINT_STYLE_NONE)
);
mod->addConstant(type_uint, "CAIRO_HINT_STYLE_SLIGHT",
static_cast<int>(CAIRO_HINT_STYLE_SLIGHT)
);
mod->addConstant(type_uint, "CAIRO_HINT_STYLE_MEDIUM",
static_cast<int>(CAIRO_HINT_STYLE_MEDIUM)
);
mod->addConstant(type_uint, "CAIRO_HINT_STYLE_FULL",
static_cast<int>(CAIRO_HINT_STYLE_FULL)
);
mod->addConstant(type_uint, "CAIRO_HINT_METRICS_DEFAULT",
static_cast<int>(CAIRO_HINT_METRICS_DEFAULT)
);
mod->addConstant(type_uint, "CAIRO_HINT_METRICS_OFF",
static_cast<int>(CAIRO_HINT_METRICS_OFF)
);
mod->addConstant(type_uint, "CAIRO_HINT_METRICS_ON",
static_cast<int>(CAIRO_HINT_METRICS_ON)
);
mod->addConstant(type_uint, "CAIRO_FONT_TYPE_TOY",
static_cast<int>(CAIRO_FONT_TYPE_TOY)
);
mod->addConstant(type_uint, "CAIRO_FONT_TYPE_FT",
static_cast<int>(CAIRO_FONT_TYPE_FT)
);
mod->addConstant(type_uint, "CAIRO_FONT_TYPE_WIN32",
static_cast<int>(CAIRO_FONT_TYPE_WIN32)
);
mod->addConstant(type_uint, "CAIRO_FONT_TYPE_QUARTZ",
static_cast<int>(CAIRO_FONT_TYPE_QUARTZ)
);
mod->addConstant(type_uint, "CAIRO_FONT_TYPE_USER",
static_cast<int>(CAIRO_FONT_TYPE_USER)
);
mod->addConstant(type_uint, "CAIRO_PATH_MOVE_TO",
static_cast<int>(CAIRO_PATH_MOVE_TO)
);
mod->addConstant(type_uint, "CAIRO_PATH_LINE_TO",
static_cast<int>(CAIRO_PATH_LINE_TO)
);
mod->addConstant(type_uint, "CAIRO_PATH_CURVE_TO",
static_cast<int>(CAIRO_PATH_CURVE_TO)
);
mod->addConstant(type_uint, "CAIRO_PATH_CLOSE_PATH",
static_cast<int>(CAIRO_PATH_CLOSE_PATH)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_DRM",
static_cast<int>(CAIRO_DEVICE_TYPE_DRM)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_GL",
static_cast<int>(CAIRO_DEVICE_TYPE_GL)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_SCRIPT",
static_cast<int>(CAIRO_DEVICE_TYPE_SCRIPT)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_XCB",
static_cast<int>(CAIRO_DEVICE_TYPE_XCB)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_XLIB",
static_cast<int>(CAIRO_DEVICE_TYPE_XLIB)
);
mod->addConstant(type_uint, "CAIRO_DEVICE_TYPE_XML",
static_cast<int>(CAIRO_DEVICE_TYPE_XML)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_IMAGE",
static_cast<int>(CAIRO_SURFACE_TYPE_IMAGE)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_PDF",
static_cast<int>(CAIRO_SURFACE_TYPE_PDF)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_PS",
static_cast<int>(CAIRO_SURFACE_TYPE_PS)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_XLIB",
static_cast<int>(CAIRO_SURFACE_TYPE_XLIB)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_XCB",
static_cast<int>(CAIRO_SURFACE_TYPE_XCB)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_GLITZ",
static_cast<int>(CAIRO_SURFACE_TYPE_GLITZ)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_QUARTZ",
static_cast<int>(CAIRO_SURFACE_TYPE_QUARTZ)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_WIN32",
static_cast<int>(CAIRO_SURFACE_TYPE_WIN32)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_BEOS",
static_cast<int>(CAIRO_SURFACE_TYPE_BEOS)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_DIRECTFB",
static_cast<int>(CAIRO_SURFACE_TYPE_DIRECTFB)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_SVG",
static_cast<int>(CAIRO_SURFACE_TYPE_SVG)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_OS2",
static_cast<int>(CAIRO_SURFACE_TYPE_OS2)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_WIN32_PRINTING",
static_cast<int>(CAIRO_SURFACE_TYPE_WIN32_PRINTING)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_QUARTZ_IMAGE",
static_cast<int>(CAIRO_SURFACE_TYPE_QUARTZ_IMAGE)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_SCRIPT",
static_cast<int>(CAIRO_SURFACE_TYPE_SCRIPT)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_QT",
static_cast<int>(CAIRO_SURFACE_TYPE_QT)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_RECORDING",
static_cast<int>(CAIRO_SURFACE_TYPE_RECORDING)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_VG",
static_cast<int>(CAIRO_SURFACE_TYPE_VG)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_GL",
static_cast<int>(CAIRO_SURFACE_TYPE_GL)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_DRM",
static_cast<int>(CAIRO_SURFACE_TYPE_DRM)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_TEE",
static_cast<int>(CAIRO_SURFACE_TYPE_TEE)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_XML",
static_cast<int>(CAIRO_SURFACE_TYPE_XML)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_SKIA",
static_cast<int>(CAIRO_SURFACE_TYPE_SKIA)
);
mod->addConstant(type_uint, "CAIRO_SURFACE_TYPE_SUBSURFACE",
static_cast<int>(CAIRO_SURFACE_TYPE_SUBSURFACE)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_INVALID",
static_cast<int>(CAIRO_FORMAT_INVALID)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_ARGB32",
static_cast<int>(CAIRO_FORMAT_ARGB32)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_RGB24",
static_cast<int>(CAIRO_FORMAT_RGB24)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_A8",
static_cast<int>(CAIRO_FORMAT_A8)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_A1",
static_cast<int>(CAIRO_FORMAT_A1)
);
mod->addConstant(type_uint, "CAIRO_FORMAT_RGB16_565",
static_cast<int>(CAIRO_FORMAT_RGB16_565)
);
mod->addConstant(type_uint, "CAIRO_PATTERN_TYPE_SOLID",
static_cast<int>(CAIRO_PATTERN_TYPE_SOLID)
);
mod->addConstant(type_uint, "CAIRO_PATTERN_TYPE_SURFACE",
static_cast<int>(CAIRO_PATTERN_TYPE_SURFACE)
);
mod->addConstant(type_uint, "CAIRO_PATTERN_TYPE_LINEAR",
static_cast<int>(CAIRO_PATTERN_TYPE_LINEAR)
);
mod->addConstant(type_uint, "CAIRO_PATTERN_TYPE_RADIAL",
static_cast<int>(CAIRO_PATTERN_TYPE_RADIAL)
);
mod->addConstant(type_uint, "CAIRO_EXTEND_NONE",
static_cast<int>(CAIRO_EXTEND_NONE)
);
mod->addConstant(type_uint, "CAIRO_EXTEND_REPEAT",
static_cast<int>(CAIRO_EXTEND_REPEAT)
);
mod->addConstant(type_uint, "CAIRO_EXTEND_REFLECT",
static_cast<int>(CAIRO_EXTEND_REFLECT)
);
mod->addConstant(type_uint, "CAIRO_EXTEND_PAD",
static_cast<int>(CAIRO_EXTEND_PAD)
);
mod->addConstant(type_uint, "CAIRO_FILTER_FAST",
static_cast<int>(CAIRO_FILTER_FAST)
);
mod->addConstant(type_uint, "CAIRO_FILTER_GOOD",
static_cast<int>(CAIRO_FILTER_GOOD)
);
mod->addConstant(type_uint, "CAIRO_FILTER_BEST",
static_cast<int>(CAIRO_FILTER_BEST)
);
mod->addConstant(type_uint, "CAIRO_FILTER_NEAREST",
static_cast<int>(CAIRO_FILTER_NEAREST)
);
mod->addConstant(type_uint, "CAIRO_FILTER_BILINEAR",
static_cast<int>(CAIRO_FILTER_BILINEAR)
);
mod->addConstant(type_uint, "CAIRO_FILTER_GAUSSIAN",
static_cast<int>(CAIRO_FILTER_GAUSSIAN)
);
mod->addConstant(type_uint, "CAIRO_REGION_OVERLAP_IN",
static_cast<int>(CAIRO_REGION_OVERLAP_IN)
);
mod->addConstant(type_uint, "CAIRO_REGION_OVERLAP_OUT",
static_cast<int>(CAIRO_REGION_OVERLAP_OUT)
);
mod->addConstant(type_uint, "CAIRO_REGION_OVERLAP_PART",
static_cast<int>(CAIRO_REGION_OVERLAP_PART)
);
mod->addConstant(type_uint, "CAIRO_PDF_VERSION_1_4",
static_cast<int>(CAIRO_PDF_VERSION_1_4)
);
mod->addConstant(type_uint, "CAIRO_PDF_VERSION_1_5",
static_cast<int>(CAIRO_PDF_VERSION_1_5)
);
mod->addConstant(type_uint, "CAIRO_SVG_VERSION_1_1",
static_cast<int>(CAIRO_SVG_VERSION_1_1)
);
mod->addConstant(type_uint, "CAIRO_SVG_VERSION_1_2",
static_cast<int>(CAIRO_SVG_VERSION_1_2)
);
mod->addConstant(type_uint, "CAIRO_PS_LEVEL_2",
static_cast<int>(CAIRO_PS_LEVEL_2)
);
mod->addConstant(type_uint, "CAIRO_PS_LEVEL_3",
static_cast<int>(CAIRO_PS_LEVEL_3)
);
}
| C++ |
#include <alsa/asoundlib.h>
snd_seq_event_t *snd_seq_event_alloc() {
snd_seq_event_t *e = new snd_seq_event_t;
snd_seq_ev_clear(e); return e; }
void snd_seq_event_setSource(snd_seq_event_t *event, int port) {
event->source.port = port; }
void snd_seq_event_setSubs(snd_seq_event_t *event) {
event->dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS;
event->dest.port = SND_SEQ_ADDRESS_UNKNOWN; }
void snd_seq_event_setDirect(snd_seq_event_t *event) {
event->queue = SND_SEQ_QUEUE_DIRECT; }
void snd_seq_event_setNoteOn(snd_seq_event_t *event, int channel, int note, int velocity) { snd_seq_ev_set_noteon(event, channel, note, velocity); }void snd_seq_event_setNoteOff(snd_seq_event_t *event, int channel, int note, int velocity) { snd_seq_ev_set_noteoff(event, channel, note, velocity); }void snd_seq_event_scheduleTick(snd_seq_event_t *event, int queue, int relative, int time) { snd_seq_ev_schedule_tick(event, queue, relative, time); }void SndSeqQueue_setTempo(snd_seq_t *seqp, int queueId, int tempo, int ppq) { snd_seq_queue_tempo_t *t; snd_seq_queue_tempo_alloca(&t); snd_seq_queue_tempo_set_tempo(t, tempo); snd_seq_queue_tempo_set_ppq(t, ppq); snd_seq_set_queue_tempo(seqp, queueId, t); }void SndSeqQueue_start(snd_seq_t *seqp, int queueId, snd_seq_event_t *event) { snd_seq_start_queue(seqp, queueId, event); }void SndSeqQueue_stop(snd_seq_t *seqp, int queueId, snd_seq_event_t *event) { snd_seq_stop_queue(seqp, queueId, event); }typedef int Undef;
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__alsa_midi_rinit() {
return;
}
extern "C"
void crack_ext__alsa_midi_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_snd_seq_t = mod->addType("snd_seq_t", sizeof(Undef));
type_snd_seq_t->finish();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_psnd__seq__t_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_snd_seq_t;
array_psnd__seq__t_q = array->getSpecialization(params);
}
crack::ext::Type *type_snd_seq_event_t = mod->addType("snd_seq_event_t", sizeof(snd_seq_event_t));
f = type_snd_seq_event_t->addConstructor("init",
(void *)snd_seq_event_alloc
);
f = type_snd_seq_event_t->addMethod(type_void, "setSource",
(void *)snd_seq_event_setSource
);
f->addArg(type_int, "port");
f = type_snd_seq_event_t->addMethod(type_void, "setSubs",
(void *)snd_seq_event_setSubs
);
f = type_snd_seq_event_t->addMethod(type_void, "setDirect",
(void *)snd_seq_event_setDirect
);
f = type_snd_seq_event_t->addMethod(type_void, "setNoteOn",
(void *)snd_seq_event_setNoteOn
);
f->addArg(type_int, "channel");
f->addArg(type_int, "note");
f->addArg(type_int, "velocity");
f = type_snd_seq_event_t->addMethod(type_void, "setNoteOff",
(void *)snd_seq_event_setNoteOff
);
f->addArg(type_int, "channel");
f->addArg(type_int, "note");
f->addArg(type_int, "velocity");
f = type_snd_seq_event_t->addMethod(type_void, "scheduleTick",
(void *)snd_seq_event_scheduleTick
);
f->addArg(type_int, "queue");
f->addArg(type_int, "relative");
f->addArg(type_int, "time");
type_snd_seq_event_t->finish();
f = mod->addFunc(type_int, "snd_seq_open",
(void *)snd_seq_open
);
f->addArg(array_psnd__seq__t_q, "seqp");
f->addArg(type_byteptr, "name");
f->addArg(type_int, "streams");
f->addArg(type_int, "mode");
f = mod->addFunc(type_int, "snd_seq_set_client_name",
(void *)snd_seq_set_client_name
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_byteptr, "name");
f = mod->addFunc(type_int, "snd_seq_create_simple_port",
(void *)snd_seq_create_simple_port
);
f->addArg(type_snd_seq_t, "handle");
f->addArg(type_byteptr, "name");
f->addArg(type_int, "caps");
f->addArg(type_int, "type");
f = mod->addFunc(type_int, "snd_seq_connect_to",
(void *)snd_seq_connect_to
);
f->addArg(type_snd_seq_t, "seq");
f->addArg(type_int, "myport");
f->addArg(type_int, "dest_client");
f->addArg(type_int, "dest_port");
f = mod->addFunc(type_int, "snd_seq_event_output",
(void *)snd_seq_event_output
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_snd_seq_event_t, "event");
f = mod->addFunc(type_int, "snd_seq_drain_output",
(void *)snd_seq_drain_output
);
f->addArg(type_snd_seq_t, "seqp");
f = mod->addFunc(type_int, "snd_seq_alloc_named_queue",
(void *)snd_seq_alloc_named_queue
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_byteptr, "name");
f = mod->addFunc(type_int, "SndSeqQueue_setTempo",
(void *)SndSeqQueue_setTempo
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_int, "queueId");
f->addArg(type_int, "tempo");
f->addArg(type_int, "ppq");
f = mod->addFunc(type_void, "SndSeqQueue_start",
(void *)SndSeqQueue_start
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_int, "queueId");
f->addArg(type_snd_seq_event_t, "event");
f = mod->addFunc(type_void, "SndSeqQueue_stop",
(void *)SndSeqQueue_stop
);
f->addArg(type_snd_seq_t, "seqp");
f->addArg(type_int, "queueId");
f->addArg(type_snd_seq_event_t, "event");
mod->addConstant(type_int, "SND_SEQ_OPEN_INPUT",
static_cast<int>(SND_SEQ_OPEN_INPUT)
);
mod->addConstant(type_int, "SND_SEQ_OPEN_OUTPUT",
static_cast<int>(SND_SEQ_OPEN_OUTPUT)
);
mod->addConstant(type_int, "SND_SEQ_OPEN_DUPLEX",
static_cast<int>(SND_SEQ_OPEN_DUPLEX)
);
mod->addConstant(type_int, "SND_SEQ_PORT_CAP_WRITE",
static_cast<int>(SND_SEQ_PORT_CAP_WRITE)
);
mod->addConstant(type_int, "SND_SEQ_PORT_CAP_SUBS_WRITE",
static_cast<int>(SND_SEQ_PORT_CAP_SUBS_WRITE)
);
mod->addConstant(type_int, "SND_SEQ_PORT_CAP_READ",
static_cast<int>(SND_SEQ_PORT_CAP_READ)
);
mod->addConstant(type_int, "SND_SEQ_PORT_CAP_SUBS_READ",
static_cast<int>(SND_SEQ_PORT_CAP_SUBS_READ)
);
mod->addConstant(type_int, "SND_SEQ_PORT_TYPE_MIDI_GENERIC",
static_cast<int>(SND_SEQ_PORT_TYPE_MIDI_GENERIC)
);
}
| C++ |
#include <GL/gl.h>
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__gl_rinit() {
return;
}
extern "C"
void crack_ext__gl_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pfloat64_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_float64;
array_pfloat64_q = array->getSpecialization(params);
}
crack::ext::Type *array_pfloat32_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_float32;
array_pfloat32_q = array->getSpecialization(params);
}
crack::ext::Type *array_pint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_int;
array_pint_q = array->getSpecialization(params);
}
crack::ext::Type *array_pbyte_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_byte;
array_pbyte_q = array->getSpecialization(params);
}
crack::ext::Type *array_puint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_uint;
array_puint_q = array->getSpecialization(params);
}
crack::ext::Type *array_pfloat_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_float;
array_pfloat_q = array->getSpecialization(params);
}
f = mod->addFunc(type_uint, "glGetError",
(void *)glGetError
);
f = mod->addFunc(type_void, "glMatrixMode",
(void *)glMatrixMode
);
f->addArg(type_uint, "mode");
f = mod->addFunc(type_void, "glLoadIdentity",
(void *)glLoadIdentity
);
f = mod->addFunc(type_void, "glFrustum",
(void *)glFrustum
);
f->addArg(type_float64, "left");
f->addArg(type_float64, "right");
f->addArg(type_float64, "bottom");
f->addArg(type_float64, "top");
f->addArg(type_float64, "nearVal");
f->addArg(type_float64, "farVal");
f = mod->addFunc(type_void, "glFlush",
(void *)glFlush
);
f = mod->addFunc(type_void, "glMultMatrixd",
(void *)glMultMatrixd
);
f->addArg(array_pfloat64_q, "matrix");
f = mod->addFunc(type_void, "glMultMatrixf",
(void *)glMultMatrixf
);
f->addArg(array_pfloat32_q, "matrix");
f = mod->addFunc(type_void, "glTranslated",
(void *)glTranslated
);
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_float64, "z");
f = mod->addFunc(type_void, "glTranslatef",
(void *)glTranslatef
);
f->addArg(type_float32, "x");
f->addArg(type_float32, "y");
f->addArg(type_float32, "z");
f = mod->addFunc(type_void, "glBegin",
(void *)glBegin
);
f->addArg(type_uint, "mode");
f = mod->addFunc(type_void, "glEnd",
(void *)glEnd
);
f = mod->addFunc(type_void, "glVertex2d",
(void *)glVertex2d
);
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f = mod->addFunc(type_void, "glVertex2f",
(void *)glVertex2f
);
f->addArg(type_float32, "x");
f->addArg(type_float32, "y");
f = mod->addFunc(type_void, "glVertex2i",
(void *)glVertex2i
);
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f = mod->addFunc(type_void, "glVertex3d",
(void *)glVertex3d
);
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_float64, "z");
f = mod->addFunc(type_void, "glVertex3f",
(void *)glVertex3f
);
f->addArg(type_float32, "x");
f->addArg(type_float32, "y");
f->addArg(type_float32, "z");
f = mod->addFunc(type_void, "glVertex3i",
(void *)glVertex3i
);
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "z");
f = mod->addFunc(type_void, "glVertex4d",
(void *)glVertex4d
);
f->addArg(type_float64, "x");
f->addArg(type_float64, "y");
f->addArg(type_float64, "z");
f->addArg(type_float64, "w");
f = mod->addFunc(type_void, "glVertex4f",
(void *)glVertex4f
);
f->addArg(type_float32, "x");
f->addArg(type_float32, "y");
f->addArg(type_float32, "z");
f->addArg(type_float32, "w");
f = mod->addFunc(type_void, "glVertex4i",
(void *)glVertex4i
);
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "z");
f->addArg(type_int, "w");
f = mod->addFunc(type_void, "glVertex2dv",
(void *)glVertex2dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glVertex2fv",
(void *)glVertex2fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glVertex2iv",
(void *)glVertex2iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glVertex3dv",
(void *)glVertex3dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glVertex3fv",
(void *)glVertex3fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glVertex3iv",
(void *)glVertex3iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glVertex4dv",
(void *)glVertex4dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glVertex4fv",
(void *)glVertex4fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glVertex4iv",
(void *)glVertex4iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glNormal3b",
(void *)glNormal3b
);
f->addArg(type_byte, "nx");
f->addArg(type_byte, "ny");
f->addArg(type_byte, "nz");
f = mod->addFunc(type_void, "glNormal3d",
(void *)glNormal3d
);
f->addArg(type_float64, "nx");
f->addArg(type_float64, "ny");
f->addArg(type_float64, "nz");
f = mod->addFunc(type_void, "glNormal3f",
(void *)glNormal3f
);
f->addArg(type_float32, "nx");
f->addArg(type_float32, "ny");
f->addArg(type_float32, "nz");
f = mod->addFunc(type_void, "glNormal3i",
(void *)glNormal3i
);
f->addArg(type_int, "nx");
f->addArg(type_int, "ny");
f->addArg(type_int, "nz");
f = mod->addFunc(type_void, "glNormal3bv",
(void *)glNormal3bv
);
f->addArg(array_pbyte_q, "v");
f = mod->addFunc(type_void, "glNormal3dv",
(void *)glNormal3dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glNormal3fv",
(void *)glNormal3fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glNormal3iv",
(void *)glNormal3iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glColor3b",
(void *)glColor3b
);
f->addArg(type_byte, "red");
f->addArg(type_byte, "green");
f->addArg(type_byte, "blue");
f = mod->addFunc(type_void, "glColor3d",
(void *)glColor3d
);
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f = mod->addFunc(type_void, "glColor3f",
(void *)glColor3f
);
f->addArg(type_float32, "red");
f->addArg(type_float32, "green");
f->addArg(type_float32, "blue");
f = mod->addFunc(type_void, "glColor3i",
(void *)glColor3i
);
f->addArg(type_int, "red");
f->addArg(type_int, "green");
f->addArg(type_int, "blue");
f = mod->addFunc(type_void, "glColor3ui",
(void *)glColor3ui
);
f->addArg(type_uint, "red");
f->addArg(type_uint, "green");
f->addArg(type_uint, "blue");
f = mod->addFunc(type_void, "glColor4b",
(void *)glColor4b
);
f->addArg(type_byte, "red");
f->addArg(type_byte, "green");
f->addArg(type_byte, "blue");
f->addArg(type_byte, "alpha");
f = mod->addFunc(type_void, "glColor4d",
(void *)glColor4d
);
f->addArg(type_float64, "red");
f->addArg(type_float64, "green");
f->addArg(type_float64, "blue");
f->addArg(type_float64, "alpha");
f = mod->addFunc(type_void, "glColor4f",
(void *)glColor4f
);
f->addArg(type_float32, "red");
f->addArg(type_float32, "green");
f->addArg(type_float32, "blue");
f->addArg(type_float32, "alpha");
f = mod->addFunc(type_void, "glColor4i",
(void *)glColor4i
);
f->addArg(type_int, "red");
f->addArg(type_int, "green");
f->addArg(type_int, "blue");
f->addArg(type_int, "alpha");
f = mod->addFunc(type_void, "glColor4ui",
(void *)glColor4ui
);
f->addArg(type_uint, "red");
f->addArg(type_uint, "green");
f->addArg(type_uint, "blue");
f->addArg(type_uint, "alpha");
f = mod->addFunc(type_void, "glColor3bv",
(void *)glColor3bv
);
f->addArg(array_pbyte_q, "v");
f = mod->addFunc(type_void, "glColor3dv",
(void *)glColor3dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glColor3fv",
(void *)glColor3fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glColor3iv",
(void *)glColor3iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glColor3uiv",
(void *)glColor3uiv
);
f->addArg(array_puint_q, "v");
f = mod->addFunc(type_void, "glColor4bv",
(void *)glColor4bv
);
f->addArg(array_pbyte_q, "v");
f = mod->addFunc(type_void, "glColor4dv",
(void *)glColor4dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glColor4fv",
(void *)glColor4fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glColor4iv",
(void *)glColor4iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glColor4uiv",
(void *)glColor4uiv
);
f->addArg(array_puint_q, "v");
f = mod->addFunc(type_void, "glViewport",
(void *)glViewport
);
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "glClearColor",
(void *)glClearColor
);
f->addArg(type_float32, "red");
f->addArg(type_float32, "green");
f->addArg(type_float32, "blue");
f->addArg(type_float32, "alpha");
f = mod->addFunc(type_void, "glClearDepth",
(void *)glClearDepth
);
f->addArg(type_float64, "depth");
f = mod->addFunc(type_void, "glClear",
(void *)glClear
);
f->addArg(type_uint, "mask");
f = mod->addFunc(type_void, "glShadeModel",
(void *)glShadeModel
);
f->addArg(type_uint, "mode");
f = mod->addFunc(type_void, "glPolygonMode",
(void *)glPolygonMode
);
f->addArg(type_uint, "face");
f->addArg(type_uint, "mode");
f = mod->addFunc(type_void, "glLightf",
(void *)glLightf
);
f->addArg(type_uint, "light");
f->addArg(type_uint, "pname");
f->addArg(type_float32, "param");
f = mod->addFunc(type_void, "glLighti",
(void *)glLighti
);
f->addArg(type_uint, "light");
f->addArg(type_uint, "pname");
f->addArg(type_int, "param");
f = mod->addFunc(type_void, "glLightfv",
(void *)glLightfv
);
f->addArg(type_uint, "light");
f->addArg(type_uint, "pname");
f->addArg(array_pfloat32_q, "params");
f = mod->addFunc(type_void, "glLightiv",
(void *)glLightiv
);
f->addArg(type_uint, "light");
f->addArg(type_uint, "pname");
f->addArg(array_pint_q, "params");
f = mod->addFunc(type_void, "glEnable",
(void *)glEnable
);
f->addArg(type_uint, "cap");
f = mod->addFunc(type_void, "glDisable",
(void *)glDisable
);
f->addArg(type_uint, "cap");
f = mod->addFunc(type_void, "glDepthFunc",
(void *)glDepthFunc
);
f->addArg(type_uint, "func");
f = mod->addFunc(type_void, "glDepthMask",
(void *)glDepthMask
);
f->addArg(type_bool, "flag");
f = mod->addFunc(type_void, "glHint",
(void *)glHint
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "mode");
f = mod->addFunc(type_void, "glGenTextures",
(void *)glGenTextures
);
f->addArg(type_int, "n");
f->addArg(array_puint_q, "textures");
f = mod->addFunc(type_void, "glDeleteTextures",
(void *)glDeleteTextures
);
f->addArg(type_int, "n");
f->addArg(array_puint_q, "textures");
f = mod->addFunc(type_void, "glBindTexture",
(void *)glBindTexture
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "texture");
f = mod->addFunc(type_void, "glTexImage2D",
(void *)glTexImage2D
);
f->addArg(type_uint, "target");
f->addArg(type_int, "level");
f->addArg(type_int, "internalFormat");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f->addArg(type_int, "border");
f->addArg(type_uint, "format");
f->addArg(type_uint, "type");
f->addArg(type_voidptr, "pixels");
f = mod->addFunc(type_void, "glTexParameterf",
(void *)glTexParameterf
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(type_float, "param");
f = mod->addFunc(type_void, "glTexParameteri",
(void *)glTexParameteri
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(type_int, "param");
f = mod->addFunc(type_void, "glTexParameterfv",
(void *)glTexParameterfv
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(array_pfloat_q, "params");
f = mod->addFunc(type_void, "glTexParameteriv",
(void *)glTexParameteriv
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(array_pint_q, "params");
f = mod->addFunc(type_void, "glGetTexParameterfv",
(void *)glGetTexParameterfv
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(array_pfloat_q, "params");
f = mod->addFunc(type_void, "glGetTexParameteriv",
(void *)glGetTexParameteriv
);
f->addArg(type_uint, "target");
f->addArg(type_uint, "pname");
f->addArg(array_pint_q, "params");
f = mod->addFunc(type_void, "glGetTexLevelParameterfv",
(void *)glGetTexLevelParameterfv
);
f->addArg(type_uint, "target");
f->addArg(type_int, "level");
f->addArg(type_uint, "pname");
f->addArg(array_pfloat_q, "params");
f = mod->addFunc(type_void, "glGetTexLevelParameteriv",
(void *)glGetTexLevelParameteriv
);
f->addArg(type_uint, "target");
f->addArg(type_int, "level");
f->addArg(type_uint, "pname");
f->addArg(array_pint_q, "params");
f = mod->addFunc(type_void, "glTexCoord1d",
(void *)glTexCoord1d
);
f->addArg(type_float64, "s");
f = mod->addFunc(type_void, "glTexCoord1f",
(void *)glTexCoord1f
);
f->addArg(type_float32, "s");
f = mod->addFunc(type_void, "glTexCoord1i",
(void *)glTexCoord1i
);
f->addArg(type_int, "s");
f = mod->addFunc(type_void, "glTexCoord2d",
(void *)glTexCoord2d
);
f->addArg(type_float64, "s");
f->addArg(type_float64, "t");
f = mod->addFunc(type_void, "glTexCoord2f",
(void *)glTexCoord2f
);
f->addArg(type_float32, "s");
f->addArg(type_float32, "t");
f = mod->addFunc(type_void, "glTexCoord2i",
(void *)glTexCoord2i
);
f->addArg(type_int, "s");
f->addArg(type_int, "t");
f = mod->addFunc(type_void, "glTexCoord3d",
(void *)glTexCoord3d
);
f->addArg(type_float64, "s");
f->addArg(type_float64, "t");
f->addArg(type_float64, "r");
f = mod->addFunc(type_void, "glTexCoord3f",
(void *)glTexCoord3f
);
f->addArg(type_float32, "s");
f->addArg(type_float32, "t");
f->addArg(type_float32, "r");
f = mod->addFunc(type_void, "glTexCoord3i",
(void *)glTexCoord3i
);
f->addArg(type_int, "s");
f->addArg(type_int, "t");
f->addArg(type_int, "r");
f = mod->addFunc(type_void, "glTexCoord4d",
(void *)glTexCoord4d
);
f->addArg(type_float64, "s");
f->addArg(type_float64, "t");
f->addArg(type_float64, "r");
f->addArg(type_float64, "q");
f = mod->addFunc(type_void, "glTexCoord4f",
(void *)glTexCoord4f
);
f->addArg(type_float32, "s");
f->addArg(type_float32, "t");
f->addArg(type_float32, "r");
f->addArg(type_float32, "q");
f = mod->addFunc(type_void, "glTexCoord4i",
(void *)glTexCoord4i
);
f->addArg(type_int, "s");
f->addArg(type_int, "t");
f->addArg(type_int, "r");
f->addArg(type_int, "q");
f = mod->addFunc(type_void, "glTexCoord1dv",
(void *)glTexCoord1dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glTexCoord1fv",
(void *)glTexCoord1fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glTexCoord1iv",
(void *)glTexCoord1iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glTexCoord2dv",
(void *)glTexCoord2dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glTexCoord2fv",
(void *)glTexCoord2fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glTexCoord2iv",
(void *)glTexCoord2iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glTexCoord3dv",
(void *)glTexCoord3dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glTexCoord3fv",
(void *)glTexCoord3fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glTexCoord3iv",
(void *)glTexCoord3iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glTexCoord4dv",
(void *)glTexCoord4dv
);
f->addArg(array_pfloat64_q, "v");
f = mod->addFunc(type_void, "glTexCoord4fv",
(void *)glTexCoord4fv
);
f->addArg(array_pfloat32_q, "v");
f = mod->addFunc(type_void, "glTexCoord4iv",
(void *)glTexCoord4iv
);
f->addArg(array_pint_q, "v");
f = mod->addFunc(type_void, "glBlendFunc",
(void *)glBlendFunc
);
f->addArg(type_uint, "sfactor");
f->addArg(type_uint, "dfactor");
mod->addConstant(type_uint, "GL_PROJECTION",
static_cast<int>(GL_PROJECTION)
);
mod->addConstant(type_uint, "GL_MODELVIEW",
static_cast<int>(GL_MODELVIEW)
);
mod->addConstant(type_uint, "GL_BYTE",
static_cast<int>(GL_BYTE)
);
mod->addConstant(type_uint, "GL_UNSIGNED_BYTE",
static_cast<int>(GL_UNSIGNED_BYTE)
);
mod->addConstant(type_uint, "GL_SHORT",
static_cast<int>(GL_SHORT)
);
mod->addConstant(type_uint, "GL_UNSIGNED_SHORT",
static_cast<int>(GL_UNSIGNED_SHORT)
);
mod->addConstant(type_uint, "GL_INT",
static_cast<int>(GL_INT)
);
mod->addConstant(type_uint, "GL_UNSIGNED_INT",
static_cast<int>(GL_UNSIGNED_INT)
);
mod->addConstant(type_uint, "GL_FLOAT",
static_cast<int>(GL_FLOAT)
);
mod->addConstant(type_uint, "GL_2_BYTES",
static_cast<int>(GL_2_BYTES)
);
mod->addConstant(type_uint, "GL_3_BYTES",
static_cast<int>(GL_3_BYTES)
);
mod->addConstant(type_uint, "GL_4_BYTES",
static_cast<int>(GL_4_BYTES)
);
mod->addConstant(type_uint, "GL_DOUBLE",
static_cast<int>(GL_DOUBLE)
);
mod->addConstant(type_uint, "GL_POINTS",
static_cast<int>(GL_POINTS)
);
mod->addConstant(type_uint, "GL_LINES",
static_cast<int>(GL_LINES)
);
mod->addConstant(type_uint, "GL_LINE_LOOP",
static_cast<int>(GL_LINE_LOOP)
);
mod->addConstant(type_uint, "GL_LINE_STRIP",
static_cast<int>(GL_LINE_STRIP)
);
mod->addConstant(type_uint, "GL_TRIANGLES",
static_cast<int>(GL_TRIANGLES)
);
mod->addConstant(type_uint, "GL_TRIANGLE_STRIP",
static_cast<int>(GL_TRIANGLE_STRIP)
);
mod->addConstant(type_uint, "GL_TRIANGLE_FAN",
static_cast<int>(GL_TRIANGLE_FAN)
);
mod->addConstant(type_uint, "GL_QUADS",
static_cast<int>(GL_QUADS)
);
mod->addConstant(type_uint, "GL_QUAD_STRIP",
static_cast<int>(GL_QUAD_STRIP)
);
mod->addConstant(type_uint, "GL_POLYGON",
static_cast<int>(GL_POLYGON)
);
mod->addConstant(type_uint, "GL_CURRENT_BIT",
static_cast<int>(GL_CURRENT_BIT)
);
mod->addConstant(type_uint, "GL_POINT_BIT",
static_cast<int>(GL_POINT_BIT)
);
mod->addConstant(type_uint, "GL_LINE_BIT",
static_cast<int>(GL_LINE_BIT)
);
mod->addConstant(type_uint, "GL_POLYGON_BIT",
static_cast<int>(GL_POLYGON_BIT)
);
mod->addConstant(type_uint, "GL_POLYGON_STIPPLE_BIT",
static_cast<int>(GL_POLYGON_STIPPLE_BIT)
);
mod->addConstant(type_uint, "GL_PIXEL_MODE_BIT",
static_cast<int>(GL_PIXEL_MODE_BIT)
);
mod->addConstant(type_uint, "GL_LIGHTING_BIT",
static_cast<int>(GL_LIGHTING_BIT)
);
mod->addConstant(type_uint, "GL_FOG_BIT",
static_cast<int>(GL_FOG_BIT)
);
mod->addConstant(type_uint, "GL_DEPTH_BUFFER_BIT",
static_cast<int>(GL_DEPTH_BUFFER_BIT)
);
mod->addConstant(type_uint, "GL_ACCUM_BUFFER_BIT",
static_cast<int>(GL_ACCUM_BUFFER_BIT)
);
mod->addConstant(type_uint, "GL_STENCIL_BUFFER_BIT",
static_cast<int>(GL_STENCIL_BUFFER_BIT)
);
mod->addConstant(type_uint, "GL_VIEWPORT_BIT",
static_cast<int>(GL_VIEWPORT_BIT)
);
mod->addConstant(type_uint, "GL_TRANSFORM_BIT",
static_cast<int>(GL_TRANSFORM_BIT)
);
mod->addConstant(type_uint, "GL_ENABLE_BIT",
static_cast<int>(GL_ENABLE_BIT)
);
mod->addConstant(type_uint, "GL_COLOR_BUFFER_BIT",
static_cast<int>(GL_COLOR_BUFFER_BIT)
);
mod->addConstant(type_uint, "GL_HINT_BIT",
static_cast<int>(GL_HINT_BIT)
);
mod->addConstant(type_uint, "GL_EVAL_BIT",
static_cast<int>(GL_EVAL_BIT)
);
mod->addConstant(type_uint, "GL_LIST_BIT",
static_cast<int>(GL_LIST_BIT)
);
mod->addConstant(type_uint, "GL_TEXTURE_BIT",
static_cast<int>(GL_TEXTURE_BIT)
);
mod->addConstant(type_uint, "GL_SCISSOR_BIT",
static_cast<int>(GL_SCISSOR_BIT)
);
mod->addConstant(type_uint, "GL_ALL_ATTRIB_BITS",
static_cast<int>(GL_ALL_ATTRIB_BITS)
);
mod->addConstant(type_uint, "GL_FILL",
static_cast<int>(GL_FILL)
);
mod->addConstant(type_uint, "GL_SMOOTH",
static_cast<int>(GL_SMOOTH)
);
mod->addConstant(type_uint, "GL_FRONT_AND_BACK",
static_cast<int>(GL_FRONT_AND_BACK)
);
mod->addConstant(type_uint, "GL_LIGHTING",
static_cast<int>(GL_LIGHTING)
);
mod->addConstant(type_uint, "GL_LIGHT0",
static_cast<int>(GL_LIGHT0)
);
mod->addConstant(type_uint, "GL_LIGHT1",
static_cast<int>(GL_LIGHT1)
);
mod->addConstant(type_uint, "GL_LIGHT2",
static_cast<int>(GL_LIGHT2)
);
mod->addConstant(type_uint, "GL_LIGHT3",
static_cast<int>(GL_LIGHT3)
);
mod->addConstant(type_uint, "GL_LIGHT4",
static_cast<int>(GL_LIGHT4)
);
mod->addConstant(type_uint, "GL_LIGHT5",
static_cast<int>(GL_LIGHT5)
);
mod->addConstant(type_uint, "GL_LIGHT6",
static_cast<int>(GL_LIGHT6)
);
mod->addConstant(type_uint, "GL_LIGHT7",
static_cast<int>(GL_LIGHT7)
);
mod->addConstant(type_uint, "GL_SPOT_EXPONENT",
static_cast<int>(GL_SPOT_EXPONENT)
);
mod->addConstant(type_uint, "GL_SPOT_CUTOFF",
static_cast<int>(GL_SPOT_CUTOFF)
);
mod->addConstant(type_uint, "GL_CONSTANT_ATTENUATION",
static_cast<int>(GL_CONSTANT_ATTENUATION)
);
mod->addConstant(type_uint, "GL_LINEAR_ATTENUATION",
static_cast<int>(GL_LINEAR_ATTENUATION)
);
mod->addConstant(type_uint, "GL_QUADRATIC_ATTENUATION",
static_cast<int>(GL_QUADRATIC_ATTENUATION)
);
mod->addConstant(type_uint, "GL_AMBIENT",
static_cast<int>(GL_AMBIENT)
);
mod->addConstant(type_uint, "GL_DIFFUSE",
static_cast<int>(GL_DIFFUSE)
);
mod->addConstant(type_uint, "GL_SPECULAR",
static_cast<int>(GL_SPECULAR)
);
mod->addConstant(type_uint, "GL_SHININESS",
static_cast<int>(GL_SHININESS)
);
mod->addConstant(type_uint, "GL_EMISSION",
static_cast<int>(GL_EMISSION)
);
mod->addConstant(type_uint, "GL_POSITION",
static_cast<int>(GL_POSITION)
);
mod->addConstant(type_uint, "GL_SPOT_DIRECTION",
static_cast<int>(GL_SPOT_DIRECTION)
);
mod->addConstant(type_uint, "GL_AMBIENT_AND_DIFFUSE",
static_cast<int>(GL_AMBIENT_AND_DIFFUSE)
);
mod->addConstant(type_uint, "GL_COLOR_INDEXES",
static_cast<int>(GL_COLOR_INDEXES)
);
mod->addConstant(type_uint, "GL_LIGHT_MODEL_TWO_SIDE",
static_cast<int>(GL_LIGHT_MODEL_TWO_SIDE)
);
mod->addConstant(type_uint, "GL_LIGHT_MODEL_LOCAL_VIEWER",
static_cast<int>(GL_LIGHT_MODEL_LOCAL_VIEWER)
);
mod->addConstant(type_uint, "GL_LIGHT_MODEL_AMBIENT",
static_cast<int>(GL_LIGHT_MODEL_AMBIENT)
);
mod->addConstant(type_uint, "GL_FRONT_AND_BACK",
static_cast<int>(GL_FRONT_AND_BACK)
);
mod->addConstant(type_uint, "GL_SHADE_MODEL",
static_cast<int>(GL_SHADE_MODEL)
);
mod->addConstant(type_uint, "GL_FLAT",
static_cast<int>(GL_FLAT)
);
mod->addConstant(type_uint, "GL_SMOOTH",
static_cast<int>(GL_SMOOTH)
);
mod->addConstant(type_uint, "GL_COLOR_MATERIAL",
static_cast<int>(GL_COLOR_MATERIAL)
);
mod->addConstant(type_uint, "GL_COLOR_MATERIAL_FACE",
static_cast<int>(GL_COLOR_MATERIAL_FACE)
);
mod->addConstant(type_uint, "GL_COLOR_MATERIAL_PARAMETER",
static_cast<int>(GL_COLOR_MATERIAL_PARAMETER)
);
mod->addConstant(type_uint, "GL_NORMALIZE",
static_cast<int>(GL_NORMALIZE)
);
mod->addConstant(type_uint, "GL_DEPTH_TEST",
static_cast<int>(GL_DEPTH_TEST)
);
mod->addConstant(type_uint, "GL_TEXTURE_2D",
static_cast<int>(GL_TEXTURE_2D)
);
mod->addConstant(type_uint, "GL_LIGHTING",
static_cast<int>(GL_LIGHTING)
);
mod->addConstant(type_uint, "GL_LEQUAL",
static_cast<int>(GL_LEQUAL)
);
mod->addConstant(type_uint, "GL_PERSPECTIVE_CORRECTION_HINT",
static_cast<int>(GL_PERSPECTIVE_CORRECTION_HINT)
);
mod->addConstant(type_uint, "GL_POINT_SMOOTH_HINT",
static_cast<int>(GL_POINT_SMOOTH_HINT)
);
mod->addConstant(type_uint, "GL_LINE_SMOOTH_HINT",
static_cast<int>(GL_LINE_SMOOTH_HINT)
);
mod->addConstant(type_uint, "GL_POLYGON_SMOOTH_HINT",
static_cast<int>(GL_POLYGON_SMOOTH_HINT)
);
mod->addConstant(type_uint, "GL_FOG_HINT",
static_cast<int>(GL_FOG_HINT)
);
mod->addConstant(type_uint, "GL_DONT_CARE",
static_cast<int>(GL_DONT_CARE)
);
mod->addConstant(type_uint, "GL_FASTEST",
static_cast<int>(GL_FASTEST)
);
mod->addConstant(type_uint, "GL_NICEST",
static_cast<int>(GL_NICEST)
);
mod->addConstant(type_uint, "GL_FOG",
static_cast<int>(GL_FOG)
);
mod->addConstant(type_uint, "GL_FOG_MODE",
static_cast<int>(GL_FOG_MODE)
);
mod->addConstant(type_uint, "GL_FOG_DENSITY",
static_cast<int>(GL_FOG_DENSITY)
);
mod->addConstant(type_uint, "GL_FOG_COLOR",
static_cast<int>(GL_FOG_COLOR)
);
mod->addConstant(type_uint, "GL_FOG_INDEX",
static_cast<int>(GL_FOG_INDEX)
);
mod->addConstant(type_uint, "GL_FOG_START",
static_cast<int>(GL_FOG_START)
);
mod->addConstant(type_uint, "GL_FOG_END",
static_cast<int>(GL_FOG_END)
);
mod->addConstant(type_uint, "GL_LINEAR",
static_cast<int>(GL_LINEAR)
);
mod->addConstant(type_uint, "GL_EXP",
static_cast<int>(GL_EXP)
);
mod->addConstant(type_uint, "GL_EXP2",
static_cast<int>(GL_EXP2)
);
mod->addConstant(type_uint, "GL_TEXTURE_MIN_FILTER",
static_cast<int>(GL_TEXTURE_MIN_FILTER)
);
mod->addConstant(type_uint, "GL_TEXTURE_MAG_FILTER",
static_cast<int>(GL_TEXTURE_MAG_FILTER)
);
mod->addConstant(type_uint, "GL_RGB",
static_cast<int>(GL_RGB)
);
mod->addConstant(type_uint, "GL_RGBA",
static_cast<int>(GL_RGBA)
);
mod->addConstant(type_uint, "GL_RGB8",
static_cast<int>(GL_RGB8)
);
mod->addConstant(type_uint, "GL_RGBA8",
static_cast<int>(GL_RGBA8)
);
mod->addConstant(type_uint, "GL_BLEND",
static_cast<int>(GL_BLEND)
);
mod->addConstant(type_uint, "GL_BLEND_SRC",
static_cast<int>(GL_BLEND_SRC)
);
mod->addConstant(type_uint, "GL_BLEND_DST",
static_cast<int>(GL_BLEND_DST)
);
mod->addConstant(type_uint, "GL_ZERO",
static_cast<int>(GL_ZERO)
);
mod->addConstant(type_uint, "GL_ONE",
static_cast<int>(GL_ONE)
);
mod->addConstant(type_uint, "GL_SRC_COLOR",
static_cast<int>(GL_SRC_COLOR)
);
mod->addConstant(type_uint, "GL_ONE_MINUS_SRC_COLOR",
static_cast<int>(GL_ONE_MINUS_SRC_COLOR)
);
mod->addConstant(type_uint, "GL_SRC_ALPHA",
static_cast<int>(GL_SRC_ALPHA)
);
mod->addConstant(type_uint, "GL_ONE_MINUS_SRC_ALPHA",
static_cast<int>(GL_ONE_MINUS_SRC_ALPHA)
);
mod->addConstant(type_uint, "GL_DST_ALPHA",
static_cast<int>(GL_DST_ALPHA)
);
mod->addConstant(type_uint, "GL_ONE_MINUS_DST_ALPHA",
static_cast<int>(GL_ONE_MINUS_DST_ALPHA)
);
mod->addConstant(type_uint, "GL_DST_COLOR",
static_cast<int>(GL_DST_COLOR)
);
mod->addConstant(type_uint, "GL_ONE_MINUS_DST_COLOR",
static_cast<int>(GL_ONE_MINUS_DST_COLOR)
);
mod->addConstant(type_uint, "GL_SRC_ALPHA_SATURATE",
static_cast<int>(GL_SRC_ALPHA_SATURATE)
);
}
| C++ |
#include <SDL.h>
SDL_Event *SDL_EventNew() { return new SDL_Event; }
int SDL_Event_GetType(SDL_Event *evt) { return evt->type; }
SDL_KeyboardEvent *SDL_Event_GetKey(SDL_Event *evt) { return &evt->key; }
SDL_keysym *SDL_KeyboardEvent_GetKeysym(SDL_KeyboardEvent *evt) { return &evt->keysym; }
unsigned SDL_keysym_GetScancode(SDL_keysym *s) { return s->scancode; }
unsigned SDL_keysym_GetSym(SDL_keysym *s) { return s->sym; }
unsigned SDL_keysym_GetMod(SDL_keysym *s) { return s->mod; }
unsigned SDL_keysym_GetUnicode(SDL_keysym *s) { return s->unicode; }
uint8_t SDL_KeyboardEvent_GetType(SDL_KeyboardEvent *evt) { return evt->type; }
uint8_t SDL_KeyboardEvent_GetWhich(SDL_KeyboardEvent *evt) { return evt->which; }
uint8_t SDL_KeyboardEvent_GetState(SDL_KeyboardEvent *evt) { return evt->state; }
SDL_MouseMotionEvent *SDL_Event_GetMotion(SDL_Event *evt) { return &evt->motion; }
uint SDL_MouseMotionEvent_GetX(SDL_MouseMotionEvent *evt) { return evt->x; }
uint SDL_MouseMotionEvent_GetY(SDL_MouseMotionEvent *evt) { return evt->y; }
SDL_ResizeEvent *SDL_Event_GetResize(SDL_Event *evt) { return &evt->resize; }
int16_t SDL_ResizeEvent_GetW(SDL_ResizeEvent *evt) { return evt->w; }
int16_t SDL_ResizeEvent_GetH(SDL_ResizeEvent *evt) { return evt->h; }
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__sdl_rinit() {
return;
}
extern "C"
void crack_ext__sdl_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int16 = mod->getInt16Type();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint16 = mod->getUint16Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_SDL_Surface = mod->addType("SDL_Surface", sizeof(SDL_Surface));
type_SDL_Surface->finish();
crack::ext::Type *type_SDL_Event = mod->addType("SDL_Event", sizeof(SDL_Event));
type_SDL_Event->finish();
crack::ext::Type *type_SDL_Rect = mod->addType("SDL_Rect", sizeof(SDL_Rect));
type_SDL_Rect->finish();
crack::ext::Type *type_SDL_KeyboardEvent = mod->addType("SDL_KeyboardEvent", sizeof(SDL_KeyboardEvent));
type_SDL_KeyboardEvent->finish();
crack::ext::Type *type_SDL_keysym = mod->addType("SDL_keysym", sizeof(SDL_keysym));
type_SDL_keysym->finish();
crack::ext::Type *type_SDL_MouseMotionEvent = mod->addType("SDL_MouseMotionEvent", sizeof(SDL_MouseMotionEvent));
type_SDL_MouseMotionEvent->finish();
crack::ext::Type *type_SDL_ResizeEvent = mod->addType("SDL_ResizeEvent", sizeof(SDL_ResizeEvent));
type_SDL_ResizeEvent->finish();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_int;
array_pint_q = array->getSpecialization(params);
}
f = mod->addFunc(type_int, "SDL_Init",
(void *)SDL_Init
);
f->addArg(type_uint32, "flags");
f = mod->addFunc(type_int, "SDL_Quit",
(void *)SDL_Quit
);
f = mod->addFunc(type_SDL_Surface, "SDL_SetVideoMode",
(void *)SDL_SetVideoMode
);
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f->addArg(type_int, "bpp");
f->addArg(type_uint32, "flags");
f = mod->addFunc(type_SDL_Event, "SDL_EventNew",
(void *)SDL_EventNew
);
f = mod->addFunc(type_int, "SDL_Event_GetType",
(void *)SDL_Event_GetType
);
f->addArg(type_SDL_Event, "event");
f = mod->addFunc(type_int, "SDL_Flip",
(void *)SDL_Flip
);
f->addArg(type_SDL_Surface, "screen");
f = mod->addFunc(type_int, "SDL_FillRect",
(void *)SDL_FillRect
);
f->addArg(type_SDL_Surface, "surface");
f->addArg(type_SDL_Rect, "rect");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_SDL_KeyboardEvent, "SDL_Event_GetKey",
(void *)SDL_Event_GetKey
);
f->addArg(type_SDL_Event, "evt");
f = mod->addFunc(type_SDL_keysym, "SDL_KeyboardEvent_GetKeysym",
(void *)SDL_KeyboardEvent_GetKeysym
);
f->addArg(type_SDL_KeyboardEvent, "evt");
f = mod->addFunc(type_uint, "SDL_keysym_GetScancode",
(void *)SDL_keysym_GetScancode
);
f->addArg(type_SDL_keysym, "keysym");
f = mod->addFunc(type_uint, "SDL_keysym_GetSym",
(void *)SDL_keysym_GetSym
);
f->addArg(type_SDL_keysym, "keysym");
f = mod->addFunc(type_uint, "SDL_keysym_GetMod",
(void *)SDL_keysym_GetMod
);
f->addArg(type_SDL_keysym, "keysym");
f = mod->addFunc(type_uint, "SDL_keysym_GetUnicode",
(void *)SDL_keysym_GetUnicode
);
f->addArg(type_SDL_keysym, "keysym");
f = mod->addFunc(type_byte, "SDL_KeyboardEvent_GetType",
(void *)SDL_KeyboardEvent_GetType
);
f->addArg(type_SDL_KeyboardEvent, "evt");
f = mod->addFunc(type_byte, "SDL_KeyboardEvent_GetWhich",
(void *)SDL_KeyboardEvent_GetWhich
);
f->addArg(type_SDL_KeyboardEvent, "evt");
f = mod->addFunc(type_byte, "SDL_KeyboardEvent_GetState",
(void *)SDL_KeyboardEvent_GetState
);
f->addArg(type_SDL_KeyboardEvent, "evt");
f = mod->addFunc(type_SDL_MouseMotionEvent, "SDL_Event_GetMotion",
(void *)SDL_Event_GetMotion
);
f->addArg(type_SDL_Event, "evt");
f = mod->addFunc(type_uint, "SDL_MouseMotionEvent_GetX",
(void *)SDL_MouseMotionEvent_GetX
);
f->addArg(type_SDL_MouseMotionEvent, "evt");
f = mod->addFunc(type_uint, "SDL_MouseMotionEvent_GetY",
(void *)SDL_MouseMotionEvent_GetY
);
f->addArg(type_SDL_MouseMotionEvent, "evt");
f = mod->addFunc(type_SDL_ResizeEvent, "SDL_Event_GetResize",
(void *)SDL_Event_GetResize
);
f->addArg(type_SDL_Event, "evt");
f = mod->addFunc(type_int16, "SDL_ResizeEvent_GetW",
(void *)SDL_ResizeEvent_GetW
);
f->addArg(type_SDL_ResizeEvent, "evt");
f = mod->addFunc(type_int16, "SDL_ResizeEvent_GetH",
(void *)SDL_ResizeEvent_GetH
);
f->addArg(type_SDL_ResizeEvent, "evt");
f = mod->addFunc(type_void, "SDL_WarpMouse",
(void *)SDL_WarpMouse
);
f->addArg(type_uint, "x");
f->addArg(type_uint, "y");
f = mod->addFunc(type_int, "SDL_PollEvent",
(void *)SDL_PollEvent
);
f->addArg(type_SDL_Event, "event");
f = mod->addFunc(type_int, "SDL_GL_SetAttribute",
(void *)SDL_GL_SetAttribute
);
f->addArg(type_uint32, "attr");
f->addArg(type_int, "value");
f = mod->addFunc(type_int, "SDL_GL_GetAttribute",
(void *)SDL_GL_GetAttribute
);
f->addArg(type_uint32, "attr");
f->addArg(array_pint_q, "value");
f = mod->addFunc(type_void, "SDL_GL_SwapBuffers",
(void *)SDL_GL_SwapBuffers
);
mod->addConstant(type_uint32, "SDL_INIT_TIMER",
static_cast<int>(SDL_INIT_TIMER)
);
mod->addConstant(type_uint32, "SDL_INIT_AUDIO",
static_cast<int>(SDL_INIT_AUDIO)
);
mod->addConstant(type_uint32, "SDL_INIT_VIDEO",
static_cast<int>(SDL_INIT_VIDEO)
);
mod->addConstant(type_uint32, "SDL_INIT_CDROM",
static_cast<int>(SDL_INIT_CDROM)
);
mod->addConstant(type_uint32, "SDL_INIT_JOYSTICK",
static_cast<int>(SDL_INIT_JOYSTICK)
);
mod->addConstant(type_uint32, "SDL_INIT_EVERYTHING",
static_cast<int>(SDL_INIT_EVERYTHING)
);
mod->addConstant(type_uint32, "SDL_INIT_NOPARACHUTE",
static_cast<int>(SDL_INIT_NOPARACHUTE)
);
mod->addConstant(type_uint32, "SDL_INIT_EVENTTHREAD",
static_cast<int>(SDL_INIT_EVENTTHREAD)
);
mod->addConstant(type_uint32, "SDL_SWSURFACE",
static_cast<int>(SDL_SWSURFACE)
);
mod->addConstant(type_uint32, "SDL_HWSURFACE",
static_cast<int>(SDL_HWSURFACE)
);
mod->addConstant(type_uint32, "SDL_ASYNCBLIT",
static_cast<int>(SDL_ASYNCBLIT)
);
mod->addConstant(type_uint32, "SDL_ANYFORMAT",
static_cast<int>(SDL_ANYFORMAT)
);
mod->addConstant(type_uint32, "SDL_HWPALETTE",
static_cast<int>(SDL_HWPALETTE)
);
mod->addConstant(type_uint32, "SDL_DOUBLEBUF",
static_cast<int>(SDL_DOUBLEBUF)
);
mod->addConstant(type_uint32, "SDL_FULLSCREEN",
static_cast<int>(SDL_FULLSCREEN)
);
mod->addConstant(type_uint32, "SDL_OPENGL",
static_cast<int>(SDL_OPENGL)
);
mod->addConstant(type_uint32, "SDL_OPENGLBLIT",
static_cast<int>(SDL_OPENGLBLIT)
);
mod->addConstant(type_uint32, "SDL_RESIZABLE",
static_cast<int>(SDL_RESIZABLE)
);
mod->addConstant(type_uint32, "SDL_NOFRAME",
static_cast<int>(SDL_NOFRAME)
);
mod->addConstant(type_uint32, "SDL_NOEVENT",
static_cast<int>(SDL_NOEVENT)
);
mod->addConstant(type_uint32, "SDL_KEYDOWN",
static_cast<int>(SDL_KEYDOWN)
);
mod->addConstant(type_uint32, "SDL_KEYUP",
static_cast<int>(SDL_KEYUP)
);
mod->addConstant(type_uint32, "SDL_MOUSEMOTION",
static_cast<int>(SDL_MOUSEMOTION)
);
mod->addConstant(type_uint32, "SDL_MOUSEBUTTONDOWN",
static_cast<int>(SDL_MOUSEBUTTONDOWN)
);
mod->addConstant(type_uint32, "SDL_MOUSEBUTTONUP",
static_cast<int>(SDL_MOUSEBUTTONUP)
);
mod->addConstant(type_uint32, "SDL_JOYAXISMOTION",
static_cast<int>(SDL_JOYAXISMOTION)
);
mod->addConstant(type_uint32, "SDL_JOYBALLMOTION",
static_cast<int>(SDL_JOYBALLMOTION)
);
mod->addConstant(type_uint32, "SDL_JOYHATMOTION",
static_cast<int>(SDL_JOYHATMOTION)
);
mod->addConstant(type_uint32, "SDL_JOYBUTTONDOWN",
static_cast<int>(SDL_JOYBUTTONDOWN)
);
mod->addConstant(type_uint32, "SDL_JOYBUTTONUP",
static_cast<int>(SDL_JOYBUTTONUP)
);
mod->addConstant(type_uint32, "SDL_QUIT",
static_cast<int>(SDL_QUIT)
);
mod->addConstant(type_uint32, "SDL_SYSWMEVENT",
static_cast<int>(SDL_SYSWMEVENT)
);
mod->addConstant(type_uint32, "SDL_EVENT_RESERVED2",
static_cast<int>(SDL_EVENT_RESERVED2)
);
mod->addConstant(type_uint32, "SDL_EVENT_RESERVED3",
static_cast<int>(SDL_EVENT_RESERVED3)
);
mod->addConstant(type_uint32, "SDL_USEREVENT",
static_cast<int>(SDL_USEREVENT)
);
mod->addConstant(type_uint32, "SDL_VIDEORESIZE",
static_cast<int>(SDL_VIDEORESIZE)
);
mod->addConstant(type_uint32, "SDL_NUMEVENTS",
static_cast<int>(SDL_NUMEVENTS)
);
mod->addConstant(type_uint32, "SDL_GL_RED_SIZE",
static_cast<int>(SDL_GL_RED_SIZE)
);
mod->addConstant(type_uint32, "SDL_GL_GREEN_SIZE",
static_cast<int>(SDL_GL_GREEN_SIZE)
);
mod->addConstant(type_uint32, "SDL_GL_BLUE_SIZE",
static_cast<int>(SDL_GL_BLUE_SIZE)
);
mod->addConstant(type_uint32, "SDL_GL_DEPTH_SIZE",
static_cast<int>(SDL_GL_DEPTH_SIZE)
);
mod->addConstant(type_uint32, "SDL_GL_DOUBLEBUFFER",
static_cast<int>(SDL_GL_DOUBLEBUFFER)
);
}
| C++ |
#include <SDL_gfxPrimitives.h>
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__sdlgfx_rinit() {
return;
}
extern "C"
void crack_ext__sdlgfx_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
mod->inject(std::string("import crack.ext._sdl SDL_Surface;"));
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int16 = mod->getInt16Type();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint16 = mod->getUint16Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_SDL_Surface = mod->getType("SDL_Surface");
f = mod->addFunc(type_int, "pixelColor",
(void *)pixelColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "pixelRGBA",
(void *)pixelRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "hlineColor",
(void *)hlineColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "hlineRGBA",
(void *)hlineRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "vlineColor",
(void *)vlineColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "y2");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "vlineRGBA",
(void *)vlineRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "y2");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "rectangleColor",
(void *)rectangleColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y2");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "rectangleRGBA",
(void *)rectangleRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y2");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "boxColor",
(void *)boxColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y2");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "boxRGBA",
(void *)boxRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x1");
f->addArg(type_int16, "y1");
f->addArg(type_int16, "x2");
f->addArg(type_int16, "y2");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "circleColor",
(void *)circleColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_int16, "r");
f->addArg(type_uint32, "color");
f = mod->addFunc(type_int, "circleRGBA",
(void *)circleRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_int16, "rad");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "characterColor",
(void *)characterColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_byte, "c");
f->addArg(type_int32, "color");
f = mod->addFunc(type_int, "characterRGBA",
(void *)characterRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_byte, "c");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_int, "stringColor",
(void *)stringColor
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_byteptr, "c");
f->addArg(type_int32, "color");
f = mod->addFunc(type_int, "stringRGBA",
(void *)stringRGBA
);
f->addArg(type_SDL_Surface, "dst");
f->addArg(type_int16, "x");
f->addArg(type_int16, "y");
f->addArg(type_byteptr, "c");
f->addArg(type_byte, "r");
f->addArg(type_byte, "g");
f->addArg(type_byte, "b");
f->addArg(type_byte, "a");
f = mod->addFunc(type_void, "gfxPrimitivesSetFont",
(void *)gfxPrimitivesSetFont
);
f->addArg(type_byteptr, "fontdata");
f->addArg(type_int, "cw");
f->addArg(type_int, "ch");
}
| C++ |
#include "opt/cairosdl.h"
void *cairosdl_surface_create_void (void *sdl_surface){
return cairosdl_surface_create((SDL_Surface *)sdl_surface);
}
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__cairosdl_rinit() {
return;
}
extern "C"
void crack_ext__cairosdl_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
mod->inject(std::string("import crack.ext._cairo cairo_t, cairo_surface_t; import crack.ext._sdl SDL_Surface, SDL_Rect;"));
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_cairo_t = mod->getType("cairo_t");
crack::ext::Type *type_cairo_surface_t = mod->getType("cairo_surface_t");
crack::ext::Type *type_SDL_Surface = mod->getType("SDL_Surface");
crack::ext::Type *type_SDL_Rect = mod->getType("SDL_Rect");
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pSDL__Rect_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_SDL_Rect;
array_pSDL__Rect_q = array->getSpecialization(params);
}
f = mod->addFunc(type_cairo_surface_t, "cairosdl_surface_create",
(void *)cairosdl_surface_create
);
f->addArg(type_SDL_Surface, "sdl_surface");
f = mod->addFunc(type_SDL_Surface, "cairosdl_surface_get_target",
(void *)cairosdl_surface_get_target
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairosdl_surface_flush_rects",
(void *)cairosdl_surface_flush_rects
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "num_rects");
f->addArg(array_pSDL__Rect_q, "rects");
f = mod->addFunc(type_void, "cairosdl_surface_flush_rect",
(void *)cairosdl_surface_flush_rect
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "cairosdl_surface_flush",
(void *)cairosdl_surface_flush
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_void, "cairosdl_surface_mark_dirty_rects",
(void *)cairosdl_surface_mark_dirty_rects
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "num_rects");
f->addArg(array_pSDL__Rect_q, "rects");
f = mod->addFunc(type_void, "cairosdl_surface_mark_dirty_rect",
(void *)cairosdl_surface_mark_dirty_rect
);
f->addArg(type_cairo_surface_t, "surface");
f->addArg(type_int, "x");
f->addArg(type_int, "y");
f->addArg(type_int, "width");
f->addArg(type_int, "height");
f = mod->addFunc(type_void, "cairosdl_surface_mark_dirty",
(void *)cairosdl_surface_mark_dirty
);
f->addArg(type_cairo_surface_t, "surface");
f = mod->addFunc(type_cairo_t, "cairosdl_create",
(void *)cairosdl_create
);
f->addArg(type_SDL_Surface, "sdl_surface");
f = mod->addFunc(type_SDL_Surface, "cairosdl_get_target",
(void *)cairosdl_get_target
);
f->addArg(type_cairo_t, "cr");
f = mod->addFunc(type_void, "cairosdl_destroy",
(void *)cairosdl_destroy
);
f->addArg(type_cairo_t, "cr");
mod->addConstant(type_uint32, "CAIROSDL_ASHIFT",
static_cast<int>(24)
);
mod->addConstant(type_uint32, "CAIROSDL_RSHIFT",
static_cast<int>(16)
);
mod->addConstant(type_uint32, "CAIROSDL_GSHIFT",
static_cast<int>(8)
);
mod->addConstant(type_uint32, "CAIROSDL_BSHIFT",
static_cast<int>(0)
);
mod->addConstant(type_uint32, "CAIROSDL_AMASK",
static_cast<int>(4278190080)
);
mod->addConstant(type_uint32, "CAIROSDL_RMASK",
static_cast<int>(16711680)
);
mod->addConstant(type_uint32, "CAIROSDL_GMASK",
static_cast<int>(65280)
);
mod->addConstant(type_uint32, "CAIROSDL_BMASK",
static_cast<int>(0)
);
}
| C++ |
#include <gtk/gtk.h>
GtkObject *GtkObject_cast(GtkWidget *widget) {
return GTK_OBJECT(widget);
}
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__gtk_rinit() {
return;
}
extern "C"
void crack_ext__gtk_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_GList = mod->addType("GList", sizeof(GList));
type_GList->finish();
crack::ext::Type *type_GtkWidget = mod->addType("GtkWidget", sizeof(GtkWidget));
type_GtkWidget->finish();
crack::ext::Type *type_GtkObject = mod->addType("GtkObject", sizeof(GtkObject));
type_GtkObject->finish();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_int;
array_pint_q = array->getSpecialization(params);
}
crack::ext::Type *array_pbyteptr_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_byteptr;
array_pbyteptr_q = array->getSpecialization(params);
}
crack::ext::Type *array_parray_pbyteptr_q_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = array_pbyteptr_q;
array_parray_pbyteptr_q_q = array->getSpecialization(params);
}
f = mod->addFunc(type_GList, "g_list_append",
(void *)g_list_append
);
f->addArg(type_GList, "list");
f->addArg(type_voidptr, "data");
f = mod->addFunc(type_void, "g_print",
(void *)g_print
);
f->addArg(type_byteptr, "b");
f = mod->addFunc(type_void, "gtk_init",
(void *)gtk_init
);
f->addArg(array_pint_q, "argc");
f->addArg(array_parray_pbyteptr_q_q, "argv");
f = mod->addFunc(type_void, "gtk_widget_destroy",
(void *)gtk_widget_destroy
);
f->addArg(type_GtkWidget, "widget");
f = mod->addFunc(type_void, "gtk_widget_show",
(void *)gtk_widget_show
);
f->addArg(type_GtkWidget, "widget");
f = mod->addFunc(type_void, "gtk_object_destroy",
(void *)gtk_object_destroy
);
f->addArg(type_GtkObject, "object");
f = mod->addFunc(type_void, "gtk_main",
(void *)gtk_main
);
f = mod->addFunc(type_void, "gtk_main_quit",
(void *)gtk_main_quit
);
f = mod->addFunc(type_void, "g_signal_connect_data",
(void *)g_signal_connect_data
);
f->addArg(type_GtkObject, "widget");
f->addArg(type_byteptr, "signal");
f->addArg(type_voidptr, "callback");
f->addArg(type_voidptr, "callbackArg");
f->addArg(type_voidptr, "destroy_data");
f->addArg(type_uint, "connect_flags");
f = mod->addFunc(type_GtkWidget, "gtk_window_new",
(void *)gtk_window_new
);
f->addArg(type_int, "val");
f = mod->addFunc(type_void, "gtk_box_pack_start",
(void *)gtk_box_pack_start
);
f->addArg(type_GtkWidget, "box");
f->addArg(type_GtkWidget, "child");
f->addArg(type_bool, "expand");
f->addArg(type_bool, "fill");
f->addArg(type_uint, "padding");
f = mod->addFunc(type_GtkWidget, "gtk_button_new_with_label",
(void *)gtk_button_new_with_label
);
f->addArg(type_byteptr, "label");
f = mod->addFunc(type_void, "gtk_container_add",
(void *)gtk_container_add
);
f->addArg(type_GtkWidget, "container");
f->addArg(type_GtkWidget, "widget");
f = mod->addFunc(type_void, "gtk_editable_select_region",
(void *)gtk_editable_select_region
);
f->addArg(type_GtkWidget, "entry");
f->addArg(type_int, "start");
f->addArg(type_int, "end");
f = mod->addFunc(type_void, "gtk_editable_set_editable",
(void *)gtk_editable_set_editable
);
f->addArg(type_GtkWidget, "entry");
f->addArg(type_bool, "editable");
f = mod->addFunc(type_byteptr, "gtk_entry_get_text",
(void *)gtk_entry_get_text
);
f->addArg(type_GtkWidget, "entry");
f = mod->addFunc(type_GtkWidget, "gtk_entry_new",
(void *)gtk_entry_new
);
f = mod->addFunc(type_void, "gtk_entry_set_text",
(void *)gtk_entry_set_text
);
f->addArg(type_GtkWidget, "entry");
f->addArg(type_byteptr, "text");
f = mod->addFunc(type_void, "gtk_entry_set_visibility",
(void *)gtk_entry_set_visibility
);
f->addArg(type_GtkWidget, "entry");
f->addArg(type_bool, "visible");
f = mod->addFunc(type_GtkWidget, "gtk_hbox_new",
(void *)gtk_hbox_new
);
f->addArg(type_bool, "homogenous");
f->addArg(type_uint, "spacing");
f = mod->addFunc(type_GtkWidget, "gtk_label_new",
(void *)gtk_label_new
);
f->addArg(type_byteptr, "text");
f = mod->addFunc(type_GtkObject, "gtk_tooltips_new",
(void *)gtk_tooltips_new
);
f = mod->addFunc(type_void, "gtk_tooltips_set_tip",
(void *)gtk_tooltips_set_tip
);
f->addArg(type_GtkObject, "tooltips");
f->addArg(type_GtkWidget, "widget");
f->addArg(type_byteptr, "tip_text");
f->addArg(type_byteptr, "tip_private");
f = mod->addFunc(type_GtkWidget, "gtk_vbox_new",
(void *)gtk_vbox_new
);
f->addArg(type_bool, "homogenous");
f->addArg(type_uint, "spacing");
f = mod->addFunc(type_GtkObject, "GtkObject_cast",
(void *)GtkObject_cast
);
f->addArg(type_GtkWidget, "widget");
}
| C++ |
#include <pcre.h>
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/Func.h"
extern "C"
void crack_ext__pcre_rinit() {
return;
}
extern "C"
void crack_ext__pcre_cinit(crack::ext::Module *mod) {
crack::ext::Func *f;
crack::ext::Type *type_Class = mod->getClassType();
crack::ext::Type *type_void = mod->getVoidType();
crack::ext::Type *type_voidptr = mod->getVoidptrType();
crack::ext::Type *type_bool = mod->getBoolType();
crack::ext::Type *type_byteptr = mod->getByteptrType();
crack::ext::Type *type_byte = mod->getByteType();
crack::ext::Type *type_int16 = mod->getInt16Type();
crack::ext::Type *type_int32 = mod->getInt32Type();
crack::ext::Type *type_int64 = mod->getInt64Type();
crack::ext::Type *type_uint16 = mod->getUint16Type();
crack::ext::Type *type_uint32 = mod->getUint32Type();
crack::ext::Type *type_uint64 = mod->getUint64Type();
crack::ext::Type *type_int = mod->getIntType();
crack::ext::Type *type_uint = mod->getUintType();
crack::ext::Type *type_intz = mod->getIntzType();
crack::ext::Type *type_uintz = mod->getUintzType();
crack::ext::Type *type_float32 = mod->getFloat32Type();
crack::ext::Type *type_float64 = mod->getFloat64Type();
crack::ext::Type *type_float = mod->getFloatType();
crack::ext::Type *type_PCRE = mod->addType("PCRE", sizeof(int));
type_PCRE->finish();
crack::ext::Type *array = mod->getType("array");
crack::ext::Type *array_pint_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_int;
array_pint_q = array->getSpecialization(params);
}
crack::ext::Type *array_pbyteptr_q;
{
std::vector<crack::ext::Type *> params(1);
params[0] = type_byteptr;
array_pbyteptr_q = array->getSpecialization(params);
}
f = mod->addFunc(type_PCRE, "pcre_compile2",
(void *)pcre_compile2
);
f->addArg(type_byteptr, "pattern");
f->addArg(type_int, "options");
f->addArg(array_pint_q, "errorCode");
f->addArg(array_pbyteptr_q, "errorText");
f->addArg(array_pint_q, "errorOffset");
f->addArg(type_byteptr, "tablePtr");
f = mod->addFunc(type_int, "pcre_exec",
(void *)pcre_exec
);
f->addArg(type_PCRE, "pcre");
f->addArg(type_voidptr, "extra");
f->addArg(type_byteptr, "subject");
f->addArg(type_uint, "subjectSize");
f->addArg(type_int, "startOffset");
f->addArg(type_int, "options");
f->addArg(array_pint_q, "outputVec");
f->addArg(type_uint, "outputVecSize");
f = mod->addFunc(type_void, "pcre_fullinfo",
(void *)pcre_fullinfo
);
f->addArg(type_PCRE, "pcre");
f->addArg(type_voidptr, "extra");
f->addArg(type_int, "param");
f->addArg(array_pint_q, "result");
f = mod->addFunc(type_int, "pcre_get_stringnumber",
(void *)pcre_get_stringnumber
);
f->addArg(type_PCRE, "pcre");
f->addArg(type_byteptr, "name");
mod->addConstant(type_int, "PCRE_ANCHORED",
static_cast<int>(PCRE_ANCHORED)
);
mod->addConstant(type_int, "PCRE_DOTALL",
static_cast<int>(PCRE_DOTALL)
);
mod->addConstant(type_int, "PCRE_AUTO_CALLOUT",
static_cast<int>(PCRE_AUTO_CALLOUT)
);
mod->addConstant(type_int, "PCRE_CASELESS",
static_cast<int>(PCRE_CASELESS)
);
mod->addConstant(type_int, "PCRE_DOLLAR_ENDONLY",
static_cast<int>(PCRE_DOLLAR_ENDONLY)
);
mod->addConstant(type_int, "PCRE_DOTALL",
static_cast<int>(PCRE_DOTALL)
);
mod->addConstant(type_int, "PCRE_EXTENDED",
static_cast<int>(PCRE_EXTENDED)
);
mod->addConstant(type_int, "PCRE_EXTRA",
static_cast<int>(PCRE_EXTRA)
);
mod->addConstant(type_int, "PCRE_FIRSTLINE",
static_cast<int>(PCRE_FIRSTLINE)
);
mod->addConstant(type_int, "PCRE_MULTILINE",
static_cast<int>(PCRE_MULTILINE)
);
mod->addConstant(type_int, "PCRE_NO_AUTO_CAPTURE",
static_cast<int>(PCRE_NO_AUTO_CAPTURE)
);
mod->addConstant(type_int, "PCRE_UNGREEDY",
static_cast<int>(PCRE_UNGREEDY)
);
mod->addConstant(type_int, "PCRE_UTF8",
static_cast<int>(PCRE_UTF8)
);
mod->addConstant(type_int, "PCRE_NO_UTF8_CHECK",
static_cast<int>(PCRE_NO_UTF8_CHECK)
);
}
| C++ |
// copyright 2011 Google Inc.
#ifndef _model_Generic_h_
#define _model_Generic_h_
#include "parser/Token.h"
#include "GenericParm.h"
#include "Namespace.h"
#include "VarDef.h"
namespace parser {
class Toker;
}
namespace model {
class Deserializer;
class Serializer;
SPUG_RCPTR(Namespace);
/** Stores information used to replay a generic. */
class Generic {
private:
static void serializeToken(Serializer &out, const parser::Token &tok);
static parser::Token deserializeToken(Deserializer &src);
public:
// the generic parameters
GenericParmVec parms;
// the body of the generic, stored in reverse order.
typedef std::vector<parser::Token> TokenVec;
TokenVec body;
// the original context Namespace and compile namespace
NamespacePtr ns, compileNS;
/** Add the token to the body. */
void addToken(const parser::Token &tok) {
body.push_back(tok);
}
/** Get the named parameter. Returns null if it is not defined. */
GenericParm *getParm(const std::string &name);
/** Replay the body into the tokenizer. */
void replay(parser::Toker &toker);
/** Serialization API. */
/** @{ */
void serialize(Serializer &out) const;
static Generic *deserialize(Deserializer &src);
/** @} */
};
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#ifndef _model_SetRegisterExpr_h_
#define _model_SetRegisterExpr_h_
#include "Expr.h"
namespace model {
/**
* Expression that obtains the value of the register in the current context.
*/
class SetRegisterExpr : public Expr {
public:
ExprPtr expr;
SetRegisterExpr(Expr *expr) : Expr(expr->type.get()), expr(expr) {}
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
virtual bool isProductive() const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_BuilderContextData_h_
#define _model_BuilderContextData_h_
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
SPUG_RCPTR(BuilderContextData);
/**
* Base class for Builder-specific information to be stored in a Context
* object.
*/
class BuilderContextData : public spug::RCBase {
public:
BuilderContextData() {}
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_TernaryExpr_h_
#define _model_TernaryExpr_h_
#include "Expr.h"
namespace model {
/**
* A ternary expression.
* As a special case to accomodate void-typed interpolated strings, the
* "false" expression pointer may be null.
*/
class TernaryExpr : public Expr {
public:
ExprPtr cond, trueVal, falseVal;
TernaryExpr(Expr *cond, Expr *trueVal, Expr *falseVal,
TypeDef *type
) :
Expr(type),
cond(cond),
trueVal(trueVal),
falseVal(falseVal) {
}
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
virtual bool isProductive() const;
};
} // namespace model
#endif
| C++ |
#include "Initializers.h"
#include "Context.h"
#include "Expr.h"
#include "FuncCall.h"
#include "TypeDef.h"
#include "VarDef.h"
using namespace model;
bool Initializers::addBaseInitializer(TypeDef *base, FuncCall *init) {
if (baseMap.find(base) != baseMap.end())
return false;
baseMap[base] = init;
return true;
}
FuncCall *Initializers::getBaseInitializer(TypeDef *base) {
BaseInitMap::iterator iter = baseMap.find(base);
if (iter == baseMap.end())
return 0;
else
return iter->second.get();
}
bool Initializers::addFieldInitializer(VarDef *var, Expr *init) {
if (fieldMap.find(var) != fieldMap.end())
return false;
fieldMap[var] = init;
return true;
}
Expr *Initializers::getFieldInitializer(VarDef *field) {
FieldInitMap::iterator iter = fieldMap.find(field);
if (iter == fieldMap.end())
return 0;
else
return iter->second.get();
}
| C++ |
// Copyright 2009 Google Inc.
#include "LocalNamespace.h"
#include "ModuleDef.h"
#include "VarDef.h"
using namespace model;
ModuleDefPtr LocalNamespace::getModule() {
return parent ? parent->getModule() : ModuleDefPtr(0);
}
NamespacePtr LocalNamespace::getParent(unsigned index) {
return index ? NamespacePtr(0) : parent;
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_NullConst_h_
#define _model_NullConst_h_
#include "Context.h"
#include "Expr.h"
namespace model {
SPUG_RCPTR(NullConst);
// A null constant. Like IntConst, this will morph to adapt to the
// corresponding type/width etc.
class NullConst : public Expr {
public:
NullConst(TypeDef *type) : Expr(type) {}
virtual ResultExprPtr emit(Context &context);
virtual ExprPtr convert(Context &context, TypeDef *newType);
virtual void writeTo(std::ostream &out) const;
virtual bool isProductive() const;
};
} // namespace parser
#endif
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_GlobalNamespace_h_
#define _model_GlobalNamespace_h_
#include "LocalNamespace.h"
namespace model {
SPUG_RCPTR(GlobalNamespace);
class GlobalNamespace : public LocalNamespace {
public:
GlobalNamespace(Namespace *parent, const std::string &cName) :
LocalNamespace(parent, cName) {}
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_ArgDef_h_
#define _model_ArgDef_h_
#include <vector>
#include "VarDef.h"
namespace model {
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(ArgDef);
class ArgDef : public VarDef {
public:
ArgDef(TypeDef *type, const std::string &name) :
VarDef(type, name) {
}
};
typedef std::vector<ArgDefPtr> ArgVec;
} // namespace model
#endif
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_StubDef_h
#define _model_StubDef_h
#include <spug/RCPtr.h>
#include "VarDef.h"
namespace model {
SPUG_RCPTR(StubDef);
/**
* When we import from a shared library, we end up with an address but no
* definition. A StubDef stores the address and reserves the name in the
* namespace until a definition arrives.
*/
class StubDef : public VarDef {
public:
void *address;
/**
* @param type should be the "void" type.
*/
StubDef(TypeDef *type, const std::string &name, void *address) :
VarDef(type, name),
address(address) {
}
virtual bool hasInstSlot() { return false; }
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "AssignExpr.h"
#include <spug/StringFmt.h>
#include "builder/Builder.h"
#include "parser/Parser.h"
#include "Context.h"
#include "ResultExpr.h"
#include "TypeDef.h"
#include "VarDef.h"
#include "VarDefImpl.h"
#include "VarRef.h"
using namespace model;
using namespace parser;
using namespace std;
AssignExpr::AssignExpr(Expr *aggregate, VarDef *var, Expr *value) :
Expr(value->type.get()),
aggregate(aggregate),
var(var),
value(value) {
}
AssignExprPtr AssignExpr::create(Context &context,
Expr *aggregate,
VarDef *var,
Expr *value
) {
// check the types
ExprPtr converted = value->convert(context, var->type.get());
if (!converted)
context.error(SPUG_FSTR("Assigning variable " << var->name <<
" of type " << var->type->name <<
" from value of type " <<
value->type->name
)
);
// XXX should let the builder do this
return new AssignExpr(aggregate, var, converted.get());
}
ResultExprPtr AssignExpr::emit(Context &context) {
// see if the variable has a release function
bool gotReleaseFunc = context.lookUpNoArgs("oper release", false,
var->type.get()
);
ResultExprPtr assnResult, oldVal;
if (aggregate) {
ExprPtr agg = aggregate;
if (gotReleaseFunc) {
// emit the aggregate, store the ResultExpr for use when we emit
// the field assignment.
ResultExprPtr aggResult;
agg = aggResult = aggregate->emit(context);
aggResult->handleTransient(context);
// emit the release call on the result
VarRefPtr varRef =
context.builder.createFieldRef(aggregate.get(), var.get());
oldVal = varRef->emit(context);
}
assnResult = context.builder.emitFieldAssign(context, agg.get(), this);
} else {
if (gotReleaseFunc) {
// emit a release call on the existing value.
VarRefPtr varRef = context.builder.createVarRef(var.get());
oldVal = varRef->emit(context);
}
assnResult = var->emitAssignment(context, value.get());
}
// cleanup the old value after assignment (we can't do it before because
// the value expression might have thrown an exception)
if (gotReleaseFunc)
oldVal->forceCleanup(context);
return assnResult;
}
bool AssignExpr::isProductive() const {
return false;
}
void AssignExpr::writeTo(std::ostream &out) const {
out << var->name << " = ";
value->writeTo(out);
}
| C++ |
// copyright 2012 Google Inc.
#include "Serializer.h"
#include <stdint.h>
#include <ostream>
using namespace std;
using namespace model;
void Serializer::write(unsigned int val) {
// special case 0
if (!val) {
dst << static_cast<char>(val);
return;
}
while (val) {
uint8_t b = val & 0x7f;
val >>= 7;
if (val)
b |= 0x80;
dst << b;
}
}
void Serializer::write(size_t length, const void *data) {
write(length);
dst.write(reinterpret_cast<const char *>(data), length);
}
bool Serializer::writeObject(void *object) {
ObjMap::iterator iter = objMap.find(object);
if (iter == objMap.end()) {
// new object
int id = lastId++;
objMap[object] = id;
write(id << 1 | 1);
return true;
} else {
write(iter->second << 1);
return false;
}
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_CleanupFrame_h_
#define _model_CleanupFrame_h_
#include <spug/RCPtr.h>
#include <spug/RCBase.h>
namespace model {
SPUG_RCPTR(CleanupFrame);
class Context;
class Expr;
class FuncCall;
class VarDef;
/**
* CleanupFrame is a collection of cleanup activities to perform at the end of
* a context - examples include the cleanup of variables at the end of a block
* or the cleanup of temporaries after evalutation of a statement.
*
* Cleanups are to be executed in the reverse order that they are added.
*/
class CleanupFrame : public spug::RCBase {
public:
CleanupFramePtr parent;
Context *context;
CleanupFrame(Context *context) : context(context) {}
/**
* Add a cleanup operation to the frame.
*/
virtual void addCleanup(Expr *cleanupFuncCall) = 0;
/**
* Adds a cleanup for the given variable definition if one is needed.
* @param aggregate if defined, this is the aggregate that varDef is a
* member of.
*/
void addCleanup(VarDef *varDef, Expr *aggregate = 0);
/**
* Close the cleanup frame. If the code is not terminal at this
* point, the cleanups will be emitted and executed.
*/
virtual void close() = 0;
};
} // namespace model
#endif
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_PrimFuncAnnotation_h_
#define _model_PrimFuncAnnotation_h_
#include "Annotation.h"
namespace parser {
class Parser;
class Toker;
}
namespace compiler {
class CrackContext;
}
namespace model {
SPUG_RCPTR(PrimFuncAnnotation);
SPUG_RCPTR(PrimFuncDef);
/**
* An annotation that wraps a primitive function pointer. These are also used
* for storing constructed annotations implemented in crack.
*/
class PrimFuncAnnotation : public Annotation {
typedef void (*AnnotationFunc)(compiler::CrackContext *);
private:
AnnotationFunc func;
void *userData;
public:
PrimFuncAnnotation(const std::string &name, AnnotationFunc func,
void *userData = 0
);
virtual void invoke(parser::Parser *parser, parser::Toker *toker,
Context *context
);
void *getUserData() { return userData; }
AnnotationFunc getFunc() { return func; }
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "VarRef.h"
#include "builder/Builder.h"
#include "VarDefImpl.h"
#include "Context.h"
#include "ResultExpr.h"
#include "TypeDef.h"
#include "VarDef.h"
using namespace model;
using namespace std;
VarRef::VarRef(VarDef *def) :
Expr(def->type.get()),
def(def) {
}
ResultExprPtr VarRef::emit(Context &context) {
assert(def->impl);
return def->impl->emitRef(context, this);
}
bool VarRef::isProductive() const {
return false;
}
void VarRef::writeTo(ostream &out) const {
out << "ref(" << def->name << ')';
}
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_Construct_h_
#define _model_Construct_h_
#include "ModuleDef.h"
#include <list>
#include <stack>
#include <sys/time.h>
namespace builder {
SPUG_RCPTR(Builder);
}
namespace crack { namespace ext {
class Module;
}}
namespace model {
SPUG_RCPTR(ModuleDef);
SPUG_RCPTR(Construct);
SPUG_RCPTR(StrConst);
SPUG_RCPTR(ConstructStats);
struct ConstructStats: public spug::RCBase {
enum CompileState { start=0, builtin, build, run, end };
typedef std::map<std::string, double> ModuleTiming;
unsigned int parsedCount;
unsigned int cachedCount;
CompileState state;
double timing[5];
ModuleTiming moduleTimes;
struct timeval lastTime;
std::string currentModule;
ConstructStats(void): parsedCount(0),
cachedCount(0),
state(start),
timing(),
moduleTimes(),
lastTime(),
currentModule("NONE") {
gettimeofday(&lastTime, NULL);
for (int i=0; i<5; i++)
timing[i] = 0.0;
}
void switchState(CompileState newState);
void write(std::ostream &out) const;
};
/**
* Construct is a bundle containing the builder and all of the modules created
* using the builder. It serves as a module cache and a way of associated the
* cache with a Builder that can create new modules.
*
* A crack executor will contain either one or two Constructs - there is one
* for the program being executed and there may be different one.
*/
class Construct : public spug::RCBase {
public:
typedef std::vector<std::string> StringVec;
typedef StringVec::const_iterator StringVecIter;
struct ModulePath {
std::string base, relPath, path;
bool found, isDir;
ModulePath(const std::string &base, const std::string &relPath,
const std::string &path,
bool found,
bool isDir
) :
base(base),
relPath(relPath),
path(path),
found(found),
isDir(isDir) {
}
};
typedef void (*CompileFunc)(crack::ext::Module *mod);
typedef void (*InitFunc)();
private:
std::stack<builder::BuilderPtr> builderStack;
// hook into the runtime module's uncaught exception function.
bool (*uncaughtExceptionFunc)();
// TODO: refactor this out of Namespace
typedef std::map<std::string, VarDefPtr> VarDefMap;
// A global mapping of definitions stored by their canonical names.
// Use of the registry is optional. It currently facilitates caching.
VarDefMap registry;
public: // XXX should be private
// if non-null, this is the alternate construct used for annotations.
// If it is null, either this _is_ the annotation construct or both
// the main program and its annotations use the same construct.
ConstructPtr compileTimeConstruct;
// the toplevel builder
builder::BuilderPtr rootBuilder;
// the toplevel context
ContextPtr rootContext;
// .builtin module, containing primitive types and functions
ModuleDefPtr builtinMod;
// mapping from the canonical name of the module to the module
// definition.
typedef std::map<std::string, ModuleDefPtr> ModuleMap;
ModuleMap moduleCache;
// list of all modules in the order that they were loaded.
std::vector<ModuleDefPtr> loadedModules;
// the library path for source files.
std::vector<std::string> sourceLibPath;
// if we keep statistics, they reside here
ConstructStatsPtr stats;
/**
* Search the specified path for a file with the name
* "moduleName.extension", if this does not exist, may also return the
* path for a directory named "moduleName."
*
* @param path the list of root directories to search through.
* @param moduleNameBegin the beginning of a vector of name
* components to search for. Name components are joined together to
* form a path, so for example the vector ["foo", "bar", "baz"] would
* match files and directories with the path "foo/bar/baz" relative
* to the root directory.
* @paramModuleNameEnd the end of the name component vector.
* @param extension The file extension to search for. This is not
* applied when matching a directory.
*/
static ModulePath searchPath(const StringVec &path,
StringVecIter moduleNameBegin,
StringVecIter modulePathEnd,
const std::string &extension,
int verbosity=0
);
/**
* Search the specified path for the 'relPath'.
*/
static ModulePath searchPath(const Construct::StringVec &path,
const std::string &relPath,
int verbosity = 0
);
/**
* Returns true if 'name' is a valid file.
*/
static bool isFile(const std::string &name);
/**
* Returns true if 'name' is a valid directory.
*/
static bool isDir(const std::string &name);
/**
* Join a file name from a base directory and a relative path.
*/
static std::string joinName(const std::string &base,
const std::string &rel
);
/**
* Join a file name from a pair of iterators and an extension.
*/
static std::string joinName(StringVecIter pathBegin,
StringVecIter pathEnd,
const std::string &ext
);
/**
* Creates a root context for the construct.
*/
ContextPtr createRootContext();
public:
// if true, emit warnings about things that have changed since the
// last version of the language.
bool migrationWarnings;
// the error context stack. This needs to be global because it is
// managed by annotations and transcends local contexts.
std::list<std::string> errorContexts;
// global string constants
typedef std::map<std::string, StrConstPtr> StrConstTable;
StrConstTable strConstTable;
// built-in types.
TypeDefPtr classType,
voidType,
voidptrType,
boolType,
byteptrType,
byteType,
int16Type,
int32Type,
int64Type,
uint16Type,
uint32Type,
uint64Type,
intType,
uintType,
intzType,
uintzType,
float32Type,
float64Type,
floatType,
vtableBaseType,
objectType,
stringType,
staticStringType,
overloadType,
crackContext,
functionType;
// Size of these PDNTs in bits.
int intSize, intzSize;
Construct(builder::Builder *rootBuilder, Construct *primary = 0);
/**
* Adds the given path to the source library path - 'path' is a
* colon separated list of directories.
*/
void addToSourceLibPath(const std::string &path);
/**
* Loads the built-in modules (should be called prior to attempting to
* load or run anything else).
*/
void loadBuiltinModules();
/**
* Parse the specified module out of the input stream. Raises all
* ParseError's that occur.
*/
void parseModule(Context &moduleContext,
ModuleDef *module,
const std::string &path,
std::istream &src
);
/**
* Initialize an extension module. This only needs to be called for
* the internal extension modules - ones that are bundled with the
* crack compiler shared library.
*/
ModuleDefPtr initExtensionModule(const std::string &canonicalName,
CompileFunc compileFunc,
InitFunc initFunc
);
/**
* Load a shared library. Should conform to the crack extension
* protocol and implement a module init method.
*/
ModuleDefPtr loadSharedLib(const std::string &path,
StringVecIter moduleNameBegin,
StringVecIter moduleNameEnd,
std::string &canonicalName
);
/**
* Try to load the module from the cache (if caching is enabled and
* the module is cached). Returns the module if it was loaded, null
* if not.
*/
ModuleDefPtr loadFromCache(const std::string &canonicalName);
/**
* Load the named module and returns it. Returns null if the module
* could not be found, raises an exception if there were errors
* parsing the module.
*/
ModuleDefPtr loadModule(StringVecIter moduleNameBegin,
StringVecIter moduleNameEnd,
std::string &canonicalName
);
/**
* a version of loadModule which accept a string canonicalName
*/
ModuleDefPtr loadModule(const std::string &canonicalName);
/**
* Load the executor's bootstrapping modules (crack.lang).
*/
bool loadBootstrapModules();
/**
* Register a module with the module cache and the loaded module list.
* This is intended to accomodate ephemeral modules
*/
void registerModule(ModuleDef *module);
/**
* Run the specified script. Catches all parse exceptions, returns
* an exit code, which will be non-zero if a parse error occurred and
* should eventually be settable by the application.
*
* @param src the script's source stream.
* @param name the script's name (for use in error reporting and
* script module creation).
*/
int runScript(std::istream &src, const std::string &name);
/**
* Returns the current builder.
*/
builder::Builder &getCurBuilder();
/**
* Register the definition in the global registry, storing it by its
* canonical name. You must be able to call getFullName() on def to
* retrieve the canonical name, which generally means that the
* definition must have an owner.
*/
void registerDef(VarDef *def);
/**
* Returns the definition registered with registerDef(), or null if
* no definition with the name was ever registered.
*/
VarDefPtr getRegisteredDef(const std::string &canonicalName);
};
} // namespace model
#endif
| C++ |
// Copyright 2010 Google Inc.
#include "PrimFuncAnnotation.h"
#include "compiler/CrackContext.h"
using namespace model;
PrimFuncAnnotation::PrimFuncAnnotation(const std::string &name,
AnnotationFunc func,
void *userData
) :
Annotation(0, name),
func(func),
userData(userData) {
}
void PrimFuncAnnotation::invoke(parser::Parser *parser, parser::Toker *toker,
Context *context
) {
compiler::CrackContext crackCtx(parser, toker, context, userData);
func(&crackCtx);
}
| C++ |
// Copyright 2011 Google Inc.
#include "MultiExpr.h"
#include "Branchpoint.h"
#include "CleanupFrame.h"
#include "Context.h"
#include "FuncCall.h"
#include "ResultExpr.h"
#include "builder/Builder.h"
using namespace model;
ResultExprPtr MultiExpr::emit(Context &context) {
// must be at least one element
assert(elems.size());
// emit all but the last of formatter functions
int i;
for (i = 0; i < elems.size() - 1; ++i)
elems[i]->emit(context)->handleTransient(context);
return elems[i]->emit(context);
}
void MultiExpr::writeTo(std::ostream &out) const {
out << "(";
for (int i = 0; i < elems.size(); ++i) {
elems[i]->writeTo(out);
out << ", ";
}
out << ")";
}
bool MultiExpr::isProductive() const {
return elems.back()->isProductive();
}
| C++ |
// Copyright 2009 Google Inc.
#include "Context.h"
#include <stdlib.h>
#include <spug/StringFmt.h>
#include "builder/Builder.h"
#include "parser/Token.h"
#include "parser/Location.h"
#include "parser/ParseError.h"
#include "Annotation.h"
#include "AssignExpr.h"
#include "BuilderContextData.h"
#include "CleanupFrame.h"
#include "ConstVarDef.h"
#include "ConstSequenceExpr.h"
#include "FuncAnnotation.h"
#include "ArgDef.h"
#include "Branchpoint.h"
#include "GlobalNamespace.h"
#include "IntConst.h"
#include "FloatConst.h"
#include "LocalNamespace.h"
#include "ModuleDef.h"
#include "NullConst.h"
#include "OverloadDef.h"
#include "ResultExpr.h"
#include "StrConst.h"
#include "TernaryExpr.h"
#include "TypeDef.h"
#include "VarDef.h"
#include "VarDefImpl.h"
#include "VarRef.h"
using namespace model;
using namespace std;
parser::Location Context::emptyLoc;
void Context::warnOnHide(const string &name) {
if (ns->lookUp(name))
cerr << loc.getName() << ":" << loc.getLineNumber() << ": " <<
"Symbol " << name <<
" hides another definition in an enclosing context." << endl;
}
namespace {
void collectAncestorOverloads(OverloadDef *overload,
Namespace *srcNs
) {
NamespacePtr parent;
for (unsigned i = 0; parent = srcNs->getParent(i++);) {
VarDefPtr var = parent->lookUp(overload->name, false);
OverloadDefPtr parentOvld;
if (!var) {
// the parent does not have this overload. Check the next level.
collectAncestorOverloads(overload, parent.get());
} else {
parentOvld = OverloadDefPtr::rcast(var);
// if there is a variable of this name but it is not an overload,
// we have a situation where there is a non-overload definition in
// an ancestor namespace that will block resolution of the
// overloads in all derived namespaces. This is a bad thing,
// but not something we want to deal with here.
if (parentOvld)
overload->addParent(parentOvld.get());
}
}
}
}
OverloadDefPtr Context::replicateOverload(const std::string &varName,
Namespace *srcNs
) {
OverloadDefPtr overload = new OverloadDef(varName);
overload->type = construct->overloadType;
// merge in the overloads from the parents
collectAncestorOverloads(overload.get(), srcNs);
srcNs->addDef(overload.get());
return overload;
}
Context::Context(builder::Builder &builder, Context::Scope scope,
Context *parentContext,
Namespace *ns,
Namespace *compileNS
) :
loc(parentContext ? parentContext->loc : emptyLoc),
parent(parentContext),
ns(ns),
compileNS(compileNS ? compileNS :
(parentContext ?
new LocalNamespace(parentContext->compileNS.get(),
ns ? ns->getNamespaceName() : ""
) :
NamespacePtr(0))
),
builder(builder),
scope(scope),
toplevel(false),
emittingCleanups(false),
terminal(false),
returnType(parentContext ? parentContext->returnType : TypeDefPtr(0)),
nextFuncFlags(FuncDef::noFlags),
nextClassFlags(TypeDef::noFlags),
construct(parentContext->construct),
cleanupFrame(builder.createCleanupFrame(*this)) {
assert(construct && "parent context must have a construct");
}
Context::Context(builder::Builder &builder, Context::Scope scope,
Construct *construct,
Namespace *ns,
Namespace *compileNS
) :
ns(ns),
compileNS(compileNS),
builder(builder),
scope(scope),
toplevel(false),
emittingCleanups(false),
terminal(false),
returnType(TypeDefPtr(0)),
nextFuncFlags(FuncDef::noFlags),
construct(construct),
cleanupFrame(builder.createCleanupFrame(*this)) {
assert(compileNS);
}
Context::~Context() {}
ContextPtr Context::createSubContext(Scope newScope, Namespace *ns,
const string *name,
Namespace *cns
) {
if (!ns) {
switch (newScope) {
case local:
ns = new LocalNamespace(this->ns.get(), name ? *name : "");
break;
case module:
ns = new GlobalNamespace(this->ns.get(), name ? *name : "");
break;
case composite:
case instance:
assert(false &&
"missing namespace when creating composite or instance "
"context"
);
}
}
return new Context(builder, newScope, this, ns, cns);
}
ContextPtr Context::getClassContext() {
if (scope == instance)
return this;
else if (parent)
return parent->getClassContext();
else
return 0;
}
ContextPtr Context::getDefContext() {
if (scope != composite)
return this;
else if (parent)
return parent->getDefContext();
else
return 0;
}
ContextPtr Context::getToplevel() {
if (toplevel)
return this;
else if (parent)
return parent->getToplevel();
else
return 0;
}
ContextPtr Context::getModuleContext() {
if (scope == module) {
return this;
} else {
assert(parent);
return parent->getModuleContext();
}
}
bool Context::encloses(const Context &other) const {
if (this == &other)
return true;
else if (other.parent)
return encloses(*other.parent);
else
return false;
}
ModuleDefPtr Context::createModule(const string &name,
const string &path,
ModuleDef *owner) {
ModuleDefPtr result = builder.createModule(*this, name, path, owner);
ns = result;
return result;
}
ModuleDefPtr Context::materializeModule(const string &canonicalName,
ModuleDef *owner) {
ModuleDefPtr result =
builder.materializeModule(*this, canonicalName, owner);
if (result)
ns = result;
return result;
}
ExprPtr Context::getStrConst(const std::string &value, bool raw) {
// look up the raw string constant
StrConstPtr strConst;
Construct::StrConstTable::iterator iter =
construct->strConstTable.find(value);
if (iter != construct->strConstTable.end()) {
strConst = iter->second;
} else {
// create a new one
strConst = builder.createStrConst(*this, value);
construct->strConstTable[value] = strConst;
}
// if we don't have a StaticString type yet (or the caller wants a raw
// bytestr), we're done.
if (raw || !construct->staticStringType)
return strConst;
// create the "new" expression for the string.
vector<ExprPtr> args;
args.push_back(strConst);
args.push_back(builder.createIntConst(*this, value.size(),
construct->uintType.get()
)
);
FuncDefPtr newFunc =
lookUp("oper new", args, construct->staticStringType.get());
FuncCallPtr funcCall = builder.createFuncCall(newFunc.get());
funcCall->args = args;
return funcCall;
}
CleanupFramePtr Context::createCleanupFrame() {
CleanupFramePtr frame = builder.createCleanupFrame(*this);
frame->parent = cleanupFrame;
cleanupFrame = frame;
return frame;
}
void Context::closeCleanupFrame() {
CleanupFramePtr frame = cleanupFrame;
cleanupFrame = frame->parent;
frame->close();
}
TypeDefPtr Context::createForwardClass(const string &name) {
TypeDefPtr type = builder.createClassForward(*this, name);
ns->addDef(type.get());
return type;
}
void Context::checkForUnresolvedForwards() {
for (Namespace::VarDefMap::iterator iter = ns->beginDefs();
iter != ns->endDefs();
++iter
) {
// check for an overload
OverloadDef *overload;
if (overload = OverloadDefPtr::rcast(iter->second)) {
for (OverloadDef::FuncList::iterator fi =
overload->beginTopFuncs();
fi != overload->endTopFuncs();
++fi
)
if ((*fi)->flags & FuncDef::forward)
error(SPUG_FSTR("Forward declared function not defined at "
"the end of the block: " <<
(*fi)->getDisplayName()
)
);
}
}
}
VarDefPtr Context::emitVarDef(Context *defCtx, TypeDef *type,
const std::string &name,
Expr *initializer,
bool constant
) {
// make sure the type isn't void
if (construct->voidType->matches(*type))
error("Can not create a variable of type 'void'");
VarDefPtr varDef;
// if this is a constant, and the expression is a constant integer or
// float, create a ConstVarDef.
if (constant && (IntConstPtr::cast(initializer) ||
FloatConstPtr::cast(initializer)
)
) {
varDef = new ConstVarDef(type, name, initializer);
} else {
createCleanupFrame();
varDef = type->emitVarDef(*this, name, initializer);
varDef->constant = constant;
closeCleanupFrame();
cleanupFrame->addCleanup(varDef.get());
}
defCtx->ns->addDef(varDef.get());
return varDef;
}
VarDefPtr Context::emitVarDef(TypeDef *type, const parser::Token &tok,
Expr *initializer,
bool constant
) {
if (construct->migrationWarnings) {
if (initializer && NullConstPtr::cast(initializer)) {
cerr << loc.getName() << ":" << loc.getLineNumber() << ": " <<
"unnecessary initialization to null" << endl;
} else if (!initializer && type->pointer) {
cerr << loc.getName() << ":" << loc.getLineNumber() << ": " <<
"default initializer is now null!" << endl;
}
}
// make sure we aren't using a forward declared type (we disallow this
// because we don't know if oper release() is defined for the type)
if (type->forward)
error(SPUG_FSTR("You cannot define a variable of a forward declared "
"type."
)
);
// if the definition context is an instance context, make sure that we
// haven't generated any constructors.
ContextPtr defCtx = getDefContext();
if (defCtx->scope == Context::instance &&
TypeDefPtr::arcast(defCtx->ns)->initializersEmitted) {
parser::Location loc = tok.getLocation();
throw parser::ParseError(SPUG_FSTR(loc.getName() << ':' <<
loc.getLineNumber() <<
": Adding an instance variable "
"after 'oper init' has been "
"defined."
)
);
}
return emitVarDef(defCtx.get(), type, tok.getData(), initializer, constant);
}
ExprPtr Context::createTernary(Expr *cond, Expr *trueVal, Expr *falseVal) {
// make sure the condition can be converted to bool
ExprPtr boolCond = cond->convert(*this, construct->boolType.get());
if (!boolCond)
error("Condition in ternary operator is not boolean.");
ExprPtr converted;
// make sure the types are compatible
TypeDefPtr type;
if (falseVal && trueVal->type != falseVal->type) {
if (trueVal->type->isDerivedFrom(falseVal->type.get())) {
type = falseVal->type;
} else if (falseVal->type->isDerivedFrom(trueVal->type.get())) {
type = trueVal->type;
} else if (converted = falseVal->convert(*this, trueVal->type.get())) {
type = trueVal->type;
falseVal = converted.get();
} else if (converted = trueVal->convert(*this, falseVal->type.get())) {
type = falseVal->type;
trueVal = converted.get();
} else {
error("Value types in ternary operator are not compatible.");
}
} else {
// the types are equal
type = trueVal->type;
}
return builder.createTernary(*this, boolCond.get(), trueVal, falseVal,
type.get()
);
}
ExprPtr Context::emitConstSequence(TypeDef *type,
const std::vector<ExprPtr> &elems
) {
// see if there is a new function for the type that accepts an element
// count.
OverloadDefPtr ovld = lookUp("oper new", type);
if (!ovld)
error(SPUG_FSTR("Cannot construct an instance of type " <<
type->name
)
);
FuncDef *cons;
TypeDef *uintType = construct->uintType.get();
vector<ExprPtr> consArgs(1);
consArgs[0] = builder.createIntConst(*this, elems.size());
cons = ovld->getMatch(*this, consArgs, false);
ConstSequenceExprPtr expr = new ConstSequenceExpr(type);
if (cons) {
expr->container = builder.createFuncCall(cons);
expr->container->args = consArgs;
// no 'oper new(uint)', try to find a default constructor.
} else {
consArgs.clear();
cons = ovld->getMatch(*this, consArgs, false);
if (!cons || cons->getOwner() != type)
error(SPUG_FSTR(type->name << " has neither a constructor "
"accepting a uint nor a default constructor."
)
);
expr->container = builder.createFuncCall(cons);
}
// create append calls for each of the elements
for (int i = 0; i < elems.size(); ++i) {
ExprPtr elem = elems[i];
vector<ExprPtr> args(1);
args[0] = elem;
FuncDefPtr appender = lookUp("append", args, type);
FuncCallPtr appendCall;
if (appender && appender->flags & FuncDef::method) {
appendCall = builder.createFuncCall(appender.get());
appendCall->args = args;
// if there's no appender, try looking up index assignment
} else {
args.insert(args.begin(),
builder.createIntConst(*this, i, uintType)
);
appender = lookUp("oper []=", args, type);
if (!appender || !(appender->flags & FuncDef::method))
error(SPUG_FSTR(type->name <<
" has neither an append() nor an oper []= "
" method accepting " << elem->type->name <<
" for element at index " << i
)
);
appendCall = builder.createFuncCall(appender.get());
appendCall->args = args;
}
// add the append to the sequence expression
expr->elems.push_back(appendCall);
}
return expr;
}
bool Context::inSameFunc(Namespace *varNS) {
if (scope != local)
// this is not a function.
return false;
// see if the namespace is our namespace
if (varNS == ns)
return true;
// if this isn't the toplevel context, check the parent
else if (!toplevel)
return parent->inSameFunc(varNS);
else
return false;
}
ExprPtr Context::createVarRef(VarDef *varDef) {
// is the variable a constant?
ConstVarDefPtr constDef;
if (constDef = ConstVarDefPtr::cast(varDef))
return constDef->expr;
// verify that the variable is reachable
// if the variable is in a module context, it is accessible
if (ModuleDefPtr::cast(varDef->getOwner()) ||
GlobalNamespacePtr::cast(varDef->getOwner())) {
return builder.createVarRef(varDef);
// if it's in an instance context, verify that this is either the composite
// context of the class or a method of the class that contains the variable.
} else if (TypeDefPtr::cast(varDef->getOwner())) {
if (scope == composite && varDef->getOwner() == parent->ns ||
getToplevel()->parent->ns
) {
return builder.createVarRef(varDef);
}
// if it's in a function context, make sure it's this function
} else if (inSameFunc(varDef->getOwner())) {
return builder.createVarRef(varDef);
}
error(SPUG_FSTR("Variable '" << varDef->name <<
"' is not accessible from within this context."
)
);
}
VarRefPtr Context::createFieldRef(Expr *aggregate, VarDef *var) {
TypeDef *aggType = aggregate->type.get();
TypeDef *varNS = TypeDefPtr::cast(var->getOwner());
if (!varNS || !aggType->isDerivedFrom(varNS))
error(SPUG_FSTR("Variable '" << var->name <<
"' is not accessible from within this context."
)
);
return builder.createFieldRef(aggregate, var);
}
void Context::setBreak(Branchpoint *branch) {
breakBranch = branch;
}
void Context::setContinue(Branchpoint *branch) {
continueBranch = branch;
}
void Context::setCatchBranchpoint(Branchpoint *branch) {
catchBranch = branch;
}
Branchpoint *Context::getBreak() {
if (breakBranch)
return breakBranch.get();
// don't attempt to propagate out of an execution scope
if (!toplevel && parent) {
return parent->getBreak();
} else {
return 0;
}
}
Branchpoint *Context::getContinue() {
if (continueBranch)
return continueBranch.get();
// don't attempt to propagate out of an execution scope
if (!toplevel && parent) {
return parent->getContinue();
} else {
return 0;
}
}
ContextPtr Context::getCatch() {
if (catchBranch)
return this;
else if (toplevel)
return this;
else if (parent)
return parent->getCatch();
}
BranchpointPtr Context::getCatchBranchpoint() {
return catchBranch;
}
ExprPtr Context::makeThisRef(const string &memberName) {
VarDefPtr thisVar = ns->lookUp("this");
if (!thisVar)
error(SPUG_FSTR("instance member " << memberName <<
" may not be used in a static context."
)
);
return createVarRef(thisVar.get());
}
void Context::expandIteration(const std::string &name, bool defineVar,
bool isIter,
Expr *seqExpr,
ExprPtr &cond,
ExprPtr &beforeBody,
ExprPtr &afterBody
) {
// verify that the sequence has an "iter" method
FuncDefPtr iterFunc = lookUpNoArgs("iter", true, seqExpr->type.get());
if (!iterFunc)
error(SPUG_FSTR("iteration expression has no 'iter' method "
"(was type " << seqExpr->type->getFullName() << ")")
);
// create an expression from it
FuncCallPtr iterCall = builder.createFuncCall(iterFunc.get());
if (iterFunc->flags & FuncDef::method)
iterCall->receiver = seqExpr;
// if the variable provided is an iterator, just use it and clear the
// "var" argument as an indicator to later code.
VarDefPtr iterVar, var;
FuncDefPtr elemFunc;
if (isIter) {
// this is a "for on" and the variable is an iterator.
if (defineVar) {
assert(scope != composite &&
"iteration expanded in a non-definition context"
);
warnOnHide(name);
iterVar =
emitVarDef(this, iterCall->type.get(), name, iterCall.get());
} else {
iterVar = ns->lookUp(name);
if (iterVar->isConstant())
error("Cannot use a constant as a loop iterator");
if (!iterVar->type->matches(*iterCall->type))
error("Loop iterator variable type does not match the type of "
"the iterator."
);
// emit code to assign the iterator
createCleanupFrame();
ExprPtr iterAssign =
AssignExpr::create(*this, iterVar.get(), iterCall.get());
iterAssign->emit(*this)->handleTransient(*this);
closeCleanupFrame();
}
} else {
// we're passing in "this" and assuming that the current context is a
// definition context.
assert(scope != composite &&
"iteration expanded in a non-definition context"
);
iterVar = emitVarDef(this, iterCall->type.get(), ":iter",
iterCall.get()
);
elemFunc = lookUpNoArgs("elem", true, iterCall->type.get());
if (!elemFunc)
error(SPUG_FSTR("Iterator type " <<
iterCall->type->getDisplayName() <<
" does not have an 'elem()' method."
)
);
if (defineVar) {
warnOnHide(name);
// if the element type doesn't have a default initializer, we need
// to create a null identifier for it so we don't seg-fault.
ExprPtr initializer;
if (!elemFunc->returnType->defaultInitializer)
initializer = new NullConst(elemFunc->returnType.get());
var = emitVarDef(this, elemFunc->returnType.get(), name,
initializer.get()
);
} else {
var = ns->lookUp(name);
if (var->isConstant())
error("Cannot use a constant as a loop variable");
if (!var->type->matches(*elemFunc->returnType))
error("Loop variable type does not match the type of the "
"return value of the iterator's elem() method."
);
}
}
// create a reference expression for the iterator
ExprPtr iterRef = createVarRef(iterVar.get());
if (var) {
// assign the variable before the body
FuncCallPtr elemCall = builder.createFuncCall(elemFunc.get());
if (elemFunc->flags & FuncDef::method)
elemCall->receiver = iterRef;
beforeBody = AssignExpr::create(*this, var.get(), elemCall.get());
}
// convert it to a boolean for the condition
cond = iterRef->convert(*this, construct->boolType.get());
if (!cond)
error("The iterator in a 'for' loop must convert to boolean.");
// create the "iter.next()" expression
FuncDefPtr nextFunc = lookUpNoArgs("next", true, iterRef->type.get());
if (!nextFunc)
error("The iterator in a 'for' loop must provide a 'next()' method");
FuncCallPtr nextCall = builder.createFuncCall(nextFunc.get());
if (nextFunc->flags & FuncDef::method)
nextCall->receiver = iterRef;
afterBody = nextCall;
}
VarDefPtr Context::lookUp(const std::string &varName, Namespace *srcNs) {
if (!srcNs)
srcNs = ns.get();
VarDefPtr def = srcNs->lookUp(varName);
// if we got an overload, we may need to create an overload in this
// context. (we can get away with checking the owner because overloads
// are never aliased)
OverloadDef *overload = OverloadDefPtr::rcast(def);
if (overload && overload->getOwner() != srcNs)
return replicateOverload(varName, srcNs);
else
return def;
}
void Context::maybeExplainOverload(std::ostream &out,
const std::string &varName,
Namespace *srcNs) {
if (!srcNs)
srcNs = ns.get();
// do a lookup, if nothing was found no further action is necessary.
VarDefPtr var = lookUp(varName, srcNs);
if (!var)
return;
// if it's an overload...
OverloadDefPtr overload = OverloadDefPtr::rcast(var);
if (!overload)
return;
// explain the overload
out << "\nPossible overloads for " << varName << ":\n";
overload->display(out);
}
FuncDefPtr Context::lookUp(const std::string &varName,
vector<ExprPtr> &args,
Namespace *srcNs,
bool allowOverrides
) {
if (!srcNs)
srcNs = ns.get();
// do a lookup, if nothing was found no further action is necessary.
VarDefPtr var = lookUp(varName, srcNs);
if (!var)
return 0;
// if "var" is a class definition, convert this to a lookup of the "oper
// new" function on the class.
TypeDef *typeDef = TypeDefPtr::rcast(var);
if (typeDef) {
FuncDefPtr operNew = lookUp("oper new", args, typeDef);
// make sure we got it, and we didn't inherit it
if (!operNew || operNew->getOwner() != typeDef)
return 0;
return operNew;
}
// make sure we got an overload
OverloadDefPtr overload = OverloadDefPtr::rcast(var);
if (!overload)
return 0;
// look up the signature in the overload
return overload->getMatch(*this, args, allowOverrides);
}
FuncDefPtr Context::lookUpNoArgs(const std::string &name, bool acceptAlias,
Namespace *srcNs
) {
OverloadDefPtr overload = OverloadDefPtr::rcast(lookUp(name, srcNs));
if (!overload)
return 0;
// we can just check for a signature match here - cheaper and easier.
ArgVec args;
FuncDefPtr result = overload->getNoArgMatch(acceptAlias);
return result;
}
VarDefPtr Context::addDef(VarDef *varDef, Namespace *srcNs) {
if (!srcNs)
srcNs = ns.get();
FuncDef *funcDef = FuncDefPtr::cast(varDef);
if (funcDef) {
OverloadDefPtr overload =
OverloadDefPtr::rcast(lookUp(varDef->name, srcNs));
if (!overload)
overload = replicateOverload(varDef->name, srcNs);
overload->addFunc(funcDef);
funcDef->setOwner(srcNs);
return overload;
} else {
srcNs->addDef(varDef);
return varDef;
}
}
void Context::insureOverloadPath(Context *ancestor, OverloadDef *overload) {
// see if we define the overload, if not we're done.
OverloadDefPtr localOverload =
OverloadDefPtr::rcast(ns->lookUp(overload->name, false));
if (!localOverload)
return;
// this code assumes that 'ancestor' must always be a direct ancestor of
// our namespace. This isn't strictly essential, but it shouldn't be
// necessary to support the general case. If we change this assumption,
// we'll get an assertion failure to warn us.
// see if the overload is one of our overload's parents, if so we're done.
if (localOverload->hasParent(overload))
return;
// verify that we are directly derived from the namespace.
NamespacePtr parentNs;
for (int i = 0; parentNs = ns->getParent(i++);)
if (parent.get() == ancestor)
break;
assert(parent && "insureOverloadPath(): parent is not a direct parent.");
localOverload->addParent(overload);
}
AnnotationPtr Context::lookUpAnnotation(const std::string &name) {
VarDefPtr result = compileNS->lookUp(name);
if (!result)
return 0;
// if we've already got an annotation, we're done.
AnnotationPtr ann;
if (ann = AnnotationPtr::rcast(result))
return ann;
// create the arg list for the signature of an annotation (we don't need
// the builder to create an ArgDef here because it's just for a signature
// match).
ArgVec args(1);
args[0] = new ArgDef(construct->crackContext.get(), "context");
OverloadDef *ovld = OverloadDefPtr::rcast(result);
if (ovld) {
FuncDefPtr f = ovld->getSigMatch(args);
if (!f)
return 0;
ann = new FuncAnnotation(f.get());
compileNS->addDef(ann.get());
return ann;
}
// XXX can't deal with variables yet
return 0;
}
namespace {
struct ContextStack {
const list<string> &stack;
ContextStack(const list<string> &stack) : stack(stack) {}
};
ostream &operator <<(ostream &out, ContextStack a) {
for (list<string>::const_iterator iter = a.stack.begin();
iter != a.stack.end();
++iter
)
out << "\n " << *iter;
return out;
}
}
void Context::error(const parser::Location &loc, const string &msg,
bool throwException
) {
list<string> &ec = construct->errorContexts;
if (throwException)
throw parser::ParseError(SPUG_FSTR(loc.getName() << ':' <<
loc.getLineNumber() << ": " <<
msg <<
ContextStack(ec) <<
endl
)
);
else {
cerr << "ParseError: " << loc.getName() << ":" <<
loc.getLineNumber() << ": " << msg << ContextStack(ec) << endl;
exit(1);
}
}
void Context::warn(const parser::Location &loc, const string &msg) {
cerr << loc.getName() << ":" << loc.getLineNumber() << ": " << msg << endl;
}
void Context::pushErrorContext(const string &msg) {
construct->errorContexts.push_front(msg);
}
void Context::popErrorContext() {
construct->errorContexts.pop_front();
}
void Context::checkAccessible(VarDef *var) {
size_t nameSize = var->name.size();
if (nameSize && var->name[0] == '_') {
// See if the variable is aliased in the current module. This is
// to accomodate generic arguments, which can alias private types.
if (getModuleContext()->ns->hasAliasFor(var))
return;
if (nameSize > 1 && var->name[1] == '_') {
// private variable: if it is owned by a class, we must be
// in the scope of that class.
TypeDef *varClass = TypeDefPtr::cast(var->getOwner());
if (!varClass)
return;
ContextPtr myClassCtx = getClassContext();
if (!myClassCtx || TypeDefPtr::rcast(myClassCtx->ns) != varClass)
error(SPUG_FSTR(var->name << " is private to class " <<
varClass->name << " and not acessible in this "
"context."
)
);
} else {
// module protected variable: no problem if part of the same
// module (use the owner module if there is one)
ModuleDefPtr varMod = var->getOwner()->getRealModule();
ModuleDefPtr curMod = getModuleContext()->ns->getRealModule();
if (varMod.get() == curMod.get())
return;
// see if this class is derived from the variable's class
ContextPtr myClassCtx = getClassContext();
TypeDef *varClass = TypeDefPtr::cast(var->getOwner());
if (varClass && myClassCtx &&
TypeDefPtr::rcast(myClassCtx->ns)->isDerivedFrom(varClass)
)
return;
// the symbol is from a different module and we are not in a
// derived class.
error(SPUG_FSTR(var->name << " is private to module " <<
varMod->getNamespaceName() <<
" and not accessible in this context."
)
);
}
}
}
void Context::recordDependency(ModuleDef *module) {
// indicate that our module depends on this other one.
ContextPtr modCtx = getModuleContext();
ModuleDefPtr::arcast(modCtx->ns->getModule())->recordDependency(module);
}
void Context::dump(ostream &out, const std::string &prefix) const {
switch (scope) {
case module: out << "module "; break;
case instance: out << "instance "; break;
case local: out << "local "; break;
case composite: out << "composite "; break;
default: out << "UNKNOWN ";
}
ns->dump(out, prefix);
}
void Context::dump() {
dump(cerr, "");
}
| C++ |
// Copyright 2010 Google Inc.
#include "Annotation.h"
#include "Expr.h"
#include "FuncAnnotation.h"
#include "FuncDef.h"
using namespace model;
Annotation::Annotation(model::TypeDef *type, const std::string &name) :
VarDef(type, name) {
}
AnnotationPtr Annotation::create(VarDef *def) {
FuncDef *funcDef;
if (funcDef = FuncDefPtr::cast(def))
return new FuncAnnotation(funcDef);
// else
// return new VarAnnotation(def);
assert(false && "VarAnnotations not supported yet");
}
| C++ |
// Copyright 2012 Google Inc.
#ifndef _model_EphemeralImportDef_h_
#define _model_EphemeralImportDef_h_
#include "VarDef.h"
namespace model {
SPUG_RCPTR(EphemeralImportDef)
/**
* This is a hack that lets us store an imported ephemeral module in the list
* of ordered definitions for a module namespace.
*/
class EphemeralImportDef : public VarDef {
public:
ModuleDefPtr module;
EphemeralImportDef(ModuleDef *module) :
VarDef(0, "ephemeral import: " + module->getNamespaceName()),
module(module) {
}
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_VarDef_h_
#define _model_VarDef_h_
#include "model/ResultExpr.h"
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
class Context;
SPUG_RCPTR(Expr);
class Namespace;
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(VarDefImpl);
SPUG_RCPTR(VarDef);
// Variable definition. All names in a context (including functions and
// types) are derived from VarDef's.
class VarDef : public virtual spug::RCBase {
protected:
Namespace *owner;
mutable std::string fullName; // a cache, built in getFullName
public:
TypeDefPtr type;
std::string name;
VarDefImplPtr impl;
bool constant;
VarDef(TypeDef *type, const std::string &name);
virtual ~VarDef();
ResultExprPtr emitAssignment(Context &context, Expr *expr);
/**
* Returns true if the definition type requires a slot in the instance
* variable.
*/
virtual bool hasInstSlot();
/**
* Returns true if the definition is class static.
*/
virtual bool isStatic() const;
/**
* Returns the fully qualified name of the definition.
*/
std::string getFullName() const;
/**
* Returns the display name of the definition. This is the name to be
* displayed in error messages. It is the same as the result of
* getFullName() except for builtins and symbols in the main module.
*/
virtual std::string getDisplayName() const;
/**
* Set namespace owner
*/
virtual void setOwner(Namespace *o) {
owner = o;
fullName.clear(); // must recache since owner changed
}
Namespace *getOwner(void) { return owner; }
/**
* Return true if the variable is unassignable.
*/
virtual bool isConstant();
virtual
void dump(std::ostream &out, const std::string &prefix = "") const;
/**
* Allow dumping from the debugger.
*/
void dump() const;
};
inline std::ostream &operator <<(std::ostream &out, const VarDef &def) {
def.dump(out);
return out;
}
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "VarDef.h"
#include "AssignExpr.h"
#include "VarDefImpl.h"
#include "Context.h"
#include "Expr.h"
#include "ResultExpr.h"
#include "TypeDef.h"
using namespace std;
using namespace model;
VarDef::VarDef(TypeDef *type, const std::string &name) :
type(type),
name(name),
owner(0),
constant(false) {
}
VarDef::~VarDef() {}
ResultExprPtr VarDef::emitAssignment(Context &context, Expr *expr) {
AssignExprPtr assign = new AssignExpr(0, this, expr);
return impl->emitAssignment(context, assign.get());
}
bool VarDef::hasInstSlot() {
return impl->hasInstSlot();
}
bool VarDef::isStatic() const {
return false;
}
std::string VarDef::getFullName() const {
if (!fullName.empty())
return fullName;
if (owner && !owner->getNamespaceName().empty())
fullName = owner->getNamespaceName()+"."+name;
else
fullName = name;
return fullName;
}
std::string VarDef::getDisplayName() const {
assert(owner && "no owner defined when getting display name");
std::string module = owner->getNamespaceName();
if (!module.compare(0, 6, ".main.")) {
// find the next namespace after the main script
size_t pos = module.find('.', 6);
if (pos != string::npos)
return module.substr(pos + 1) + "." + name;
else
return name;
} else if (module == ".builtin") {
return name;
} else {
return getFullName();
}
}
bool VarDef::isConstant() {
return constant;
}
void VarDef::dump(ostream &out, const string &prefix) const {
out << prefix << (type ? type->getFullName() : string("<null>")) << " " << name << endl;
}
void VarDef::dump() const {
dump(std::cerr, "");
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_OverloadDef_h_
#define _model_OverloadDef_h_
#include <list>
#include "FuncDef.h"
namespace model {
class Context;
SPUG_RCPTR(Expr);
SPUG_RCPTR(Namespace);
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(OverloadDef);
/** An overloaded function. */
class OverloadDef : public VarDef {
public:
typedef std::list<FuncDefPtr> FuncList;
typedef std::vector<OverloadDefPtr> ParentVec;
private:
FuncList funcs;
ParentVec parents;
/**
* Sets the impl and the type object from the function. To be called
* for the first function added as a hack to keep function-as-objects
* working.
*/
void setImpl(FuncDef *func);
/**
* Flatten the overload definition into a single list where each
* signature is represented only once.
*
* @param funcs output list of functions to add to.
*/
void flatten(FuncList &funcs) const;
public:
OverloadDef(const std::string &name) :
// XXX need function types, but they'll probably be assigned after
// the fact.
VarDef(0, name) {
}
/**
* Returns the overload matching the given args, null if one does not
* exist
*
* @param context the context used in case conversion expressions need
* to be constructed.
* @param args the argument list. This will be modified if 'convert'
* is not "noConvert".
* @param convertFlag defines whether and when conversions are done.
* @param allowOverrides by default, this function will ignore
* overrides of a virtual function in considering a match -
* this is to provide the correct method resolution order.
* Setting this flag to true causes it to return the first
* matching function, regardless of whether it is an override.
*/
FuncDef *getMatch(Context &context, std::vector<ExprPtr> &args,
FuncDef::Convert convertFlag,
bool allowOverrides
);
/**
* Returns the overload matching the given args. This does the full
* resolution pass, first attempting a resolution without any
* conversions and then applying conversions. As such, it will modify
* "args" if there are conversions to be applied.
*/
FuncDef *getMatch(Context &context, std::vector<ExprPtr> &args,
bool allowOverrides
);
/**
* Returns the overload with the matching signature if there is one,
* NULL if not.
* @param matchNames if true, require that the signator match the
* names of the arg list. If false, only require that the
* types match.
*/
FuncDef *getSigMatch(const ArgVec &args,
bool matchNames = false);
/**
* Returns the overload with no arguments. If 'acceptAlias' is false,
* it must belong to the same context as the overload in which it is
* defined.
*/
FuncDef *getNoArgMatch(bool acceptAlias);
/**
* Returns true if the overload includeds a signature for the
* specified argument list.
*/
bool matches(const ArgVec &args) {
return getSigMatch(args) ? true : false;
}
/**
* Adds the function to the overload set. The function will be
* inserted after all other overloads from the context but before
* overloads from the parent context.
*/
void addFunc(FuncDef *func);
/**
* Adds the parent overload. Lookups will be delgated to parents in
* the order provided.
*/
void addParent(OverloadDef *paren);
/** Returns true if 'parent' is a parent of the overload. */
bool hasParent(OverloadDef *parent);
/**
* Create an alias overload - an alias overload is comprised of all
* of the functions in the overload and its ancestors flattened. It
* has no ancestors of its own.
*/
OverloadDefPtr createAlias();
/**
* Iterate over the funcs local to this context - do not iterate over
* the functions in the parent overloads.
*/
/** @{ */
FuncList::iterator beginTopFuncs() { return funcs.begin(); }
FuncList::iterator endTopFuncs() { return funcs.end(); }
/** @} */
bool hasInstSlot();
bool isStatic() const;
/**
* Returns true if the overload consists of only one function.
*/
bool isSingleFunction() const;
/**
* Make sure we have an implementation object, create one if we don't.
*/
void createImpl();
virtual bool isConstant();
virtual
void dump(std::ostream &out, const std::string &prefix = "") const;
void display(std::ostream &out, const std::string &prefix = "") const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "CompositeNamespace.h"
#include "Expr.h"
#include "VarDef.h"
#include "ModuleDef.h"
#include "OverloadDef.h"
using namespace model;
CompositeNamespace::CompositeNamespace(Namespace *parent0,
Namespace *parent1
) :
Namespace(parent0->getNamespaceName()),
parents(2) {
parents[0] = parent0;
parents[1] = parent1;
}
ModuleDefPtr CompositeNamespace::getModule() {
return parents[0]->getModule();
}
NamespacePtr CompositeNamespace::getParent(unsigned index) {
if (index < parents.size())
return parents[index];
else
return 0;
}
void CompositeNamespace::addDef(VarDef *def) {
assert(OverloadDefPtr::cast(def) &&
"composite namespace addDef called on non-overload");
Namespace::addDef(def);
}
void CompositeNamespace::removeDef(VarDef *def) {
assert(false && "composite namespace mutation removeDef called");
}
void CompositeNamespace::addAlias(VarDef *def) {
assert(false && "composite namespace mutation addAlias(d) called");
}
OverloadDefPtr CompositeNamespace::addAlias(const std::string &name, VarDef *def) {
assert(false && "composite namespace mutation addAlias(n,d) called");
}
void CompositeNamespace::addUnsafeAlias(const std::string &name, VarDef *def) {
assert(false && "composite namespace mutation addUnsafeAlias(n,d) called");
}
void CompositeNamespace::replaceDef(VarDef *def) {
assert(false && "composite namespace mutation replaceDef called");
}
| C++ |
// Copyright 2010 Google Inc.
#include "Construct.h"
#include <sys/stat.h>
#include <fstream>
#include <dlfcn.h>
#include <limits.h>
#include <stdlib.h>
#include <sstream>
#include "parser/Parser.h"
#include "parser/ParseError.h"
#include "parser/Toker.h"
#include "spug/check.h"
#include "builder/Builder.h"
#include "ext/Module.h"
#include "Context.h"
#include "GlobalNamespace.h"
#include "ModuleDef.h"
#include "StrConst.h"
#include "TypeDef.h"
#include "compiler/init.h"
#include "builder/util/CacheFiles.h"
#include "builder/util/SourceDigest.h"
using namespace std;
using namespace model;
using namespace parser;
using namespace builder;
using namespace crack::ext;
void ConstructStats::write(std::ostream &out) const {
out << "\n----------------\n";
out << "parsed : " << parsedCount << "\n";
out << "cached : " << cachedCount << "\n";
out << "startup : " << timing[start] << "s\n";
out << "builtin : " << timing[builtin] << "s\n";
out << "parse/build: " << timing[build] << "s\n";
out << "run : " << timing[run] << "s\n";
double total = 0;
for (ModuleTiming::const_iterator i = moduleTimes.begin();
i != moduleTimes.end();
++i) {
cout << i->first << ": " << i->second << "s\n";
total += i->second;
}
out << "total module time: " << total << "s\n";
out << endl;
}
void ConstructStats::switchState(CompileState newState) {
struct timeval t;
gettimeofday(&t, NULL);
double beforeF = (lastTime.tv_usec/1000000.0) + lastTime.tv_sec;
double nowF = (t.tv_usec/1000000.0) + t.tv_sec;
double diff = (nowF - beforeF);
timing[state] += diff;
if (state == build && currentModule != "NONE") {
// if we are saving build time, add it to the current module
// as well
moduleTimes[currentModule] += diff;
}
lastTime = t;
state = newState;
}
Construct::ModulePath Construct::searchPath(
const Construct::StringVec &path,
Construct::StringVecIter moduleNameBegin,
Construct::StringVecIter moduleNameEnd,
const std::string &extension,
int verbosity
) {
// try to find a matching file.
for (StringVecIter pathIter = path.begin();
pathIter != path.end();
++pathIter
) {
string relPath = joinName(moduleNameBegin, moduleNameEnd, extension);
string fullName = joinName(*pathIter, relPath);
if (verbosity > 1)
cerr << "search: " << fullName << endl;
if (isFile(fullName))
return ModulePath(*pathIter, relPath, fullName, true, false);
}
// try to find a matching directory.
string empty;
for (StringVecIter pathIter = path.begin();
pathIter != path.end();
++pathIter
) {
string relPath = joinName(moduleNameBegin, moduleNameEnd, empty);
string fullName = joinName(*pathIter, relPath);
if (isDir(fullName))
return ModulePath(*pathIter, relPath, fullName, true, true);
}
return ModulePath(empty, empty, empty, false, false);
}
Construct::ModulePath Construct::searchPath(
const Construct::StringVec &path,
const string &relPath,
int verbosity
) {
// try to find a matching file.
for (StringVecIter pathIter = path.begin();
pathIter != path.end();
++pathIter
) {
string fullName = joinName(*pathIter, relPath);
if (verbosity > 1)
cerr << "search: " << fullName << endl;
if (isFile(fullName))
return ModulePath(*pathIter, relPath, fullName, true, false);
}
// try to find a matching directory.
string empty;
for (StringVecIter pathIter = path.begin();
pathIter != path.end();
++pathIter
) {
string fullName = joinName(*pathIter, relPath);
if (isDir(fullName))
return ModulePath(*pathIter, relPath, fullName, true, true);
}
return ModulePath(empty, empty, empty, false, false);
}
bool Construct::isFile(const std::string &name) {
struct stat st;
if (stat(name.c_str(), &st))
return false;
// XXX should check symlinks, too
return S_ISREG(st.st_mode);
}
bool Construct::isDir(const std::string &name) {
struct stat st;
if (stat(name.c_str(), &st))
return false;
// XXX should check symlinks, too
return S_ISDIR(st.st_mode);
}
std::string Construct::joinName(Construct::StringVecIter pathBegin,
Construct::StringVecIter pathEnd,
const std::string &ext
) {
string result;
StringVecIter iter = pathBegin;
if (iter != pathEnd) {
result = *iter;
++iter;
}
for (; iter != pathEnd; ++iter )
result += "/" + *iter;
return result + ext;
}
std::string Construct::joinName(const std::string &base,
const std::string &rel
) {
return base + "/" + rel;
}
Construct::Construct(Builder *builder, Construct *primary) :
rootBuilder(builder),
uncaughtExceptionFunc(0),
migrationWarnings(false) {
if (builder->options->statsMode)
stats = new ConstructStats();
builderStack.push(builder);
createRootContext();
// steal any stuff from the primary we want to use as a default.
if (primary)
sourceLibPath = primary->sourceLibPath;
}
void Construct::addToSourceLibPath(const string &path) {
size_t pos = 0;
size_t i = path.find(':');
while (i != -1) {
if (i > 1 && path[i-1] == '/')
sourceLibPath.push_back(path.substr(pos, i - pos - 1));
else
sourceLibPath.push_back(path.substr(pos, i - pos));
pos = i + 1;
i = path.find(':', pos);
}
if (path.size() > 1 && path[path.size()-1] == '/')
sourceLibPath.push_back(path.substr(pos, (path.size()-pos)-1));
else
sourceLibPath.push_back(path.substr(pos));
}
ContextPtr Construct::createRootContext() {
rootContext = new Context(*rootBuilder, Context::module, this,
new GlobalNamespace(0, ""),
new GlobalNamespace(0, "")
);
// register the primitives into our builtin module
ContextPtr builtinContext =
new Context(*rootBuilder, Context::module, rootContext.get(),
// NOTE we can't have rootContext namespace be the parent
// here since we are adding the aliases into rootContext
// and we get dependency issues
new GlobalNamespace(0, ".builtin"),
new GlobalNamespace(0, ".builtin"));
builtinMod = rootBuilder->registerPrimFuncs(*builtinContext);
// alias builtins to the root namespace
for (Namespace::VarDefMap::iterator i = builtinContext->ns->beginDefs();
i != builtinContext->ns->endDefs();
++i) {
rootContext->ns->addUnsafeAlias(i->first, i->second.get());
}
return rootContext;
}
void Construct::loadBuiltinModules() {
// loads the compiler extension. If we have a compile-time construct,
// the extension belongs to him and we just want to steal his defines.
// Otherwise, we initialize them ourselves.
NamespacePtr ns;
if (compileTimeConstruct) {
ns = compileTimeConstruct->rootContext->compileNS;
} else {
// initialize the built-in compiler extension and store the
// CrackContext type in global data.
ModuleDefPtr ccMod =
initExtensionModule("crack.compiler", &compiler::init, 0);
rootContext->construct->crackContext = ccMod->lookUp("CrackContext");
moduleCache["crack.compiler"] = ccMod;
ccMod->finished = true;
ns = ccMod;
}
// in either case, aliases get installed in the compiler namespace.
rootContext->compileNS->addAlias(ns->lookUp("static").get());
rootContext->compileNS->addAlias(ns->lookUp("final").get());
rootContext->compileNS->addAlias(ns->lookUp("abstract").get());
rootContext->compileNS->addAlias(ns->lookUp("FILE").get());
rootContext->compileNS->addAlias(ns->lookUp("LINE").get());
rootContext->compileNS->addAlias(ns->lookUp("encoding").get());
rootContext->compileNS->addAlias(ns->lookUp("export_symbols").get());
// load the runtime extension
StringVec crackRuntimeName(2);
crackRuntimeName[0] = "crack";
crackRuntimeName[1] = "runtime";
string name;
ModuleDefPtr rtMod = rootContext->construct->loadModule(
crackRuntimeName.begin(),
crackRuntimeName.end(),
name
);
if (!rtMod) {
cerr << "failed to load crack runtime from module load path" << endl;
// XXX exception?
exit(1);
}
// alias some basic builtins from runtime
// mostly for legacy reasons
VarDefPtr a = rtMod->lookUp("puts");
assert(a && "no puts in runtime");
rootContext->ns->addUnsafeAlias("puts", a.get());
a = rtMod->lookUp("putc");
assert(a && "no putc in runtime");
rootContext->ns->addUnsafeAlias("putc", a.get());
a = rtMod->lookUp("__die");
assert(a && "no __die in runtime");
rootContext->ns->addUnsafeAlias("__die", a.get());
rootContext->compileNS->addUnsafeAlias("__die", a.get());
a = rtMod->lookUp("printint");
if (a)
rootContext->ns->addUnsafeAlias("printint", a.get());
// for jit builders, get the uncaught exception handler
if (rootBuilder->isExec()) {
FuncDefPtr uncaughtExceptionFuncDef =
rootContext->lookUpNoArgs("__CrackUncaughtException", true,
rtMod.get()
);
if (uncaughtExceptionFuncDef)
uncaughtExceptionFunc =
reinterpret_cast<bool (*)()>(
uncaughtExceptionFuncDef->getFuncAddr(*rootBuilder)
);
else
cerr << "Uncaught exception function not found in runtime!" <<
endl;
}
}
void Construct::parseModule(Context &context,
ModuleDef *module,
const std::string &path,
istream &src
) {
Toker toker(src, path.c_str());
Parser parser(toker, &context);
string lastModule;
ConstructStats::CompileState oldStatState;
if (rootBuilder->options->statsMode) {
stats->switchState(ConstructStats::build);
lastModule = stats->currentModule;
stats->currentModule = module->getFullName();
oldStatState = context.construct->stats->state;
stats->parsedCount++;
}
parser.parse();
if (rootBuilder->options->statsMode) {
stats->switchState(oldStatState);
stats->currentModule = lastModule;
}
module->close(context);
}
ModuleDefPtr Construct::initExtensionModule(const string &canonicalName,
Construct::CompileFunc compileFunc,
Construct::InitFunc initFunc
) {
// create a new context
BuilderPtr builder = rootBuilder->createChildBuilder();
builderStack.push(builder);
ContextPtr context =
new Context(*builder, Context::module, rootContext.get(),
new GlobalNamespace(rootContext->ns.get(), canonicalName),
0 // we don't need a compile namespace
);
context->toplevel = true;
// create a module object
ModuleDefPtr modDef = context->createModule(canonicalName);
Module mod(context.get());
compileFunc(&mod);
modDef->fromExtension = true;
mod.finish();
modDef->close(*context);
builderStack.pop();
if (initFunc)
initFunc();
return modDef;
}
namespace {
// load a function from a shared library
void *loadFunc(void *handle, const string &path, const string &funcName) {
void *func = dlsym(handle, funcName.c_str());
if (!func) {
cerr << "Error looking up function " << funcName
<< " in extension library " << path << ": "
<< dlerror() << endl;
return 0;
} else {
return func;
}
}
}
ModuleDefPtr Construct::loadSharedLib(const string &path,
Construct::StringVecIter moduleNameBegin,
Construct::StringVecIter moduleNameEnd,
string &canonicalName
) {
void *handle = rootBuilder->loadSharedLibrary(path);
// construct the full init function name
// XXX should do real name mangling. also see LLVMLinkerBuilder::initializeImport
std::string initFuncName;
for (StringVecIter iter = moduleNameBegin;
iter != moduleNameEnd;
++iter
)
initFuncName += *iter + '_';
CompileFunc cfunc = (CompileFunc)loadFunc(handle, path,
initFuncName + "cinit"
);
InitFunc rfunc = (InitFunc)loadFunc(handle, path, initFuncName + "rinit");
if (!cfunc || !rfunc)
return 0;
return initExtensionModule(canonicalName, cfunc, rfunc);
}
ModuleDefPtr Construct::loadModule(const string &canonicalName) {
StringVec name;
name = ModuleDef::parseCanonicalName(canonicalName);
string cname;
ModuleDefPtr m = loadModule(name.begin(), name.end(), cname);
SPUG_CHECK(cname == canonicalName,
"canonicalName mismatch. constructed = " << cname <<
", requested = " << canonicalName
);
return m;
}
ModuleDefPtr Construct::loadFromCache(const string &canonicalName) {
if (!rootBuilder->options->cacheMode)
return 0;
// see if it's in the in-memory cache
Construct::ModuleMap::iterator iter = moduleCache.find(canonicalName);
if (iter != moduleCache.end())
return iter->second;
// create a new builder, context and module
BuilderPtr builder = rootBuilder->createChildBuilder();
builderStack.push(builder);
ContextPtr context =
new Context(*builder, Context::module, rootContext.get(),
new GlobalNamespace(rootContext->ns.get(),
canonicalName
),
new GlobalNamespace(rootContext->compileNS.get(),
canonicalName
)
);
context->toplevel = true;
ModuleDefPtr modDef = context->materializeModule(canonicalName);
if (modDef && rootBuilder->options->statsMode)
stats->cachedCount++;
moduleCache[canonicalName] = modDef;
builderStack.pop();
return modDef;
}
ModuleDefPtr Construct::loadModule(Construct::StringVecIter moduleNameBegin,
Construct::StringVecIter moduleNameEnd,
string &canonicalName
) {
// create the dotted canonical name of the module
StringVecIter iter = moduleNameBegin;
if (iter != moduleNameEnd) {
canonicalName = *iter;
++iter;
}
for (; iter != moduleNameEnd; ++iter)
canonicalName += "." + *iter;
// check to see if we have it in the cache
Construct::ModuleMap::iterator mapi = moduleCache.find(canonicalName);
if (mapi != moduleCache.end())
return mapi->second;
// look for a shared library
ModulePath modPath = searchPath(sourceLibPath, moduleNameBegin,
moduleNameEnd,
".so",
rootBuilder->options->verbosity
);
ModuleDefPtr modDef;
if (modPath.found && !modPath.isDir) {
modDef = loadSharedLib(modPath.path, moduleNameBegin,
moduleNameEnd,
canonicalName
);
moduleCache[canonicalName] = modDef;
} else {
// not in in-memory cache, not a shared library
// create a new builder, context and module
BuilderPtr builder = rootBuilder->createChildBuilder();
builderStack.push(builder);
ContextPtr context =
new Context(*builder, Context::module, rootContext.get(),
new GlobalNamespace(rootContext->ns.get(),
canonicalName
),
new GlobalNamespace(rootContext->compileNS.get(),
canonicalName
)
);
context->toplevel = true;
// before parsing the module from scratch, we give the builder a chance
// to materialize the module through its own means (e.g., a cache)
bool cached = false;
if (rootBuilder->options->cacheMode && !modPath.isDir)
modDef = context->materializeModule(canonicalName);
if (modDef && modDef->matchesSource(sourceLibPath)) {
cached = true;
if (rootBuilder->options->statsMode)
stats->cachedCount++;
} else {
// if we got a stale module from the cache, use the relative
// source path of that module (avoiding complications from cached
// ephemeral modules). Otherwise, just look it up in the library
// path.
if (modDef)
modPath = searchPath(sourceLibPath, modDef->sourcePath,
rootBuilder->options->verbosity
);
else
modPath = searchPath(sourceLibPath, moduleNameBegin,
moduleNameEnd, ".crk",
rootBuilder->options->verbosity
);
if (!modPath.found)
return 0;
modDef = context->createModule(canonicalName, modPath.path);
}
modDef->sourcePath = modPath.relPath;
moduleCache[canonicalName] = modDef;
if (!cached) {
if (!modPath.isDir) {
ifstream src(modPath.path.c_str());
// parse from scratch
parseModule(*context, modDef.get(), modPath.path, src);
} else {
// directory
modDef->close(*context);
}
} else {
// XXX hook to run/finish cached module
}
builderStack.pop();
}
modDef->finished = true;
loadedModules.push_back(modDef);
return modDef;
}
void Construct::registerModule(ModuleDef *module) {
moduleCache[module->getFullName()] = module;
loadedModules.push_back(module);
}
namespace {
// extract a class from a module and verify that it is a class - returns
// null on failure.
TypeDef *extractClass(ModuleDef *mod, const char *name) {
VarDefPtr var = mod->lookUp(name);
TypeDef *type;
if (var && (type = TypeDefPtr::rcast(var))) {
return type;
} else {
cerr << name << " class not found in module crack.lang" << endl;
return 0;
}
}
}
bool Construct::loadBootstrapModules() {
try {
StringVec crackLangName(2);
crackLangName[0] = "crack";
crackLangName[1] = "lang";
string name;
ModuleDefPtr mod = loadModule(crackLangName.begin(),
crackLangName.end(),
name
);
if (!mod) {
cerr << "Bootstrapping module crack.lang not found." << endl;
return false;
}
// extract the basic types from the module context
rootContext->construct->objectType = extractClass(mod.get(), "Object");
rootContext->ns->addAlias(rootContext->construct->objectType.get());
rootContext->construct->stringType = extractClass(mod.get(), "String");
rootContext->ns->addAlias(rootContext->construct->stringType.get());
rootContext->construct->staticStringType =
extractClass(mod.get(), "StaticString");
rootContext->ns->addAlias(
rootContext->construct->staticStringType.get()
);
// replace the bootstrapping context with a new context that
// delegates to the original root context - this is the "bootstrapped
// context." It contains all of the special definitions that were
// extracted from the bootstrapping modules.
rootContext = rootContext->createSubContext(Context::module);
// extract some constants
VarDefPtr v = mod->lookUp("true");
if (v)
rootContext->ns->addAlias(v.get());
v = mod->lookUp("false");
if (v)
rootContext->ns->addAlias(v.get());
v = mod->lookUp("print");
if (v)
rootContext->ns->addUnsafeAlias("print", v.get());
return rootContext->construct->objectType &&
rootContext->construct->stringType;
} catch (const ParseError &ex) {
cerr << ex << endl;
return false;
} catch (...) {
if (!uncaughtExceptionFunc)
cerr << "Uncaught exception, no uncaught exception handler!" <<
endl;
else if (!uncaughtExceptionFunc())
cerr << "Unknown exception caught." << endl;
}
return true;
}
namespace {
// Returns a "brief path" for the filename. A brief path consists of an
// md5 hash of the absolute path of the directory of the file, followed by
// an underscore and the file name.
string briefPath(const string &filename) {
// try to expand the name to the real path
char path[PATH_MAX];
string fullName;
if (realpath(filename.c_str(), path))
fullName = path;
else
fullName = filename;
// convert the directory to a hash
int lastSlash = fullName.rfind('/');
if (lastSlash == fullName.size()) {
return fullName;
} else {
ostringstream tmp;
tmp << SourceDigest::fromStr(fullName.substr(0, lastSlash)).asHex()
<< '_' << fullName.substr(lastSlash + 1);
return tmp.str();
}
}
// Converts a script name to its canonical module name. Module names for
// scripts are of the form ".main._<abs-path-hash>_<escaped-filename>"
string modNameFromFile(const string &filename) {
ostringstream tmp;
tmp << ".main._";
string base = briefPath(filename);
for (int i = 0; i < base.size(); ++i) {
if (isalnum(base[i]))
tmp << base[i];
else
tmp << "_" << hex << static_cast<int>(base[i]);
}
return tmp.str();
}
}
int Construct::runScript(istream &src, const string &name) {
// get the canonical name for the script
string canName = modNameFromFile(name);
// create the builder and context for the script.
BuilderPtr builder = rootBuilder->createChildBuilder();
builderStack.push(builder);
ContextPtr context =
new Context(*builder, Context::module, rootContext.get(),
new GlobalNamespace(rootContext->ns.get(), canName)
);
context->toplevel = true;
ModuleDefPtr modDef;
bool cached = false;
if (rootBuilder->options->cacheMode)
builder::initCacheDirectory(rootBuilder->options.get());
// we check cacheMode again after init,
// because it might have been disabled if
// we couldn't find an appropriate cache directory
if (rootBuilder->options->cacheMode) {
modDef = context->materializeModule(canName);
}
if (modDef) {
cached = true;
loadedModules.push_back(modDef);
if (rootBuilder->options->statsMode)
stats->cachedCount++;
}
else
modDef = context->createModule(canName, name);
try {
if (!cached) {
parseModule(*context, modDef.get(), name, src);
loadedModules.push_back(modDef);
} else {
// XXX hook to run/finish cached module
}
} catch (const ParseError &ex) {
cerr << ex << endl;
return 1;
} catch (...) {
if (!uncaughtExceptionFunc)
cerr << "Uncaught exception, no uncaught exception handler!" <<
endl;
else if (!uncaughtExceptionFunc())
cerr << "Unknown exception caught." << endl;
}
builderStack.pop();
rootBuilder->finishBuild(*context);
if (rootBuilder->options->statsMode)
stats->switchState(ConstructStats::end);
return 0;
}
builder::Builder &Construct::getCurBuilder() {
return *builderStack.top();
}
void Construct::registerDef(VarDef *def) {
registry[def->getFullName()] = def;
}
VarDefPtr Construct::getRegisteredDef(const std::string &name) {
VarDefMap::iterator iter = registry.find(name);
if (iter != registry.end())
return iter->second;
else
return 0;
} | C++ |
#include "Deserializer.h"
#include <assert.h>
#include <stdint.h>
#include <iostream>
using namespace std;
using namespace model;
unsigned int Deserializer::readUInt() {
uint8_t b = 0x80;
unsigned val = 0, offset = 0;
while (b & 0x80) {
b = src.get();
// see if we've got the last byte
val = val | ((b & 0x7f) << offset);
offset += 7;
}
return val;
}
char *Deserializer::readBlob(size_t &size, char *buffer) {
size_t cap = size;
size = readUInt();
if (size > cap || !buffer)
buffer = new char[size];
src.read(buffer, size);
return buffer;
}
string Deserializer::readString(size_t expectedMaxSize) {
char buffer[expectedMaxSize];
size_t size = expectedMaxSize;
char *tmp = readBlob(size, buffer);
if (tmp != buffer) {
string result(tmp, size);
delete tmp;
} else {
return string(tmp, size);
}
}
void *Deserializer::readObject(const ObjectReader &reader) {
int id = readUInt();
if (id & 1) {
// this is a definition - let the reader read the object
void *obj = reader.read(*this);
objMap[id >> 1] = obj;
return obj;
} else {
// the object should already exist
ObjMap::iterator iter = objMap.find(id >> 1);
assert(iter != objMap.end() && "Unable to resolve serialized object");
return iter->second;
}
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_Expr_h_
#define _model_Expr_h_
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
class Context;
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(ResultExpr);
SPUG_RCPTR(Expr);
// Base class for everything representing an expression.
class Expr : public spug::RCBase {
public:
TypeDefPtr type;
Expr(TypeDef *type);
~Expr();
/**
* Emit the expression in the given context.
*
* Returns a result expression to be used for object lifecycle
* management.
*/
virtual ResultExprPtr emit(Context &context) = 0;
/**
* Emit the expression for use in a conditional context.
* This defaults to calling Builder::emitTest(). Builder-derived
* classes should override in cases where there is a more appropriate
* path.
*/
virtual void emitCond(Context &context);
/**
* Returns an expression that converts the expression to the specified
* type, null if it cannot be converted.
*/
virtual ExprPtr convert(Context &context, TypeDef *type);
/** Returns true if the expression is productive (see /notes.txt). */
virtual bool isProductive() const;
/**
* Returns true if the expression changes type to adapt to the
* requirements of the context (integer and float constants).
*/
virtual bool isAdaptive() const;
/**
* Write a representation of the expression to the stream.
*/
virtual void writeTo(std::ostream &out) const = 0;
/**
* Do const folding on the expression. Returns either the original
* expression object or a folded constant.
* The base class version of this always returns null. Derived
* classes may implement it for operations that support const folding.
*/
virtual ExprPtr foldConstants();
void dump() const;
};
inline std::ostream &operator <<(std::ostream &out, const Expr &expr) {
expr.writeTo(out);
return out;
}
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "StrConst.h"
#include "builder/Builder.h"
#include "VarDefImpl.h"
#include "Context.h"
#include "ResultExpr.h"
#include "TypeDef.h"
using namespace model;
using namespace std;
StrConst::StrConst(TypeDef *type, const std::string &val) :
Expr(type),
val(val) {
}
ResultExprPtr StrConst::emit(Context &context) {
return context.builder.emitStrConst(context, this);
}
void StrConst::writeTo(ostream &out) const {
out << '"' << val << '"';
}
| C++ |
#include "Namespace.h"
#include "Context.h"
#include "Expr.h"
#include "OverloadDef.h"
#include "VarDef.h"
using namespace std;
using namespace model;
void Namespace::storeDef(VarDef *def) {
assert(!FuncDefPtr::cast(def) &&
"it is illegal to store a FuncDef directly (should be wrapped "
"in an OverloadDef)");
defs[def->name] = def;
orderedForCache.push_back(def);
}
VarDefPtr Namespace::lookUp(const std::string &varName, bool recurse) {
VarDefMap::iterator iter = defs.find(varName);
if (iter != defs.end()) {
return iter->second;
} else if (recurse) {
VarDefPtr def;
// try to find the definition in the parents
NamespacePtr parent;
for (unsigned i = 0; parent = getParent(i++);)
if (def = parent->lookUp(varName))
break;
return def;
}
return 0;
}
ModuleDefPtr Namespace::getRealModule() {
ModuleDefPtr mod = getModule();
ModuleDefPtr owner = ModuleDefPtr::cast(mod->getOwner());
return owner ? owner : mod;
}
bool Namespace::hasAliasFor(VarDef *def) const {
for (VarDefMap::const_iterator iter = defs.begin(); iter != defs.end();
++iter
)
if (iter->second.get() == def)
return true;
return false;
}
void Namespace::addDef(VarDef *def) {
assert(!def->getOwner());
storeDef(def);
def->setOwner(this);
}
void Namespace::removeDef(VarDef *def) {
assert(!OverloadDefPtr::cast(def));
VarDefMap::iterator iter = defs.find(def->name);
assert(iter != defs.end());
defs.erase(iter);
// remove it from the ordered defs
for (VarDefVec::iterator iter = ordered.begin();
iter != ordered.end();
++iter
) {
ordered.erase(iter);
break;
}
// remove it from the ordered for cache defs
for (VarDefVec::iterator iter = orderedForCache.begin();
iter != orderedForCache.end();
++iter
) {
orderedForCache.erase(iter);
break;
}
}
void Namespace::addAlias(VarDef *def) {
// make sure that the symbol is already bound to a context.
assert(def->getOwner());
// overloads should never be aliased - otherwise the new context could
// extend them.
OverloadDef *overload = OverloadDefPtr::cast(def);
if (overload) {
OverloadDefPtr child = overload->createAlias();
storeDef(child.get());
child->setOwner(this);
} else {
storeDef(def);
}
}
OverloadDefPtr Namespace::addAlias(const string &name, VarDef *def) {
// make sure that the symbol is already bound to a context.
assert(def->getOwner());
// overloads should never be aliased - otherwise the new context could
// extend them.
OverloadDef *overload = OverloadDefPtr::cast(def);
if (overload) {
OverloadDefPtr child = overload->createAlias();
defs[name] = child.get();
child->setOwner(this);
return child;
} else {
defs[name] = def;
return 0;
}
}
void Namespace::addUnsafeAlias(const string &name, VarDef *def) {
// make sure that the symbol is already bound to a context.
assert(def->getOwner());
defs[name] = def;
}
void Namespace::aliasAll(Namespace *other) {
for (VarDefMap::iterator iter = other->beginDefs();
iter != other->endDefs();
++iter
)
if (!lookUp(iter->first))
addAlias(iter->second.get());
// do parents afterwards - since we don't clobber existing aliases, we
// want to do the innermost names first.
NamespacePtr parent;
for (int i = 0; parent = other->getParent(i++);) {
aliasAll(parent.get());
}
}
void Namespace::replaceDef(VarDef *def) {
assert(!def->getOwner());
assert(!def->hasInstSlot() &&
"Attempted to replace an instance variable, this doesn't work "
"because it won't change the 'ordered' vector."
);
def->setOwner(this);
defs[def->name] = def;
}
void Namespace::dump(ostream &out, const string &prefix) {
out << canonicalName << " (0x" << this << ") {\n";
string childPfx = prefix + " ";
unsigned i = 0;
Namespace *parent;
while (parent = getParent(i++).get()) {
out << childPfx << "parent namespace ";
parent->dump(out, childPfx);
}
for (VarDefMap::const_iterator varIter = defs.begin();
varIter != defs.end();
++varIter
)
varIter->second->dump(out, childPfx);
out << prefix << "}\n";
}
void Namespace::dump() {
dump(cerr, "");
}
| C++ |
// Copyright 2011 Google Inc.
#ifndef _model_GenericParm_h_
#define _model_GenericParm_h_
#include <vector>
#include "spug/RCPtr.h"
#include "spug/RCBase.h"
namespace model {
SPUG_RCPTR(GenericParm);
/** A parameter for a generic type. */
class GenericParm : public spug::RCBase {
public:
std::string name;
GenericParm(const std::string &name) : name(name) {}
};
typedef std::vector<GenericParmPtr> GenericParmVec;
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_ConstVarDef_h_
#define _model_ConstVarDef_h_
#include "VarDef.h"
namespace model {
SPUG_RCPTR(ConstVarDef);
class ConstVarDef : public VarDef {
public:
ExprPtr expr;
ConstVarDef(TypeDef *type, const std::string &name,
ExprPtr expr
) :
VarDef(type, name),
expr(expr) {
}
virtual bool isConstant() { return true; }
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_VarRef_h_
#define _model_VarRef_h_
#include "Expr.h"
namespace model {
SPUG_RCPTR(VarDef);
SPUG_RCPTR(VarRef);
// A variable reference - or dereference, actually.
class VarRef : public Expr {
public:
// the definition of the variable we're referencing
VarDefPtr def;
VarRef(VarDef *def);
virtual ResultExprPtr emit(Context &context);
// variable references are non-productive, so we override.
virtual bool isProductive() const;
virtual void writeTo(std::ostream &out) const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
// Copyright 2010 Shannon Weyrick <weyrick@mozek.us>
#include "FloatConst.h"
#include <math.h>
#include "builder/Builder.h"
#include "parser/ParseError.h"
#include "VarDefImpl.h"
#include "Context.h"
#include "ResultExpr.h"
#include "TypeDef.h"
#include "IntConst.h"
using namespace model;
using namespace parser;
FloatConst::FloatConst(TypeDef *type, double val) :
Expr(type),
val(val) {
}
ResultExprPtr FloatConst::emit(Context &context) {
return context.builder.emitFloatConst(context, this);
}
ExprPtr FloatConst::convert(Context &context, TypeDef *newType) {
if (newType == this->type)
return this;
if (newType == context.construct->float64Type ||
newType == context.construct->float32Type ||
newType == context.construct->floatType
)
; // nothing we can do about these right now
else {
// delegate all other conversions to the type
return Expr::convert(context, newType);
}
return context.builder.createFloatConst(context, val, newType);
}
void FloatConst::writeTo(std::ostream &out) const {
out << val;
}
bool FloatConst::isAdaptive() const {
return true;
}
FloatConstPtr FloatConst::create(double val) const {
return new FloatConst(type.get(), val);
}
ExprPtr FloatConst::foldFRem(Expr *other) {
FloatConstPtr fo = FloatConstPtr::cast(other);
if (fo)
return create(val - floor(val / fo->val) * fo->val);
return 0;
}
ExprPtr FloatConst::foldNeg() {
return create(-val);
}
#define FOLD(name, sym) \
ExprPtr FloatConst::fold##name(Expr *other) { \
FloatConstPtr fo = FloatConstPtr::cast(other); \
if (fo) \
return create(val sym fo->val); \
\
return 0; \
}
FOLD(FAdd, +)
FOLD(FSub, -)
FOLD(FMul, *)
FOLD(FDiv, /)
| C++ |
// Copyright 2009 Google Inc.
#include "ResultExpr.h"
#include "builder/Builder.h"
#include "CleanupFrame.h"
#include "Context.h"
#include "FuncCall.h"
#include "FuncDef.h"
#include "TypeDef.h"
using namespace model;
void ResultExpr::handleAssignment(Context &context) {
// if the expression is productive, the assignment will just consume its
// reference.
if (sourceExpr->isProductive())
return;
// the expression is non-productive: check for a bind function
FuncCall::ExprVec args;
FuncDefPtr bindFunc = context.lookUpNoArgs("oper bind", false, type.get());
if (!bindFunc)
return;
// got a bind function: create a bind call and emit it. (emit should
// return a ResultExpr for a void object, so we don't need to do anything
// special for it).
FuncCallPtr bindCall = context.builder.createFuncCall(bindFunc.get());
bindCall->receiver = this;
bindCall->emit(context);
}
void ResultExpr::handleTransient(Context &context) {
// we don't need to do anything if we're currently emitting cleanups or for
// non-productive expressions.
if (context.emittingCleanups || !sourceExpr->isProductive())
return;
// the expression is productive - clean it up
forceCleanup(context);
}
void ResultExpr::forceCleanup(Context &context) {
// check for a release function
FuncDefPtr releaseFunc = context.lookUpNoArgs("oper release", false,
type.get()
);
if (!releaseFunc)
return;
// got a release function: create a release call and store it in the
// cleanups.
FuncCallPtr releaseCall =
context.builder.createFuncCall(releaseFunc.get());
releaseCall->receiver = this;
context.cleanupFrame->addCleanup(releaseCall.get());
}
bool ResultExpr::isProductive() const {
// result expressions are always non-productive, since they always
// reference the result of an existing expression. This means that the
// ResultExpression returned from ResultExpression::emit() will treat a
// re-used result as a non-productive expression, which is what we want.
return false;
}
void ResultExpr::writeTo(std::ostream &out) const {
out << "result(" << *sourceExpr << ')';
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_Context_h_
#define _model_Context_h_
#include <map>
#include <vector>
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
#include "Construct.h"
#include "FuncDef.h"
#include "parser/Location.h"
namespace builder {
class Builder;
}
namespace parser {
class Token;
}
namespace model {
SPUG_RCPTR(Annotation);
SPUG_RCPTR(Branchpoint);
SPUG_RCPTR(BuilderContextData);
SPUG_RCPTR(CleanupFrame);
SPUG_RCPTR(Expr);
SPUG_RCPTR(ModuleDef);
SPUG_RCPTR(Namespace);
SPUG_RCPTR(OverloadDef);
SPUG_RCPTR(StrConst);
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(VarDef);
SPUG_RCPTR(VarRef);
SPUG_RCPTR(Context);
/**
* Holds everything relevant to the current parse context.
*/
class Context : public spug::RCBase {
private:
// break, continue and catch branchpoints
BranchpointPtr breakBranch, continueBranch, catchBranch;
// the current source location.
parser::Location loc;
// initializer for an empty location object
static parser::Location emptyLoc;
// emit a variable definition with no error checking.
VarDefPtr emitVarDef(Context *defCtx, TypeDef *type,
const std::string &name,
Expr *initializer,
bool constant = false
);
// issue a warning if defining the variable would hide a symbol in an
// enclosing context.
void warnOnHide(const std::string &name);
// create a new overload for srcNs that correctly delegates to the
// ancestor namespace.
OverloadDefPtr replicateOverload(const std::string &varName,
Namespace *srcNs
);
public:
// context scope - this is used to control how variables defined in
// the scope are stored.
enum Scope {
module,
instance,
local,
composite // scope is just a composition of parent scopes
};
ContextPtr parent;
// the context namespace.
NamespacePtr ns;
// the compile namespace (used to resolve annotations).
NamespacePtr compileNS;
builder::Builder &builder;
BuilderContextDataPtr builderData;
Scope scope;
// true if the context is the outermost context of a function.
bool toplevel;
// true if we are currently in the process of emitting cleanups -
// prevents us from trying to add cleanups on the expressions that we
// are cleaning up.
bool emittingCleanups;
// if true, a terminal statement has been emitted in the context.
bool terminal;
// this is the return type for a function context, and the class type
// for a class context.
TypeDefPtr returnType;
// a register used to store results passed between different parts of
// complex expressions (see SetRegisterExpr and GetRegisterExpr).
ResultExprPtr reg;
// the current cleanup frame.
CleanupFramePtr cleanupFrame;
// flags to be injected into the next function
FuncDef::Flags nextFuncFlags;
// flags to be injected into the next class
TypeDef::Flags nextClassFlags;
// the construct
Construct *construct;
Context(builder::Builder &builder, Scope scope, Context *parentContext,
Namespace *ns,
Namespace *compileNS = 0
);
Context(builder::Builder &builder, Scope scope, Construct *construct,
Namespace *ns,
Namespace *compileNS
);
~Context();
/**
* Create a new subcontext with a different scope from the parent
* context.
*/
ContextPtr createSubContext(Scope newScope, Namespace *ns = 0,
const std::string *name = 0,
Namespace *cns = 0
);
/**
* Create a new subcontext in the same scope.
* @param sameCNS if true, use the compile namespace of the existing
* context.
*/
ContextPtr createSubContext(bool sameCNS = false) {
return createSubContext(scope, 0, 0,
sameCNS ? compileNS.get() : 0
);
}
/**
* Returns the depth-first closest enclosing class context, null if
* there is none. (class contexts are contexts with scope = instance)
*/
ContextPtr getClassContext();
/**
* Returns the depth-first closest enclosing definition context,
* raises an exception if there is none.
* Definition contexts are non-composite contexts.
*/
ContextPtr getDefContext();
/**
* Returns the depth-first closest enclosing toplevel context.
*/
ContextPtr getToplevel();
/**
* Returns the first enclosing module context.
*/
ContextPtr getModuleContext();
/**
* Returns the parent of the context.
*/
ContextPtr getParent() {
return parent;
}
/**
* Returns the compile-time construct - this will revert to the
* default construct if there is no compile-time construct.
*/
Construct *getCompileTimeConstruct() {
if (construct->compileTimeConstruct.get())
return construct->compileTimeConstruct.get();
else
return construct;
}
/**
* Returns true if the context encloses the "other" context - a
* context encloses another context if it is an ancestor of the other
* context.
*/
bool encloses(const Context &other) const;
ModuleDefPtr createModule(const std::string &name,
const std::string &path = "",
ModuleDef *owner = 0
);
// possibly load from cache
ModuleDefPtr materializeModule(const std::string &canonicalName,
ModuleDef *owner = 0
);
/**
* Get or create a string constant. This can be either a
* "StaticString(StrConst, uint size)" expression if StaticString is
* defined, or a simple StrConst if it is not.
* @param raw if true, create a byteptr even if StaticString is
* defined.
*/
ExprPtr getStrConst(const std::string &value, bool raw = false);
/**
* Create a new cleanup frame. Cleanup frames group all
* cleanups that are emitted until the frame is closed with
* closeCleanupFrame(). Code emitted within a cleanup frame must
* call all of the cleanups whenever exiting from the scope of the
* frame, no matter how it exits.
*/
CleanupFramePtr createCleanupFrame();
/**
* Closes the current cleanup frame, emitting all cleaup code if
* appropriate.
*/
void closeCleanupFrame();
/**
* Create a forward declaration for the class and return it.
*/
TypeDefPtr createForwardClass(const std::string &name);
/**
* Checks for any forward declarations that have not been defined.
* Throws a ParseError if there are any.
*/
void checkForUnresolvedForwards();
/**
* Emit a variable definition in the context.
*/
VarDefPtr emitVarDef(TypeDef *type, const parser::Token &name,
Expr *initializer,
bool constant = false
);
/**
* Create a ternary expression.
*/
ExprPtr createTernary(Expr *cond, Expr *trueVal, Expr *falseVal);
/**
* Emit a sequence initializer.
*/
ExprPtr emitConstSequence(TypeDef *type,
const std::vector<ExprPtr> &elems
);
/**
* Returns true if the namespace is in the same function as the
* context.
*/
bool inSameFunc(Namespace *varNS);
/**
* Create a variable reference from the context and check that the
* variable is actually reachable from the context.
*/
ExprPtr createVarRef(VarDef *def);
/**
* Create a field reference and check that the variable is actually in
* the aggregate.
*/
VarRefPtr createFieldRef(Expr *aggregate, VarDef *var);
/**
* Set the branchpoint to be used for a break statement.
* @param branch the branchpoint, may be null.
*/
void setBreak(Branchpoint *branch);
/**
* Set the branchpoint to be used for a continue statement.
* @param branch the branchpoint, may be null.
*/
void setContinue(Branchpoint *branch);
/**
* Set the "catch" flag, indicating that this context is in a try
* block.
*/
void setCatchBranchpoint(Branchpoint *branch);
/**
* Obtains the branchpoint to be used for a break statement, returns
* null if there is none.
*/
Branchpoint *getBreak();
/**
* Obtains the branchpoint to be used for a continue statement,
* returns null if there is none.
*/
Branchpoint *getContinue();
/**
* Returns the catch context - this is either the first enclosing
* context with a try/catch statement or the parent of the toplevel
* context.
*/
ContextPtr getCatch();
/**
* Returns the catch branchpoint for the context.
*/
BranchpointPtr getCatchBranchpoint();
/**
* Create a reference to the "this" variable, error if there is none.
*/
model::ExprPtr makeThisRef(const std::string &memberName);
/**
* Expand an iterator style for loop into initialization, condition
* and after-body. The initialization will actually be emitted,
* condition and after-body will be filled in.
*/
void expandIteration(const std::string &name, bool defineVar,
bool isIter,
Expr *seqExpr,
ExprPtr &cond,
ExprPtr &beforeBody,
ExprPtr &afterBody
);
// Function store/lookup methods (these are handled through a Context
// instead of a namespace because Context can better do overload
// management)
/**
* Looks up a symbol in the context. Use this when looking up an
* overload definition if you care about it including all possible
* overloads accessible from the scope.
*/
VarDefPtr lookUp(const std::string &varName, Namespace *srcNs = 0);
/**
* Looks up a function matching the given expression list.
*
* @param context the current context (distinct from the lookup
* context)
* @param varName the function name
* @param vals list of parameter expressions. These will be converted
* to conversion expressions of the correct type for a match.
* @param srcNs if specified, the namespace to do the lookup in
* (default is the context's namespace)
* @param allowOverrides by default, this function will ignore
* overrides of a virtual function in considering a match - this is
* to provide the correct method resolution order. Setting this flag
* to true causes it to return the first matching function,
* regardless of whether it is an override.
*/
FuncDefPtr lookUp(const std::string &varName,
std::vector<ExprPtr> &vals,
Namespace *srcNs = 0,
bool allowOverrides = false
);
/**
* Look up a function with no arguments. This is provided as a
* convenience, as in this case we don't need to pass the call context.
* @param acceptAlias if false, ignore an alias.
* @param srcNs if specified, the namespace to do the lookup in
* (default is the context's namespace)
*/
FuncDefPtr lookUpNoArgs(const std::string &varName,
bool acceptAlias = true,
Namespace *srcNs = 0
);
/**
* Add a new variable definition to the context namespace. This is
* preferable to the Namespace::addDef() method in that it wraps
* FuncDef objects in an OverloadDef.
* @returns the definition that was actually stored. This could be
* varDef or
*/
VarDefPtr addDef(VarDef *varDef, Namespace *srcNs = 0);
/**
* Insures that if there is a child overload definition for 'overload'
* in the context's namespace, that it delegates to 'overload' in
* 'ancestor's namespace.
*/
void insureOverloadPath(Context *ancestor, OverloadDef *overload);
/**
* If an overload exists for varName,
* this will write overload possibilities to stream out
*/
void maybeExplainOverload(std::ostream &out,
const std::string &varName,
Namespace *srcNs);
// location management
/**
* Set the current source location.
*/
void setLocation(const parser::Location loc0) {
loc = loc0;
}
/**
* Get the current location.
*/
const parser::Location &getLocation() const {
return loc;
}
// annotation management
/**
* Look up the annotation in the compile namespace. Returns null if
* undefined.
*/
AnnotationPtr lookUpAnnotation(const std::string &name);
// error/warning handling
/**
* Emit an error message. If 'throwException' is true, a
* ParseException will be thrown. Otherwise, exit() is called to
* terminate the program.
*/
void error(const parser::Location &loc, const std::string &msg,
bool throwException = true
);
/**
* Emit an error message using the last recorded location.
*/
void error(const std::string &msg, bool throwException = true) {
error(loc, msg, throwException);
}
/**
* Emit the warning.
*/
void warn(const parser::Location &loc, const std::string &msg);
/**
* Emit the warning using the last recorded location.
*/
void warn(const std::string &msg) {
warn(loc, msg);
}
/**
* Push an error context. Error contexts will be displayed indented
* under an error or warning in the reverse order in which they were
* pushed.
*/
void pushErrorContext(const std::string &msg);
/**
* Pop and discard the last error context.
*/
void popErrorContext();
/**
* Verifies that the variable is accessible within the context (that
* it is not some other namespace's private or protected variable).
*/
void checkAccessible(VarDef *var);
/**
* Used to indicate that somthing in the current context depends on
* the module, and as such the module must be loaded and initialized
* in order for the current module to work.
*
* This was added to accomodate generics instantiations, which act
* like an implicit import of a dependent module.
*/
void recordDependency(ModuleDef *module);
void dump(std::ostream &out, const std::string &prefix) const;
void dump();
};
inline std::ostream &operator <<(std::ostream &out, const Context &context) {
context.dump(out, "");
return out;
}
}; // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_Namespace_h_
#define _model_Namespace_h_
#include <map>
#include <vector>
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
class Context;
SPUG_RCPTR(Expr);
SPUG_RCPTR(FuncDef);
SPUG_RCPTR(ModuleDef);
SPUG_RCPTR(OverloadDef);
SPUG_RCPTR(VarDef);
SPUG_RCPTR(Namespace);
/**
* A namespace is a symbol table. It defines the symbols that exist in a
* given context.
*/
class Namespace : public virtual spug::RCBase {
public:
typedef std::map<std::string, VarDefPtr> VarDefMap;
typedef std::vector<VarDefPtr> VarDefVec;
protected:
VarDefMap defs;
// in an "instance" context, this maintains the order of declaration
// of the instance variables so we can create and delete in the
// correct order.
VarDefVec ordered;
// ordered list of _all_ vardefs. XXX this is only needed for
// caching currently
VarDefVec orderedForCache;
// fully qualified namespace name, e.g. "crack.io"
std::string canonicalName;
/**
* Stores a definition, promoting it to an overload if necessary.
*/
virtual void storeDef(VarDef *def);
public:
Namespace(const std::string &cName) :
canonicalName(cName)
{
}
/**
* Returns the fully qualified name of the namespace
*/
const std::string &getNamespaceName() const { return canonicalName; }
/**
* Returns the parent at the index, null if it is greater than
* the number of parents.
*/
virtual NamespacePtr getParent(unsigned index) = 0;
VarDefPtr lookUp(const std::string &varName, bool recurse = true);
/**
* Returns the module that the namespace is part of.
*/
virtual ModuleDefPtr getModule() = 0;
/**
* Returns the "real module" that the namespace is part of. If the
* namespace is part of an ephemeral module generated for a generic,
* the real module is the module that the generic was defined in.
* This is equivalent to the owner of the module returned by
* getModule() if there is one, and simply the module returned by
* getModule() if it doesn't have an owner.
*/
ModuleDefPtr getRealModule();
/**
* Returns true if the definition is aliased in the namespace.
*/
bool hasAliasFor(VarDef *def) const;
/**
* Add a new definition to the namespace (this may not be used for
* FuncDef's, these must be wrapped in an OverloadDef. See Context
* for an easy way to add FuncDef's)
*/
virtual void addDef(VarDef *def);
/**
* Remove a definition. Intended for use with stubs - "def" must not
* be an OverloadDef.
*/
virtual void removeDef(VarDef *def);
/**
* Adds a definition to the context, but does not make the definition's
* context the context. This is used for importing symbols into a
* module context.
*/
virtual void addAlias(VarDef *def);
virtual OverloadDefPtr addAlias(const std::string &name,
VarDef *def
);
/**
* Adds an alias without special processing if 'def' is an overload.
* This is only safe in a situation where we know that the overload
* can never be extended in a new context, which happens to be the
* case when we're aliasing symbols from .builtin to the root module.
*/
virtual void addUnsafeAlias(const std::string &name, VarDef *def);
/**
* Alias all symbols from the other namespace and all of its ancestor
* namespaces.
*/
void aliasAll(Namespace *other);
/**
* Replace an existing defintion with the new definition.
* This is only used to replace a StubDef with an external function
* definition.
*/
virtual void replaceDef(VarDef *def);
void dump(std::ostream &out, const std::string &prefix);
void dump();
/** Funcs to iterate over the set of definitions. */
/// @{
VarDefMap::iterator beginDefs() { return defs.begin(); }
VarDefMap::iterator endDefs() { return defs.end(); }
VarDefMap::const_iterator beginDefs() const { return defs.begin(); }
VarDefMap::const_iterator endDefs() const { return defs.end(); }
/// @}
/** Funcs to iterate over the definitions in order of declaration. */
/// @{
VarDefVec::iterator beginOrderedDefs() { return ordered.begin(); }
VarDefVec::iterator endOrderedDefs() { return ordered.end(); }
VarDefVec::const_iterator beginOrderedDefs() const {
return ordered.begin();
}
VarDefVec::const_iterator endOrderedDefs() const {
return ordered.end();
}
/// @}
/** XXX Cache ordered vector */
/// @{
VarDefVec::const_iterator beginOrderedForCache() const {
return orderedForCache.begin();
}
VarDefVec::const_iterator endOrderedForCache() const {
return orderedForCache.end();
}
/// @}
};
} // namespace model
#endif
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_Annotation_h_
#define _model_Annotation_h_
#include "spug/RCPtr.h"
#include "VarDef.h"
namespace parser {
class Parser;
class Toker;
}
namespace model {
class Context;
class VarDef;
SPUG_RCPTR(Annotation);
/**
* Annotation is a wrapper around either a variable or a function that makes
* using it easier for the parser.
*/
class Annotation : public VarDef {
public:
Annotation(model::TypeDef *type, const std::string &name);
virtual void invoke(parser::Parser *parser, parser::Toker *toker,
model::Context *context) = 0;
/**
* Create a new annotation from the definition of the correct derived
* type (if 'def' is a function, creates a FuncAnnotation, if it is a
* variable creates a VarAnnotation)
*/
static AnnotationPtr create(VarDef *def);
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "FuncCall.h"
#include "builder/Builder.h"
#include "VarDefImpl.h"
#include "ArgDef.h"
#include "Context.h"
#include "FuncDef.h"
#include "ResultExpr.h"
#include "TypeDef.h"
using namespace model;
FuncCall::FuncCall(FuncDef *funcDef, bool squashVirtual) :
Expr(funcDef->returnType.get()),
func(funcDef),
virtualized(squashVirtual ? false :
(funcDef->flags & FuncDef::virtualized)
) {
if (!funcDef->returnType)
std::cerr << "bad func def: " << funcDef->name << std::endl;
assert(funcDef->returnType);
}
ResultExprPtr FuncCall::emit(Context &context) {
return context.builder.emitFuncCall(context, this);
}
void FuncCall::writeTo(std::ostream &out) const {
if (receiver)
out << "(" << *receiver << ").";
out << "call \"" << func->name << "\"(";
for (ExprVec::const_iterator iter = args.begin();
iter != args.end();
++iter
)
out << **iter << ", ";
out << ")";
}
std::ostream &model::operator <<(std::ostream &out,
const FuncCall::ExprVec &args
) {
for (int i = 0; i < args.size(); i++) {
if (i > 0) out << ", ";
out << args[i]->type->name;
}
return out;
}
| C++ |
// Copyright 2009 Google Inc.
#include "CleanupFrame.h"
#include "builder/Builder.h"
#include "Context.h"
#include "FuncCall.h"
#include "FuncDef.h"
#include "TypeDef.h"
#include "VarDef.h"
#include "VarRef.h"
using namespace model;
void CleanupFrame::addCleanup(VarDef *varDef, Expr *aggregate) {
// we only need to do cleanups for types with a "release" function
FuncDefPtr releaseFunc =
context->lookUpNoArgs("oper release", false, varDef->type.get());
if (releaseFunc) {
VarRefPtr varRef;
if (aggregate)
varRef = context->builder.createFieldRef(aggregate, varDef);
else
varRef = context->builder.createVarRef(varDef);
FuncCallPtr funcCall =
context->builder.createFuncCall(releaseFunc.get());
funcCall->receiver = varRef;
addCleanup(funcCall.get());
}
}
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_ModuleDef_h_
#define _model_ModuleDef_h_
#include <vector>
#include "Namespace.h"
#include "VarDef.h"
namespace model {
SPUG_RCPTR(Context);
SPUG_RCPTR(ModuleDef);
/**
* A module.
* The context of a module is the parent module.
*/
class ModuleDef : public VarDef, public Namespace {
public:
typedef std::vector<std::string> StringVec;
// the parent namespace. This should be the root namespace where
// builtins are stored.
NamespacePtr parent;
// this is true if the module has been completely parsed and the
// close() method has been called.
bool finished;
// true if this module was generated from an extension (as opposed
// to crack source)
bool fromExtension;
// aliased symbols that other modules are allowed to import.
std::map<std::string, bool> exports;
// path to original source code on disk
std::string sourcePath;
ModuleDef(const std::string &name, Namespace *parent);
/**
* Close the module, executing it.
*/
void close(Context &context);
/**
* Call the module destructor - cleans up all global variables.
*/
virtual void callDestructor() = 0;
virtual bool hasInstSlot();
/**
* Set namespace owner, and set our namespace name
*/
virtual void setOwner(Namespace *o) {
owner = o;
canonicalName = o->getNamespaceName()+"."+name;
fullName.clear();
}
/**
* Record a dependency on another module. See
* model::Context::recordDependency() for more info.
* Derived classes should override if it's important.
*/
virtual void recordDependency(ModuleDef *other) {}
/**
* Returns true if the module matches the source file found along the
* given path.
*/
bool matchesSource(const StringVec &libSearchPath);
/**
* Returns true if the module matches the specific source file.
*/
virtual bool matchesSource(const std::string &sourcePath) = 0;
virtual NamespacePtr getParent(unsigned index);
virtual ModuleDefPtr getModule();
/**
* Parse a canonical module name, return it as a vector of name
* components.
*/
static StringVec parseCanonicalName(const std::string &name);
};
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#include "GetRegisterExpr.h"
#include "Context.h"
#include "ResultExpr.h"
using namespace model;
ResultExprPtr GetRegisterExpr::emit(Context &context) {
return context.reg->emit(context);
}
void GetRegisterExpr::writeTo(std::ostream &out) const {
out << "register";
}
bool GetRegisterExpr::isProductive() const {
// like result expressions, register expressions are inherently
// non-productive.
return false;
} | C++ |
// Copyright 2009 Google Inc.
#include "NullConst.h"
#include "builder/Builder.h"
#include "Context.h"
#include "ResultExpr.h"
using namespace model;
using namespace std;
ResultExprPtr NullConst::emit(Context &context) {
return context.builder.emitNull(context, this);
}
ExprPtr NullConst::convert(Context &context, TypeDef *newType) {
return new NullConst(newType);
}
void NullConst::writeTo(ostream &out) const {
out << "null";
}
bool NullConst::isProductive() const {
return false;
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_TypeDef_h
#define _model_TypeDef_h
#include <vector>
#include <map>
#include <spug/RCPtr.h>
#include "ArgDef.h"
#include "VarDef.h"
#include "Namespace.h"
namespace model {
SPUG_RCPTR(Context);
SPUG_RCPTR(Expr);
SPUG_RCPTR(FuncDef);
class Generic;
class Initializers;
SPUG_RCPTR(VarDef);
SPUG_RCPTR(TypeDef);
// a type.
class TypeDef : public VarDef, public Namespace {
public:
class TypeVecObj;
typedef std::vector<TypeDefPtr> TypeVec;
bool isAbstract(FuncDef *func);
bool hasAbstractFuncs(OverloadDef *overload,
std::vector<FuncDefPtr> *abstractFuncs
);
protected:
TypeDef *findSpecialization(TypeVecObj *types);
std::string getSpecializedName(TypeVecObj *types, bool fullName);
virtual void storeDef(VarDef *def);
public:
SPUG_RCPTR(TypeVecObj);
class TypeVecObj : public spug::RCBase,
public std::vector<TypeDefPtr> {
};
// a vector of types that can be used as a key
struct TypeVecObjKey {
TypeVecObjPtr vec;
TypeVecObjKey(TypeVecObj *vec) : vec(vec) {}
bool operator <(const TypeVecObjKey &other) const {
if (vec == other.vec)
return false;
else {
size_t mySize = vec->size(), otherSize = other.vec->size();
for (int i = 0; i < std::max(mySize, otherSize);
++i
) {
if (i >= mySize)
// other is greater
return true;
else if (i >= otherSize)
// this is greater
return false;
TypeDef *myVal = vec->operator [](i).get(),
*otherVal = other.vec->operator [](i).get();
if (myVal < otherVal)
return true;
else if (otherVal < myVal)
return false;
}
return false;
}
}
bool equals(const TypeVecObj *other) const {
return *vec == *other;
}
};
typedef std::map<TypeVecObjKey, TypeDefPtr> SpecializationCache;
// the parent vector.
TypeVec parents;
// defined for a generic type. Stores the cache of all
// specializations for the type.
SpecializationCache *generic;
Generic *genericInfo;
// defined for a generic instantiation
TypeVec genericParms;
// the number of bytes of padding required by the type after the
// instance variables (this exists so we can define extension types,
// whose instances consist entirely of padding with no instance
// variables)
unsigned padding;
// the default initializer expression (XXX I'm not sure that we want
// to keep this, for now it's expedient to be able to do variable
// initialization without the whole "oper new" business)
ExprPtr defaultInitializer;
// if true, the type is a pointer type (points to a structure)
bool pointer;
// if true, the type has a vtable (and is derived from vtable_base)
bool hasVTable;
// if the type is a meta type, "meta" is the type that it is the
// meta-type of.
TypeDef *meta;
// true if the type has been completely defined (so that we can
// determine whether to emit references or placeholders for instance
// variable references and assignments)
bool complete;
// true if the type has been forward declared but has not yet been
// defined.
bool forward;
// if true, the initializers for the type have been emitted and it is
// now illegal to add instance variables.
bool initializersEmitted;
// if true, this is an abstract class (contains abstract methods)
bool abstract;
enum Flags {
noFlags = 0,
abstractClass = 1,
explicitFlags = 256 // these flags were set by an annotation
};
// if true, the user has created an explicit "oper new" for the class,
// so don't generate them for any more of the init methods.
bool gotExplicitOperNew;
TypeDef(TypeDef *metaType, const std::string &name,
bool pointer = false
) :
VarDef(metaType, name),
Namespace(name),
genericInfo(0),
generic(0),
padding(0),
pointer(pointer),
hasVTable(false),
meta(0),
complete(false),
forward(false),
initializersEmitted(false),
abstract(false),
gotExplicitOperNew(false) {
}
~TypeDef() { if (generic) delete generic; }
/** required implementation of Namespace::getModule() */
virtual ModuleDefPtr getModule();
/** required implementation of Namespace::getParent() */
virtual NamespacePtr getParent(unsigned i);
/**
* Overrides VarDef::hasInstSlot() to return false (nested classes
* don't need an instance slot).
*/
virtual bool hasInstSlot();
/**
* Returns true if the function name is the name of a method that is
* implicitly final (non-virtual).
*/
static bool isImplicitFinal(const std::string &name);
/**
* Adds the type and all of its ancestors to the ancestor list. In
* the process, verifies that the type can safely be added to the
* existing set of ancestors. Aborts with an error if verification
* fails.
*
* The current verifications are:
* - that the type is not a primitive class.
* - that neither the type nor any of its ancestors is already in
* 'ancestors' (this check is ignored for the VTableBase class).
*/
void addToAncestors(Context &context, TypeVec &ancestors);
/**
* Returns true if the type is derived from "other."
*/
bool isDerivedFrom(const TypeDef *other) const;
/** Emit a variable definition for the type. */
VarDefPtr emitVarDef(Context &container, const std::string &name,
Expr *initializer
);
/**
* Returns true if "other" satisfies the type - in other words, if
* "other" either equals "this" or is a subclass of "this".
*/
bool matches(const TypeDef &other) const;
/**
* Create a default oper init function with the specified argument
* list. This requires that all base classes have either a default
* constructor or a constructor exactly matching args.
*/
FuncDefPtr createOperInit(Context &classContext, const ArgVec &args);
/**
* Create the default initializer.
*/
FuncDefPtr createDefaultInit(Context &classContext);
/**
* Create the default destructor for the type.
*/
void createDefaultDestructor(Context &classContext);
/**
* Create a "new" function to wrap the specified "init" function.
*/
void createNewFunc(Context &classContext, FuncDef *initFunc);
/**
* Return a function to convert to the specified type, if such a
* function exists.
*/
virtual FuncDefPtr getConverter(Context &context,
const TypeDef &other);
/**
* Create a function to cast to the type (should only be used on a
* type with a vtable)
* @param outerContext this should be the context that the type was
* defined in (it's used to find the module scoped __die()
* function).
* @param throws if true, emit the single argument version of the
* function which throws an exception. Otherwise emit the two
* argument version which returns a default value provided by
* the caller.
*/
void createCast(Context &outerContext, bool throws);
/**
* Returns true if the class has any abstract functions.
* @param abstractFuncs if provided, this is a vector to fill with the
* abstract functions we've discovered.
* @param ancestor (for internal use) if provided, this the ancestor
* to start searching from.
*/
bool gotAbstractFuncs(std::vector<FuncDefPtr> *abstractFuncs = 0,
TypeDef *ancestor = 0
);
/**
* Alias definitions in all of the base meta-types in our meta-type.
* This should be done immediately after setting the base classes.
*/
void aliasBaseMetaTypes();
/**
* Fill in everything that's missing from the class.
*/
void rectify(Context &classContext);
/**
* Returns true if 'type' is a parent.
*/
bool isParent(TypeDef *type);
struct AncestorReference {
unsigned index;
TypeDefPtr ancestor;
};
typedef std::vector<AncestorReference> AncestorPath;
/**
* Finds the path to the specified ancesetor.
* Returns true if the ancestor was found, false if not.
*/
bool getPathToAncestor(const TypeDef &ancestor, AncestorPath &path,
unsigned depth = 0
);
/**
* Emit all of the initializers for the type (base classes and fields)
* and amrk the type as initilalized so we can't go introducing new
* members.
*/
void emitInitializers(Context &context, Initializers *inits);
/**
* Add the destructor cleanups for the type to the cleanup frame for
* the context.
*/
void addDestructorCleanups(Context &context);
/**
* Returns a new specialization for the specified types, creating it
* if necessary.
*/
virtual TypeDef *getSpecialization(Context &context, TypeVecObj *types);
/**
* Set namespace owner, and set our namespace name.
*/
virtual void setOwner(Namespace *o) {
owner = o;
// set the TypeDef namespace canonical name based on owner
canonicalName = (!o->getNamespaceName().empty())?
o->getNamespaceName()+"."+name :
name;
fullName.clear();
}
virtual std::string getDisplayName() const;
virtual bool isConstant();
/**
* Fills 'deps' with the set of dependent classes - dependent classes
* are nested classes that are derived from this class.
* Base class version does nothing, derived classes must implement.
*/
virtual void getDependents(std::vector<TypeDefPtr> &deps);
virtual
void dump(std::ostream &out, const std::string &prefix = "") const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "TypeDef.h"
#include <spug/check.h>
#include <spug/Exception.h>
#include <spug/StringFmt.h>
#include "builder/Builder.h"
#include "parser/Parser.h"
#include "parser/Toker.h"
#include "AllocExpr.h"
#include "AssignExpr.h"
#include "CleanupFrame.h"
#include "ArgDef.h"
#include "Branchpoint.h"
#include "Context.h"
#include "FuncDef.h"
#include "Generic.h"
#include "GlobalNamespace.h"
#include "Initializers.h"
#include "InstVarDef.h"
#include "OverloadDef.h"
#include "NullConst.h"
#include "ResultExpr.h"
#include "VarDef.h"
#include "VarDefImpl.h"
#include "VarRef.h"
using namespace builder;
using namespace std;
using namespace model;
using namespace spug;
using namespace parser;
// returns true if func is non-null and abstract
bool TypeDef::isAbstract(FuncDef *func) {
if (func && (func->flags & FuncDef::abstract)) {
// found one. do a look-up on the function, if there is a
// non-abstract implementation we should get a match that is
// _not_ abstract.
OverloadDefPtr overloads =
OverloadDefPtr::rcast(lookUp(func->name));
assert(overloads);
FuncDefPtr nearest = overloads->getSigMatch(func->args);
if (nearest->flags & FuncDef::abstract)
return true;
}
return false;
}
// if overload contains abstract functions, returns true and adds them to
// abstractFuncs (assuming abstractFuncs is non-null)
bool TypeDef::hasAbstractFuncs(OverloadDef *overload,
vector<FuncDefPtr> *abstractFuncs
) {
bool gotAbstract = false;
for (OverloadDef::FuncList::iterator iter = overload->beginTopFuncs();
iter != overload->endTopFuncs();
++iter
) {
if (isAbstract(iter->get()))
if (abstractFuncs) {
abstractFuncs->push_back(iter->get());
gotAbstract = true;
} else {
return true;
}
}
return gotAbstract;
}
TypeDef *TypeDef::findSpecialization(TypeVecObj *types) {
assert(generic && "find specialization called on non-generic type");
SpecializationCache::iterator match = generic->find(types);
if (match != generic->end() && match->first.equals(types))
return match->second.get();
else
return 0;
}
void TypeDef::storeDef(VarDef *def) {
Namespace::storeDef(def);
if (def->hasInstSlot())
ordered.push_back(def);
}
ModuleDefPtr TypeDef::getModule() {
return owner->getModule();
}
NamespacePtr TypeDef::getParent(unsigned i) {
if (i < parents.size())
return parents[i];
else
return 0;
}
bool TypeDef::hasInstSlot() {
return false;
}
bool TypeDef::isImplicitFinal(const std::string &name) {
return name == "oper init" ||
name == "oper bind" ||
name == "oper release";
}
void TypeDef::addToAncestors(Context &context, TypeVec &ancestors) {
// ignore VTableBase
if (this == context.construct->vtableBaseType)
return;
// make sure this isn't a primitive class (we use the "pointer" attribute
// to make this determination)
if (!pointer)
context.error(SPUG_FSTR("You may not inherit from " <<
getDisplayName() <<
" because it's a primitive class."
)
);
// store the current endpoint so we don't bother checking against our own
// ancestors.
size_t initAncSize = ancestors.size();
// if this is the object class, make sure that it's the first ancestor.
if (initAncSize && this == context.construct->objectType)
context.error("If you directly or indirectly inherit from Object, "
"Object (or its derivative) must come first in the "
"ancestor list.");
for (TypeVec::const_iterator iter = parents.begin();
iter != parents.end();
++iter
)
(*iter)->addToAncestors(context, ancestors);
// make sure that we're not already in the ancestor list
for (size_t i = 0; i < initAncSize; ++i)
if (ancestors[i] == this)
context.error(SPUG_FSTR("Class " << getDisplayName() <<
" is already an ancestor."
)
);
// add this to the ancestors.
ancestors.push_back(this);
}
bool TypeDef::isDerivedFrom(const TypeDef *other) const {
if (this == other)
return true;
for (TypeVec::const_iterator iter = parents.begin();
iter != parents.end();
++iter
)
if ((*iter)->isDerivedFrom(other))
return true;
return false;
}
VarDefPtr TypeDef::emitVarDef(Context &container, const std::string &name,
Expr *initializer
) {
return container.builder.emitVarDef(container, this, name, initializer);
}
bool TypeDef::matches(const TypeDef &other) const {
if (&other == this)
return true;
// try the parents
for (TypeVec::const_iterator iter = other.parents.begin();
iter != other.parents.end();
++iter
)
if (matches(**iter))
return true;
return false;
}
FuncDefPtr TypeDef::createOperInit(Context &classContext,
const ArgVec &args
) {
assert(classContext.ns.get() == this); // needed for final addDef()
ContextPtr funcContext = classContext.createSubContext(Context::local);
funcContext->toplevel = true;
// create the "this" variable
ArgDefPtr thisDef = classContext.builder.createArgDef(this, "this");
funcContext->addDef(thisDef.get());
VarRefPtr thisRef = new VarRef(thisDef.get());
TypeDef *voidType = classContext.construct->voidType.get();
FuncDefPtr newFunc = classContext.builder.emitBeginFunc(*funcContext,
FuncDef::method,
"oper init",
voidType,
args,
0
);
// do initialization for the base classes.
for (TypeVec::iterator ibase = parents.begin(); ibase != parents.end();
++ibase
) {
// if the base class contains no constructors at all, either it's a
// special class or it has no need for constructors, so ignore it.
OverloadDefPtr overloads = (*ibase)->lookUp("oper init");
if (!overloads)
continue;
// look for a matching constructor
bool useDefaultCons = false;
FuncDefPtr baseInit = overloads->getSigMatch(args, true);
if (!baseInit || baseInit->getOwner() != ibase->get()) {
// we must get a default initializer and it must be specific to the
// base class (not inherited from an ancestor of the base class)
useDefaultCons = true;
baseInit = overloads->getNoArgMatch(false);
if (!baseInit || baseInit->getOwner() != ibase->get())
classContext.error(SPUG_FSTR("Cannot create a default "
"constructor because base "
"class " <<
(*ibase)->name <<
" has no default constructor."
)
);
}
FuncCallPtr funcCall =
classContext.builder.createFuncCall(baseInit.get());
funcCall->receiver = thisRef;
// construct an argument list if we're not using the default arguments
if (!useDefaultCons && args.size()) {
for (int i = 0; i < args.size(); ++i)
funcCall->args.push_back(
funcContext->builder.createVarRef(args[i].get())
);
}
funcCall->emit(*funcContext);
}
// generate constructors for all of the instance variables in the order
// that they were declared.
for (VarDefVec::iterator iter = beginOrderedDefs();
iter != endOrderedDefs();
++iter
) {
InstVarDef *ivar = InstVarDefPtr::arcast(*iter);
// when creating a default constructor, everything has to have an
// initializer.
// XXX make this a parser error
if (!ivar->initializer)
classContext.error(SPUG_FSTR("no initializer for variable " <<
ivar->name <<
" while creating default "
"constructor."
)
);
AssignExprPtr assign = new AssignExpr(thisRef.get(),
ivar,
ivar->initializer.get()
);
classContext.builder.emitFieldAssign(*funcContext, thisRef.get(),
assign.get()
);
}
classContext.builder.emitReturn(*funcContext, 0);
classContext.builder.emitEndFunc(*funcContext, newFunc.get());
classContext.addDef(newFunc.get());
return newFunc;
}
FuncDefPtr TypeDef::createDefaultInit(Context &classContext) {
ArgVec args(0);
return createOperInit(classContext, args);
}
void TypeDef::createDefaultDestructor(Context &classContext) {
assert(classContext.ns.get() == this); // needed for final addDef()
ContextPtr funcContext = classContext.createSubContext(Context::local);
funcContext->toplevel = true;
// create the "this" variable
ArgDefPtr thisDef = classContext.builder.createArgDef(this, "this");
funcContext->addDef(thisDef.get());
FuncDef::Flags flags =
FuncDef::method |
(hasVTable ? FuncDef::virtualized : FuncDef::noFlags);
// check for an override
FuncDefPtr override = classContext.lookUpNoArgs("oper del", true, this);
ArgVec args(0);
TypeDef *voidType = classContext.construct->voidType.get();
FuncDefPtr delFunc = classContext.builder.emitBeginFunc(*funcContext,
flags,
"oper del",
voidType,
args,
override.get()
);
// all we have to do is add the destructor cleanups
addDestructorCleanups(*funcContext);
// ... and close off the function
classContext.builder.emitReturn(*funcContext, 0);
classContext.builder.emitEndFunc(*funcContext, delFunc.get());
classContext.addDef(delFunc.get());
}
void TypeDef::createNewFunc(Context &classContext, FuncDef *initFunc) {
ContextPtr funcContext = classContext.createSubContext(Context::local);
funcContext->toplevel = true;
funcContext->returnType = this;
// copy the original arg list
ArgVec args;
for (ArgVec::iterator iter = initFunc->args.begin();
iter != initFunc->args.end();
++iter
) {
ArgDefPtr argDef =
classContext.builder.createArgDef((*iter)->type.get(),
(*iter)->name
);
args.push_back(argDef);
funcContext->addDef(argDef.get());
}
FuncDefPtr newFunc = classContext.builder.emitBeginFunc(*funcContext,
FuncDef::noFlags,
"oper new",
this,
args,
0
);
// create "Type this = alloc(Type);"
ExprPtr allocExpr = new AllocExpr(this);
VarDefPtr thisVar = classContext.builder.emitVarDef(*funcContext, this,
"this",
allocExpr.get(),
false
);
VarRefPtr thisRef = new VarRef(thisVar.get());
// initialize all vtable_base pointers. XXX hack. Replace this with code
// in vtable_base.oper init() once we get proper constructor composition
if (hasVTable) {
thisRef->emit(*funcContext);
classContext.builder.emitVTableInit(*funcContext, this);
}
// create "this.init(*args);"
FuncCallPtr initFuncCall = new FuncCall(initFunc);
FuncCall::ExprVec initArgs(args.size());
for (ArgVec::iterator iter = args.begin(); iter != args.end();
++iter
)
initFuncCall->args.push_back(new VarRef(iter->get()));
initFuncCall->receiver = thisRef;
initFuncCall->emit(*funcContext);
// return the resulting object and close the new function
classContext.builder.emitReturn(*funcContext, thisRef.get());
classContext.builder.emitEndFunc(*funcContext, newFunc.get());
// register it in the class
classContext.addDef(newFunc.get());
}
void TypeDef::createCast(Context &outer, bool throws) {
assert(hasVTable && "Attempt to createCast() on a non-virtual class");
ContextPtr funcCtx = outer.createSubContext(Context::local);
funcCtx->toplevel = true;
funcCtx->returnType = this;
ArgVec args;
args.reserve(2);
args.push_back(
outer.builder.createArgDef(outer.construct->vtableBaseType.get(),
"val"
)
);
// if this isn't the throwing variety, add a "defaultValue" arg.
if (!throws)
args.push_back(
outer.builder.createArgDef(this, "defaultValue")
);
FuncDefPtr castFunc = outer.builder.emitBeginFunc(*funcCtx,
FuncDef::noFlags,
"cast",
this,
args,
0
);
// function body is:
// if (val.class.isSubclass(ThisClass);
// return ThisClass.unsafeCast(val);
// else
// __CrackBadCast(val.class, ThisClass);
// val.class
VarRefPtr valRef = funcCtx->builder.createVarRef(args[0].get());
FuncDefPtr f = funcCtx->lookUpNoArgs("oper class", false);
assert(f && "oper class missing");
// XXX this was trace code that mysteriously seg-faults: since I think there
// might be some memory corruption happening, I'm leaving this until I can
// investigate.
// string s = f->getReceiverType()->name;
// std::cerr << "Got oper class for " << s << endl;
FuncCallPtr call = funcCtx->builder.createFuncCall(f.get());
call->receiver = valRef;
ExprPtr valClass = call;
valClass = valClass->emit(*funcCtx);
// $.isSubclass(ThisClass)
FuncCall::ExprVec isSubclassArgs(1);
isSubclassArgs[0] = funcCtx->builder.createVarRef(this);
f = funcCtx->lookUp("isSubclass", isSubclassArgs, type.get());
assert(f && "isSubclass missing");
call = funcCtx->builder.createFuncCall(f.get());
call->args = isSubclassArgs;
call->receiver = valClass;
// if ($)
BranchpointPtr branchpoint = funcCtx->builder.emitIf(*funcCtx, call.get());
// return ThisClass.unsafeCast(val);
FuncCall::ExprVec unsafeCastArgs(1);
unsafeCastArgs[0] = valRef;
f = funcCtx->lookUp("unsafeCast", unsafeCastArgs, type.get());
assert(f && "unsafeCast missing");
call = funcCtx->builder.createFuncCall(f.get());
call->args = unsafeCastArgs;
funcCtx->builder.emitReturn(*funcCtx, call.get());
// else
branchpoint = funcCtx->builder.emitElse(*funcCtx, branchpoint.get(), true);
if (throws) {
// __CrackBadCast(val.class, ThisClass);
FuncCall::ExprVec badCastArgs(2);
badCastArgs[0] = valClass;
badCastArgs[1] = funcCtx->builder.createVarRef(this);
f = outer.getParent()->lookUp("__CrackBadCast", badCastArgs);
assert(f && "__CrackBadCast missing");
call = funcCtx->builder.createFuncCall(f.get());
call->args = badCastArgs;
funcCtx->createCleanupFrame();
call->emit(*funcCtx)->handleTransient(*funcCtx);
funcCtx->closeCleanupFrame();
// need to "return null" to provide a terminator.
TypeDef *vp = outer.construct->voidptrType.get();
ExprPtr nullVal = (new NullConst(vp))->convert(*funcCtx, this);
funcCtx->builder.emitReturn(*funcCtx, nullVal.get());
} else {
// return defaultVal;
VarRefPtr defaultValRef = funcCtx->builder.createVarRef(args[1].get());
funcCtx->builder.emitReturn(*funcCtx, defaultValRef.get());
}
// end of story.
funcCtx->builder.emitEndIf(*funcCtx, branchpoint.get(), true);
funcCtx->builder.emitEndFunc(*funcCtx, castFunc.get());
// add the cast function to the meta-class
outer.addDef(castFunc.get(), type.get());
}
bool TypeDef::gotAbstractFuncs(vector<FuncDefPtr> *abstractFuncs,
TypeDef *ancestor
) {
bool gotAbstract = false;
if (!ancestor)
ancestor = this;
// iterate over the definitions, locate all abstract functions
for (VarDefMap::iterator iter = ancestor->beginDefs();
iter != ancestor->endDefs();
++iter
) {
OverloadDef *ovld = OverloadDefPtr::rcast(iter->second);
if (ovld && hasAbstractFuncs(ovld, abstractFuncs)) {
if (abstractFuncs)
gotAbstract = true;
else
return true;
}
}
// recurse through all of the parents
TypeDefPtr parent;
for (int i = 0; parent = ancestor->getParent(i++);)
if (gotAbstractFuncs(abstractFuncs, parent.get()))
if (abstractFuncs)
gotAbstract = true;
else
return true;
return gotAbstract;
}
void TypeDef::aliasBaseMetaTypes() {
for (TypeVec::iterator base = parents.begin();
base != parents.end();
++base
) {
TypeDef *meta = (*base)->type.get();
assert(meta != base->get());
for (VarDefMap::iterator var = meta->beginDefs();
var != meta->endDefs();
++var
) {
// add all overloads that we haven't already defined.
// XXX this check is extremely lame. First of all, we should be
// separating namespace qualification from attribute/method access
// and we should probably do so explicitly. Secondly, if we were
// going to continue in the current direction, what we need here
// is to do our checking at the signature level for each function,
// and allow Parser's addDef() to override existing values.
if (OverloadDefPtr::rcast(var->second) &&
!type->lookUp(var->first) &&
var->first != "cast")
type->addAlias(var->second.get());
}
}
}
void TypeDef::rectify(Context &classContext) {
// if this is an abstract class, make sure we have abstract methods. If
// it is not, make sure we don't have abstract methods.
if (abstract && !gotAbstractFuncs()) {
classContext.warn(SPUG_FSTR("Abstract class " << name <<
" has no abstract functions."
)
);
} else if (!abstract) {
vector<FuncDefPtr> funcs;
if (gotAbstractFuncs(&funcs)) {
ostringstream tmp;
tmp << "Non-abstract class " << name <<
" has abstract methods:\n";
for (int i = 0; i < funcs.size(); ++i)
tmp << " " << *funcs[i] << '\n';
classContext.error(tmp.str());
}
}
// if there are no init functions specific to this class, create a
// default constructor and possibly wrap it in a new function.
if (!lookUp("oper init", false)) {
FuncDefPtr initFunc = createDefaultInit(classContext);
if (!abstract)
createNewFunc(classContext, initFunc.get());
}
// if the class doesn't already define a delete operator specific to the
// class, generate one.
FuncDefPtr operDel = classContext.lookUpNoArgs("oper del");
if (!operDel || operDel->getOwner() != this)
createDefaultDestructor(classContext);
}
bool TypeDef::isParent(TypeDef *type) {
for (TypeVec::iterator iter = parents.begin();
iter != parents.end();
++iter
)
if (type == iter->get())
return true;
return false;
}
FuncDefPtr TypeDef::getConverter(Context &context, const TypeDef &other) {
return context.lookUpNoArgs("oper to " + other.getFullName(), true, this);
}
bool TypeDef::getPathToAncestor(const TypeDef &ancestor,
TypeDef::AncestorPath &path,
unsigned depth
) {
if (this == &ancestor) {
path.resize(depth);
return true;
}
int i = 0;
for (TypeVec::iterator iter = parents.begin();
iter != parents.end();
++iter, ++i
) {
TypeDef *base = iter->get();
if (base->getPathToAncestor(ancestor, path, depth + 1)) {
path[depth].index = i;
path[depth].ancestor = base;
return true;
}
}
return false;
}
void TypeDef::emitInitializers(Context &context, Initializers *inits) {
VarDefPtr thisDef = context.ns->lookUp("this");
assert(thisDef &&
"trying to emit initializers in a context with no 'this'");
VarRefPtr thisRef = new VarRef(thisDef.get());
// do initialization for the base classes.
for (TypeVec::iterator ibase = parents.begin(); ibase != parents.end();
++ibase
) {
TypeDef *base = ibase->get();
// see if there's a constructor for the base class in our list of
// initializers.
FuncCallPtr initCall = inits->getBaseInitializer(base);
if (initCall) {
initCall->emit(context);
continue;
}
// if the base class contains no constructors at all, either it's a
// special class or it has no need for constructors, so ignore it.
OverloadDefPtr overloads = base->lookUp("oper init");
if (!overloads)
continue;
// we must get a default initializer and it must be specific to the
// base class (not inherited from an ancestor of the base class)
ArgVec args;
FuncDefPtr baseInit = overloads->getSigMatch(args);
if (!baseInit || baseInit->getOwner() != base)
context.error(SPUG_FSTR("Cannot initialize base classes "
"because base class " <<
base->name <<
" has no default constructor."
)
);
FuncCallPtr funcCall = context.builder.createFuncCall(baseInit.get());
funcCall->receiver = thisRef;
funcCall->emit(context);
}
// generate constructors for all of the instance variables
for (VarDefVec::iterator iter = beginOrderedDefs();
iter != endOrderedDefs();
++iter
) {
InstVarDef *ivar = InstVarDefPtr::arcast(*iter);
// see if the user has supplied an initializer, use it if so.
ExprPtr initializer = inits->getFieldInitializer(ivar);
if (!initializer)
initializer = ivar->initializer;
// when creating a default constructor, everything has to have an
// initializer.
// XXX make this a parser error
if (!initializer)
context.error(SPUG_FSTR("no initializer for variable " <<
ivar->name <<
" while creating default "
"constructor."
)
);
SPUG_CHECK(initializer->type->isDerivedFrom(ivar->type.get()),
"initializer for " << ivar->name << " should be of type " <<
ivar->type->getDisplayName() <<
" but is of incompatible type " <<
initializer->type->getDisplayName()
);
AssignExprPtr assign = new AssignExpr(thisRef.get(),
ivar,
initializer.get()
);
context.builder.emitFieldAssign(context, thisRef.get(),
assign.get()
);
}
initializersEmitted = true;
}
void TypeDef::addDestructorCleanups(Context &context) {
VarRefPtr thisRef = new VarRef(context.ns->lookUp("this").get());
// first add the cleanups for the base classes, in order defined, then the
// cleanups for the derived classes. Cleanups are applied in the reverse
// order that they are added, so this will result in the expected
// destruction order of instance variables followed by base classes.
// generate calls to the destructors for all of the base classes.
for (TypeVec::iterator ibase = parents.begin();
ibase != parents.end();
++ibase
) {
TypeDef *base = ibase->get();
// check for a delete operator (the primitive base classes don't have
// them and don't need cleanup)
FuncDefPtr operDel = context.lookUpNoArgs("oper del", true, base);
if (!operDel)
continue;
// create a cleanup function and don't call it through the vtable.
FuncCallPtr funcCall =
context.builder.createFuncCall(operDel.get(), true);
funcCall->receiver = thisRef.get();
context.cleanupFrame->addCleanup(funcCall.get());
}
// generate destructors for all of the instance variables in order of
// definition (cleanups run in the reverse order that they were added,
// which is exactly what we want).
for (VarDefVec::iterator iter = beginOrderedDefs();
iter != endOrderedDefs();
++iter
)
context.cleanupFrame->addCleanup(iter->get(), thisRef.get());
initializersEmitted = true;
}
string TypeDef::getSpecializedName(TypeVecObj *types, bool fullName) {
// construct the module name from the class name plus type parameters
ostringstream tmp;
tmp << (fullName ? getFullName() : name) << '[';
int last = types->size()-1;
for (int i = 0; i <= last; ++i) {
tmp << (*types)[i]->getFullName();
if (i != last)
tmp << ',';
}
tmp << ']';
return tmp.str();
}
TypeDef *TypeDef::getSpecialization(Context &context,
TypeDef::TypeVecObj *types
) {
assert(genericInfo);
// check the cache
TypeDef *result = findSpecialization(types);
if (result) {
// record a dependency on the owner's module and return the result.
context.recordDependency(result->getOwner()->getModule().get());
return result;
}
// construct the module name from the class name plus type parameters
string moduleName = getSpecializedName(types, true);
string newTypeName = getSpecializedName(types, false);
// the name that the specialization will be stored as in the
// specialization module. This varies depending on whether we are
// building the specialization or loading from the precompiled module cache.
string nameInModule;
// check the precompiled module cache
ModuleDefPtr module = context.construct->loadFromCache(moduleName);
if (!module) {
// make sure we've got the right number of arguments
if (types->size() != genericInfo->parms.size())
context.error(SPUG_FSTR("incorrect number of arguments for "
"generic " << moduleName <<
". Expected " <<
genericInfo->parms.size() << " got " <<
types->size()
)
);
// create an ephemeral module for the new class
Context *rootContext = context.construct->rootContext.get();
NamespacePtr compileNS =
new GlobalNamespace(rootContext->compileNS.get(),
moduleName
);
BuilderPtr moduleBuilder =
context.construct->rootBuilder->createChildBuilder();
ContextPtr modContext =
new Context(*moduleBuilder, Context::module, rootContext,
new GlobalNamespace(rootContext->ns.get(),
moduleName
)
);
modContext->toplevel = true;
// create the new module with the current module as the owner. Use
// the newTypeName instead of moduleName, the name will be
// canonicalized by its owner.
ModuleDef *currentModule =
ModuleDefPtr::rcast(context.getModuleContext()->ns);
module = modContext->createModule(newTypeName, "", currentModule);
// XXX this is confusing: there's a "owner" that's part of some kinds of
// ModuleDef that's different from VarDef::owner - we set VarDef::owner
// here so that we can accept protected variables from the original
// module's context
ModuleDefPtr owner = genericInfo->ns->getRealModule();
module->setOwner(owner.get());
// alias all global symbols in the original module and original compile
// namespace.
modContext->ns->aliasAll(genericInfo->ns.get());
modContext->compileNS->aliasAll(genericInfo->compileNS.get());
// alias the template arguments to their parameter names
for (int i = 0; i < types->size(); ++i)
modContext->ns->addAlias(genericInfo->parms[i]->name,
(*types)[i].get()
);
istringstream fakeInput;
Toker toker(fakeInput, moduleName.c_str());
genericInfo->replay(toker);
toker.putBack(Token(Token::ident, name, Location()));
toker.putBack(Token(Token::classKw, "class", Location()));
if (abstract)
modContext->nextClassFlags =
static_cast<Flags>(model::TypeDef::explicitFlags |
model::TypeDef::abstractClass
);
Location instantiationLoc = context.getLocation();
if (instantiationLoc)
modContext->pushErrorContext(SPUG_FSTR("in generic instantiation "
"at " << instantiationLoc
)
);
else
// XXX I think we should never get here now that we're
// materializing generic modules.
modContext->pushErrorContext(SPUG_FSTR("In generic instantiation "
"from compiled module "
"(this should never "
"happen!)"
)
);
Parser parser(toker, modContext.get());
parser.parse();
// use the source path of the owner
module->sourcePath = owner->sourcePath;
module->close(*modContext);
modContext->popErrorContext();
// store the module in the in-memory cache
context.construct->registerModule(module.get());
nameInModule = name;
} else {
nameInModule = newTypeName;
}
//
// extract the type out of the newly created module and store it in the
// specializations cache
result = TypeDefPtr::rcast(module->lookUp(name));
result->genericParms = *types;
assert(result);
(*generic)[types] = result;
// XXX this is recording dependencies on ephemeral modules and making them
// show up in import metadata nodes in cached files. commenting this fixes
// it. do we need this?
// record a dependency on the owner's module
//context.recordDependency(result->getOwner()->getModule().get());
return result;
}
string TypeDef::getDisplayName() const {
if (genericParms.size()) {
ostringstream tmp;
tmp << VarDef::getDisplayName() << '(';
bool first = false;
for (TypeVec::const_iterator iter = genericParms.begin();
iter != genericParms.end();
++iter
) {
tmp << (*iter)->getDisplayName();
if (first)
first = false;
else
tmp << ", ";
}
} else {
return VarDef::getDisplayName();
}
}
bool TypeDef::isConstant() {
return true;
}
void TypeDef::getDependents(std::vector<TypeDefPtr> &deps) {}
void TypeDef::dump(ostream &out, const string &prefix) const {
out << prefix << "class " << getFullName() << " {" << endl;
string childPrefix = prefix + " ";
for (TypeVec::const_iterator baseIter = parents.begin();
baseIter != parents.end();
++baseIter
) {
out << childPrefix << "parent:" << endl;
(*baseIter)->dump(out, childPrefix+" ");
}
for (VarDefMap::const_iterator iter = beginDefs(); iter != endDefs();
++iter
)
iter->second->dump(out, childPrefix);
out << prefix << "}" << endl;
}
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_FuncAnnotation_h_
#define _model_FuncAnnotation_h_
#include "Annotation.h"
namespace parser {
class Parser;
class Toker;
}
namespace model {
SPUG_RCPTR(FuncAnnotation);
SPUG_RCPTR(FuncDef);
/** An annotation implemented as a function. */
class FuncAnnotation : public Annotation {
private:
FuncDefPtr func;
public:
FuncAnnotation(FuncDef *func);
virtual void invoke(parser::Parser *parser, parser::Toker *toker,
Context *context
);
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "IntConst.h"
#define __STDC_LIMIT_MACROS 1
#include "stdint.h"
#include "builder/Builder.h"
#include "parser/ParseError.h"
#include "VarDefImpl.h"
#include "Context.h"
#include "ResultExpr.h"
#include "TypeDef.h"
#include "FloatConst.h"
using namespace model;
using namespace parser;
IntConst::IntConst(TypeDef *type, int64_t val0) :
Expr(type),
val(),
reqUnsigned(false),
uneg(false) {
val.sval = val0;
}
IntConst::IntConst(TypeDef *type, uint64_t val0) :
Expr(type),
val(),
reqUnsigned(val0 > INT64_MAX),
uneg(false) {
val.uval = val0;
}
ResultExprPtr IntConst::emit(Context &context) {
return context.builder.emitIntConst(context, this);
}
ExprPtr IntConst::convert(Context &context, TypeDef *newType) {
if (newType == this->type)
return this;
if (newType == context.construct->int64Type ||
newType == context.construct->intType &&
context.construct->intSize == 64 ||
newType == context.construct->intzType &&
context.construct->intzSize == 64
) {
if (reqUnsigned)
return 0;
} else if (newType == context.construct->uint64Type ||
newType == context.construct->uintType &&
context.construct->intSize == 64
) {
if (!(reqUnsigned || uneg) && val.sval < 0)
return 0;
// since we can't currently give these errors, at least record
// them in the comments.
// context.error = "Negative constant can not be converted to "
// "uint64"
} else if (newType == context.construct->int32Type ||
newType == context.construct->intType ||
newType == context.construct->intzType
) {
if (reqUnsigned ||
val.sval > static_cast<int64_t>(INT32_MAX) ||
val.sval < static_cast<int64_t>(INT32_MIN))
return 0;
// context.error = "Constant out of range of int32"
} else if (newType == context.construct->int16Type) {
if (reqUnsigned ||
val.sval > static_cast<int64_t>(INT16_MAX) ||
val.sval < static_cast<int64_t>(INT16_MIN))
return 0;
// context.error = "Constant out of range of int16"
} else if (newType == context.construct->float32Type ||
newType == context.construct->float64Type ||
newType == context.construct->floatType
) {
// XXX range check?
return context.builder.createFloatConst(context,
(double)val.sval,
newType);
} else if (newType == context.construct->uint32Type ||
newType == context.construct->uintType ||
newType == context.construct->uintzType
) {
if ((uneg && (val.sval < -static_cast<uint64_t>(UINT32_MAX + 1) ||
val.sval >= 0
)
) ||
(!uneg && val.uval > static_cast<uint64_t>(UINT32_MAX))
)
return 0;
// context.error = "Constant out of range of uint32"
} else if (newType == context.construct->uint16Type) {
if ((uneg && (val.sval < -static_cast<uint64_t>(UINT16_MAX + 1) ||
val.sval >= 0
)
) ||
(!uneg && val.uval > static_cast<uint64_t>(UINT16_MAX))
)
return 0;
// context.error = "Constant out of range of uint16"
} else if (newType == context.construct->byteType) {
// to convert to a byte either
// 1) we're uneg and in -255 .. -1
// 2) we're not uneg and in 0 .. 255
if ((uneg && (val.sval < -(UINT8_MAX + 1) || val.sval >= 0)) ||
(!uneg && val.uval > UINT8_MAX)
) {
return 0;
// context.error = "Constant out of range of byte"
}
// check for the PDNTs, which are always safe to convert to.
} else if (!(newType == context.construct->intType ||
newType == context.construct->uintType ||
newType == context.construct->intzType ||
newType == context.construct->uintzType
)
) {
// delegate all other conversions to the type
return Expr::convert(context, newType);
}
if (reqUnsigned)
return context.builder.createUIntConst(context, val.uval, newType);
else
return context.builder.createIntConst(context, val.sval, newType);
}
void IntConst::writeTo(std::ostream &out) const {
out << val.sval;
}
bool IntConst::isAdaptive() const {
return true;
}
IntConstPtr IntConst::create(int64_t v) { return new IntConst(type.get(), v); }
IntConstPtr IntConst::create(uint64_t v) { return new IntConst(type.get(), v); }
// for selecting the default type of a constant
TypeDef *IntConst::selectType(Context &context, int64_t val) {
// note, due to the way the parser processes large unsigned ints,
// this shouldn't be called if val > INT64_MAX, i.e. when it requires
// unsigned int 64
if (val > INT32_MAX || val < INT32_MIN)
return context.construct->int64Type.get();
else return context.construct->intType.get();
}
#define HIBIT(c) (c)->val.sval & 0x8000000000000000 ? true : false
// folding for bitwise operations (use the operation to determine uneg)
#define FOLDB(name, sym, signed) \
ExprPtr IntConst::fold##name(Expr *other) { \
IntConstPtr o = IntConstPtr::cast(other); \
if (o) { \
bool newUneg = uneg sym o->uneg; \
o = create(val.signed##val sym o->val.signed##val); \
o->uneg = newUneg; \
o->reqUnsigned = HIBIT(o); \
return o; \
} else { \
return 0; \
} \
}
// folding for arithmetic operations (result is never uneg and never "req
// unsigned" - just to keep things simple)
#define FOLDA(name, sym, signed) \
ExprPtr IntConst::fold##name(Expr *other) { \
IntConstPtr o = IntConstPtr::cast(other); \
if (o) { \
o = create(val.signed##val sym o->val.signed##val); \
return o; \
} else { \
return 0; \
} \
}
// folding for arithmetic shift operations (result uneg is left-operand uneg)
#define FOLDL(name, sym, signed) \
ExprPtr IntConst::fold##name(Expr *other) { \
IntConstPtr o = IntConstPtr::cast(other); \
if (o) { \
o = create(val.signed##val sym o->val.signed##val); \
o->uneg = uneg; \
o->reqUnsigned = HIBIT(o) != uneg; \
return o; \
} else { \
return 0; \
} \
}
FOLDA(Add, +, s)
FOLDA(Sub, -, s)
FOLDA(Mul, *, s)
FOLDA(SDiv, /, s)
FOLDA(UDiv, /, u)
FOLDA(SRem, %, s)
FOLDA(URem, %, u)
FOLDB(Or, |, u)
FOLDB(And, &, u)
FOLDB(Xor, ^, u)
ExprPtr IntConst::foldNeg() {
IntConstPtr result = create(-val.sval);
result->uneg = false;
return result;
}
ExprPtr IntConst::foldBitNot() {
IntConstPtr result = create(~val.sval);
result->uneg = !uneg;
result->reqUnsigned = reqUnsigned;
return result;
}
// the shift operators are unique WRT their treatement of uneg and reqUnsigned
ExprPtr IntConst::foldAShr(Expr *other) {
IntConstPtr o = IntConstPtr::cast(other);
if (o) {
// convert the shift to a logical shift if the constant must be an
// unsigned
o = reqUnsigned ? create(val.uval >> o->val.sval) :
create(val.sval >> o->val.sval);
o->uneg = uneg;
// shift right is easy: unsigned is never required.
o->reqUnsigned = false;
return o;
} else {
return 0;
}
}
ExprPtr IntConst::foldLShr(Expr *other) {
IntConstPtr o = IntConstPtr::cast(other);
if (o) {
o = create(val.uval >> o->val.sval);
o->uneg = uneg;
// shift right is easy: unsigned is never required.
o->reqUnsigned = false;
return o;
} else {
return 0;
}
}
#define HISET 0x8000000000000000LL
ExprPtr IntConst::foldShl(Expr *other) {
IntConstPtr o = IntConstPtr::cast(other);
if (o) {
o = create(val.sval << o->val.sval);
o->uneg = uneg;
// a left-shift requires negative if any of the bits being shifted
// away are not of the same polarity of the sign.
bool negative = uneg || (reqUnsigned && HIBIT(this));
o->reqUnsigned = negative ? (HISET >> (o->val.sval + 1)) & ~val.uval :
(HISET >> (o->val.sval + 1)) & val.uval;
return o;
} else {
return 0;
}
}
| C++ |
// Copyright 2010 Google Inc.
#include "ModuleDef.h"
#include "builder/Builder.h"
#include "Context.h"
using namespace std;
using namespace model;
ModuleDef::ModuleDef(const std::string &name, Namespace *parent) :
VarDef(0, name),
Namespace(name),
parent(parent),
finished(false),
fromExtension(false) {
}
bool ModuleDef::hasInstSlot() {
return false;
}
bool ModuleDef::matchesSource(const StringVec &libSearchPath) {
int i;
string fullSourcePath;
for (i = 0; i < libSearchPath.size(); ++i) {
fullSourcePath = libSearchPath[i] + "/" + sourcePath;
if (Construct::isFile(fullSourcePath))
break;
}
// if we didn't find the source file, assume the module is up-to-date
// (this will allow us to submit applications as a set of cache files).
if (i == libSearchPath.size())
return true;
return matchesSource(fullSourcePath);
}
void ModuleDef::close(Context &context) {
context.builder.closeModule(context, this);
}
NamespacePtr ModuleDef::getParent(unsigned index) {
return index ? NamespacePtr(0) : parent;
}
ModuleDefPtr ModuleDef::getModule() {
return this;
}
ModuleDef::StringVec ModuleDef::parseCanonicalName(const std::string &name) {
StringVec result;
// track the level of bracket nesting, we only split "outer" components.
int nested = 0;
int last = 0;
int i;
for (i = 0; i < name.size(); ++i) {
if (!nested) {
switch (name[i]) {
case '.':
result.push_back(name.substr(last, i - last));
last = i + 1;
break;
case '[':
++nested;
break;
case ']':
std::cerr << "Invalid canonical name: [" << name << "]" <<
std::endl;
assert(false);
break;
}
} else {
switch (name[i]) {
case '[':
++nested;
break;
case ']':
--nested;
break;
}
}
}
// add the last segment
result.push_back(name.substr(last, i - last));
return result;
} | C++ |
// copyright 2012 Google Inc.
#ifndef _model_Serializer_h_
#define _model_Serializer_h_
#include <map>
#include <string>
namespace model {
class Serializer {
private:
std::ostream &dst;
// mapping from a pointer to the object id associated with that
// pointer. This is part of the mechanism that allows us to serialize
// an object that is used in multiple locations only the first time it
// is used.
typedef std::map<void *, int> ObjMap;
ObjMap objMap;
int lastId;
public:
Serializer(std::ostream &dst) : dst(dst), lastId(0) {}
/** Serialize an integer. */
void write(unsigned int val);
/** Serialize byte data (writes the length followed by the bytes) */
void write(size_t length, const void *data);
/** Convenience method for writing strings. */
void write(const std::string &str) {
write(str.size(), str.data());
}
/**
* If we have "object" before, serialize its id with the "definition"
* flag set to false and return false. Otherwise serialize a new
* identifier with a definition flag set to true and return true,
* indicating that the caller should serialize the state of the object.
*/
bool writeObject(void *object);
};
}
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_Branchpoint_h_
#define _model_Branchpoint_h_
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
SPUG_RCPTR(Branchpoint);
/**
* An opaque datastructure for storing the location of a branchpoint that is
* likely to need to be fixed up by the builder.
*/
class Branchpoint : public spug::RCBase {
public:
Context *context;
Branchpoint(Context *context) : context(context) {}
Branchpoint() : context(0) {}
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_FuncCall_h_
#define _model_FuncCall_h_
#include <string>
#include <vector>
#include "Expr.h"
namespace model {
SPUG_RCPTR(FuncDef);
SPUG_RCPTR(FuncCall);
class FuncCall : public Expr {
public:
FuncDefPtr func;
typedef std::vector<ExprPtr> ExprVec;
ExprVec args;
// if FuncCall is a method, this is the receiver (the "this"),
// otherwise it will be null
ExprPtr receiver;
// if true, the function call is virtual (func->flags must include
// "virtualized" in this case)
bool virtualized;
/**
* @param squashVirtual If true, call a virtualized function
* directly, without the use of the vtable (causes virtualized to be
* set to false, regardless of whether funcDef is virtual).
*/
FuncCall(FuncDef *funcDef, bool squashVirtual = false);
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
};
std::ostream &operator <<(std::ostream &out, const FuncCall::ExprVec &args);
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_InstVarDef_h_
#define _model_InstVarDef_h_
#include <vector>
#include "VarDef.h"
namespace model {
SPUG_RCPTR(Expr);
SPUG_RCPTR(InstVarDef);
/**
* An instance variable definition - these are special because we preserve the
* initializer.
*/
class InstVarDef : public VarDef {
public:
ExprPtr initializer;
InstVarDef(TypeDef *type, const std::string &name,
Expr *initializer
) :
VarDef(type, name),
initializer(initializer) {
}
};
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#ifndef _model_GetRegisterExpr_h_
#define _model_GetRegisterExpr_h_
#include "Expr.h"
namespace model {
/**
* Expression that obtains the value of the register in the current context.
*/
class GetRegisterExpr : public Expr {
public:
GetRegisterExpr(TypeDef *type) : Expr(type) {}
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
virtual bool isProductive() const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_FuncDef_h_
#define _model_FuncDef_h_
#include <vector>
#include "TypeDef.h"
#include "VarDef.h"
#include "ArgDef.h"
namespace builder {
class Builder;
}
namespace model {
//SPUG_RCPTR(ArgDef);
SPUG_RCPTR(Expr);
SPUG_RCPTR(Namespace);
SPUG_RCPTR(FuncDef);
class FuncDef : public VarDef {
public:
enum Flags {
noFlags =0, // so we can specify this
method = 1, // function is a method (has a receiver)
virtualized = 2, // function is virtual
forward = 4, // this is a forward declaration
variadic = 8, // this is a variadic function
reverse = 16, // for a binary op, reverse receiver and first arg
abstract = 32, // This is an abstract (pure virtual function)
explicitFlags = 256 // these flags were set by an annotation
} flags;
// flag to tell us what to do about function arguments during matching.
enum Convert {
noConvert = 0,
adapt = 1, // only convert adaptive arguments
adaptSecondary = 2, // convert adaptives except for the first
// argument
convert = 3 // convert all arguments
};
typedef std::vector<ArgDefPtr> ArgVec;
ArgVec args;
ArgDefPtr thisArg;
TypeDefPtr returnType;
NamespacePtr ns;
// for a virtual function, this is the path to the base class
// where the vtable is defined
TypeDef::AncestorPath pathToFirstDeclaration;
FuncDef(Flags flags, const std::string &name, size_t argCount);
/**
* Returns true if 'args' matches the types of the functions
* arguments.
*
* @param newValues the set of converted values. This is only
* constructed if 'convertFlag' is something other than
* "noConvert".
* @param convertFlag defines how to do argument conversions.
*/
virtual bool matches(Context &context,
const std::vector<ExprPtr> &vals,
std::vector<ExprPtr> &newVals,
Convert convertFlag
);
/**
* Returns true if the arg list matches the functions args.
*/
bool matches(const ArgVec &args);
/**
* Returns true if 'args' matches the functions arg names and types.
*/
bool matchesWithNames(const ArgVec &args);
/**
* Returns true if the function can be overriden.
*/
bool isOverridable() const;
virtual bool hasInstSlot();
virtual bool isStatic() const;
virtual std::string getDisplayName() const;
/**
* Returns true if the function is an override of a virtual method
* in an ancestor class.
*/
bool isVirtualOverride() const;
/**
* Returns the "receiver type." For a non-virtual function, this
* is simply the type that the function was declared in. For a
* virtual function, it is the type of the base class in which the
* function was first declared.
*/
TypeDef *getReceiverType() const;
/**
* Returns the "this" type of the function. This is always either
* the receiver type or a specialization of it.
*/
TypeDef *getThisType() const;
virtual bool isConstant();
/**
* Returns the address of the underlying compiled function, suitable
* for use when directly calling a function from C.
* It is fair to assume that this will trigger an assertion failure if
* called on an incomplete function.
*/
virtual void *getFuncAddr(builder::Builder &builder) = 0;
/**
* Returns a const-folded form of the function if there is one, null
* if not.
*/
ExprPtr foldConstants(const std::vector<ExprPtr> &args) const;
virtual
void dump(std::ostream &out, const std::string &prefix = "") const;
void display(std::ostream &out, const std::string &prefix = "") const;
/** Allow us to write the argument list. */
static void dump(std::ostream &out, const ArgVec &args);
static void display(std::ostream &out, const ArgVec &args);
};
inline FuncDef::Flags operator |(FuncDef::Flags a, FuncDef::Flags b) {
return static_cast<FuncDef::Flags>(static_cast<int>(a) |
static_cast<int>(b));
}
inline std::ostream &operator <<(std::ostream &out,
const FuncDef::ArgVec &args
) {
FuncDef::display(out, args);
return out;
}
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#include "SetRegisterExpr.h"
#include "Context.h"
#include "ResultExpr.h"
using namespace model;
ResultExprPtr SetRegisterExpr::emit(Context &context) {
ResultExprPtr result = expr->emit(context);
context.reg = result;
return result;
}
void SetRegisterExpr::writeTo(std::ostream &out) const {
out << "register = ";
expr->writeTo(out);
}
bool SetRegisterExpr::isProductive() const {
// delegate this to the expression we wrap
return expr->isProductive();
}
| C++ |
#include "TernaryExpr.h"
#include "builder/Builder.h"
#include "Context.h"
#include "ResultExpr.h"
using namespace std;
using namespace model;
ResultExprPtr TernaryExpr::emit(Context &context) {
return context.builder.emitTernary(context, this);
}
void TernaryExpr::writeTo(ostream &out) const {
out << "(";
cond->writeTo(out);
out << " ? ";
trueVal->writeTo(out);
out << " : ";
if (falseVal)
falseVal->writeTo(out);
else
out << "void";
out << ")";
}
bool TernaryExpr::isProductive() const {
return trueVal->isProductive() || falseVal && falseVal->isProductive();
} | C++ |
// copyright 2011 Google Inc.
#include "Generic.h"
#include <string.h>
#include "Serializer.h"
#include "Deserializer.h"
#include "parser/Toker.h"
using namespace std;
using namespace model;
using namespace parser;
GenericParm *Generic::getParm(const std::string &name) {
for (int i = 0; i < parms.size(); ++i)
if (parms[i]->name == name)
return parms[i].get();
return 0;
}
void Generic::replay(parser::Toker &toker) {
// we have to put back the token list in reverse order.
for (int i = body.size() - 1; i >= 0; --i)
toker.putBack(body[i]);
}
void Generic::serializeToken(Serializer &out, const Token &tok) {
out.write(static_cast<int>(tok.getType()));
// only write data for token types where it matters
switch (tok.getType()) {
case Token::integer:
case Token::string:
case Token::floatLit:
case Token::octalLit:
case Token::hexLit:
case Token::binLit:
out.write(tok.getData());
}
const Location &loc = tok.getLocation();
if (out.writeObject(loc.get())) {
const char *name = loc.getName();
out.write(strlen(name), name);
out.write(loc.getLineNumber());
}
}
namespace {
struct LocReader : public Deserializer::ObjectReader {
virtual void *read(Deserializer &src) const {
string name = src.readString(256);
int lineNum = src.readUInt();
// we don't need to use LocationMap for this: the deserializer's object
// map serves the same function.
return new LocationImpl(name.c_str(), lineNum);
}
};
}
Token Generic::deserializeToken(Deserializer &src) {
Token::Type tokType = static_cast<Token::Type>(src.readUInt());
string tokText;
switch (tokType) {
case Token::integer:
case Token::string:
case Token::floatLit:
case Token::octalLit:
case Token::hexLit:
case Token::binLit:
tokText = src.readString(32);
}
Location loc =
reinterpret_cast<LocationImpl *>(src.readObject(LocReader()));
return Token(tokType, tokText, loc);
}
void Generic::serialize(Serializer &out) const {
// serialize the parameters
out.write(parms.size());
for (GenericParmVec::const_iterator iter = parms.begin();
iter != parms.end();
++iter
)
out.write((*iter)->name);
out.write(body.size());
for (TokenVec::const_iterator iter = body.begin();
iter != body.end();
++iter
)
serializeToken(out, *iter);
}
Generic *Generic::deserialize(Deserializer &src) {
Generic *result = new Generic();
int parmCount = src.readUInt();
result->parms.reserve(parmCount);
for (int i = 0; i < parmCount; ++i)
result->parms.push_back(new GenericParm(src.readString(32)));
int tokCount = src.readUInt();
result->body.reserve(tokCount);
for (int i = 0; i < tokCount; ++i)
result->body.push_back(deserializeToken(src));
return result;
}
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_VarAnnotation_h_
#define _model_VarAnnotation_h_
#include "Annotation.h"
namespace model {
SPUG_RCPTR(VarAnnotation);
/** An annotation implemented as a variable. */
class VarAnnotation : VarDef {
private:
VarDefPtr var;
public:
VarAnnotation(VarDef *func);
virtual void invoke(Parser *parser, Toker *toker, Context *context);
};
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#include "ConstSequenceExpr.h"
#include "CleanupFrame.h"
#include "Context.h"
#include "FuncCall.h"
#include "ResultExpr.h"
using namespace model;
ResultExprPtr ConstSequenceExpr::emit(Context &context) {
ResultExprPtr containerResult = container->emit(context);
// emit all of the element append epxressions
for (int i = 0; i < elems.size(); ++i) {
context.createCleanupFrame();
// this is rather ugly. We have to set the receiver here to avoid
// having to either create a variable to hold the container or
// re-evalutating the container expression every time (effectively
// allocating one container for each element)
elems[i]->receiver = containerResult;
elems[i]->emit(context)->handleTransient(context);
context.closeCleanupFrame();
}
// re-emit the result.
containerResult->emit(context);
return containerResult;
}
void ConstSequenceExpr::writeTo(std::ostream &out) const {
out << "[";
for (int i = 0; i < elems.size(); ++i) {
elems[i]->writeTo(out);
out << ", ";
}
out << "]";
}
| C++ |
// Copyright 2010 Google Inc.
#ifndef _model_Initializers_h_
#define _model_Initializers_h_
#include <map>
#include <spug/RCPtr.h>
#include <spug/RCBase.h>
namespace model {
SPUG_RCPTR(Expr);
SPUG_RCPTR(FuncCall);
class TypeDef;
class VarDef;
SPUG_RCPTR(Initializers);
/**
* This class keeps track of the list of initializers in a constructor (oper
* init).
*/
class Initializers : public spug::RCBase {
private:
typedef std::map<TypeDef *, FuncCallPtr> BaseInitMap;
BaseInitMap baseMap;
typedef std::map<VarDef *, ExprPtr> FieldInitMap;
FieldInitMap fieldMap;
public:
bool addBaseInitializer(TypeDef *base, FuncCall *init);
FuncCall *getBaseInitializer(TypeDef *base);
bool addFieldInitializer(VarDef *var, Expr *init);
Expr *getFieldInitializer(VarDef *var);
};
} // namespace model
#endif
| C++ |
// Copyright 2010 Google Inc.
#include "FuncAnnotation.h"
#include "compiler/CrackContext.h"
#include "parser/Parser.h"
#include "Context.h"
#include "FuncDef.h"
using namespace compiler;
using namespace model;
using namespace parser;
FuncAnnotation::FuncAnnotation(FuncDef *func) :
Annotation(0, func->name),
func(func) {
}
void FuncAnnotation::invoke(Parser *parser, Toker *toker, Context *context) {
typedef void (*AnnotationFunc)(CrackContext *);
CrackContext crackCtx(parser, toker, context);
// use the compile time construct's builder
Construct *construct = context->getCompileTimeConstruct();
((AnnotationFunc)func->getFuncAddr(*construct->rootBuilder))(&crackCtx);
}
| C++ |
// Copyright 2011 Google Inc.
#ifndef _model_MultiExpr_h_
#define _model_MultiExpr_h_
#include <vector>
#include "Expr.h"
namespace model {
SPUG_RCPTR(FuncCall);
SPUG_RCPTR(MultiExpr);
/**
* This is a high-level expression type that is a list of expression that are
* evaluated sequentially. The result of a MultiExpr is the result of the
* last sub-expression. A MultiExpr must have at least one sub-expression.
*/
class MultiExpr : public Expr {
private:
std::vector<ExprPtr> elems;
public:
MultiExpr() : Expr(0) {}
void add(Expr *expr) { elems.push_back(expr); }
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
virtual bool isProductive() const;
};
} // namespace model
#endif
| C++ |
// Copyright 2011 Google Inc.
#ifndef _model_ConstSequenceExpr_h_
#define _model_ConstSequenceExpr_h_
#include <vector>
#include "Expr.h"
namespace model {
SPUG_RCPTR(FuncCall);
SPUG_RCPTR(ConstSequenceExpr);
/**
* This is a high-level expression type that holds a sequence constant.
*/
class ConstSequenceExpr : public Expr {
public:
FuncCallPtr container;
std::vector<FuncCallPtr> elems;
ConstSequenceExpr(TypeDef *type) : Expr(type) {}
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "OverloadDef.h"
#include "Context.h"
#include "Expr.h"
#include "TypeDef.h"
#include "VarDefImpl.h"
using namespace std;
using namespace model;
void OverloadDef::setImpl(FuncDef *func) {
type = func->type;
impl = func->impl;
}
void OverloadDef::flatten(OverloadDef::FuncList &flatFuncs) const {
// first do all of the local functions
for (FuncList::const_iterator iter = funcs.begin();
iter != funcs.end();
++iter
) {
bool gotMatch = false;
for (FuncList::const_iterator inner = flatFuncs.begin();
inner != flatFuncs.end();
++inner
)
if ( (*inner)->matches((*iter)->args) ) {
gotMatch = true;
break;
}
// if the signature is not already in flatFuncs, add it.
if (!gotMatch)
flatFuncs.push_back(iter->get());
}
// now flatten all of the parents
for (ParentVec::const_iterator parent = parents.begin();
parent != parents.end();
++parent
)
(*parent)->flatten(flatFuncs);
}
FuncDef *OverloadDef::getMatch(Context &context, vector<ExprPtr> &args,
FuncDef::Convert convertFlag,
bool allowOverrides
) {
vector<ExprPtr> newArgs(args.size());
for (FuncList::iterator iter = funcs.begin();
iter != funcs.end();
++iter) {
// ignore the function if it is a virtual override and we're not
// looking for those
if (!allowOverrides && (*iter)->isVirtualOverride())
continue;
// see if the function matches
if ((*iter)->matches(context, args, newArgs, convertFlag)) {
if (convertFlag != FuncDef::noConvert)
args = newArgs;
return iter->get();
}
}
for (ParentVec::iterator parent = parents.begin();
parent != parents.end();
++parent
) {
FuncDef *result = (*parent)->getMatch(context, args, convertFlag,
allowOverrides
);
if (result)
return result;
}
return 0;
}
FuncDef *OverloadDef::getMatch(Context &context, std::vector<ExprPtr> &args,
bool allowOverrides
) {
// see if we have any adaptive arguments and if all of them are adaptive.
bool someAdaptive = false, allAdaptive = true;
for (vector<ExprPtr>::iterator iter = args.begin();
iter != args.end();
++iter
)
if ((*iter)->isAdaptive())
someAdaptive = true;
else
allAdaptive = false;
// if any of the arguments are adpative, convert the adaptive arguments.
FuncDef::Convert convertFlag = FuncDef::noConvert;
if (someAdaptive)
convertFlag = FuncDef::adapt;
// if _all_ of the arguments are adaptive,
if (allAdaptive)
convertFlag = FuncDef::adaptSecondary;
FuncDef *result = getMatch(context, args, convertFlag, allowOverrides);
if (!result)
result = getMatch(context, args, FuncDef::convert, allowOverrides);
return result;
}
FuncDef *OverloadDef::getSigMatch(const FuncDef::ArgVec &args,
bool matchNames
) {
for (FuncList::iterator iter = funcs.begin();
iter != funcs.end();
++iter)
if (!matchNames && (*iter)->matches(args) ||
matchNames && (*iter)->matchesWithNames(args)
)
return iter->get();
for (ParentVec::iterator parent = parents.begin();
parent != parents.end();
++parent
) {
FuncDef *result = (*parent)->getSigMatch(args, matchNames);
if (result)
return result;
}
return 0;
}
FuncDef *OverloadDef::getNoArgMatch(bool acceptAlias) {
// check the local functions.
for (FuncList::iterator iter = funcs.begin();
iter != funcs.end();
++iter
)
if ((*iter)->args.empty() &&
(acceptAlias || (*iter)->getOwner() == owner)
)
return iter->get();
// check delegated functions.
for (ParentVec::iterator parent = parents.begin();
parent != parents.end();
++parent
) {
FuncDef *result = (*parent)->getNoArgMatch(acceptAlias);
if (result)
return result;
}
return 0;
}
OverloadDefPtr OverloadDef::createAlias() {
OverloadDefPtr alias = new OverloadDef(name);
alias->type = type;
alias->impl = impl;
flatten(alias->funcs);
return alias;
}
void OverloadDef::addFunc(FuncDef *func) {
if (funcs.empty()) setImpl(func);
funcs.push_back(func);
}
void OverloadDef::addParent(OverloadDef *parent) {
parents.push_back(parent);
}
bool OverloadDef::hasParent(OverloadDef *parent) {
for (ParentVec::iterator iter = parents.begin(); iter != parents.end();
++iter
)
if (iter->get() == parent)
return true;
return false;
}
bool OverloadDef::hasInstSlot() {
return false;
}
bool OverloadDef::isStatic() const {
FuncList flatFuncs;
flatten(flatFuncs);
assert((flatFuncs.size() == 1) &&
"isStatic() check applied to a multi-function overload"
);
return flatFuncs.front()->isStatic();
}
bool OverloadDef::isSingleFunction() const {
FuncList flatFuncs;
flatten(flatFuncs);
return flatFuncs.size() == 1;
}
void OverloadDef::createImpl() {
if (!impl) {
// get the impl from the first parent with one.
for (ParentVec::iterator parent = parents.begin();
parent != parents.end();
++parent
) {
(*parent)->createImpl();
if ((*parent)->impl) {
impl = (*parent)->impl;
break;
}
}
assert(impl);
}
}
bool OverloadDef::isConstant() {
return true;
}
void OverloadDef::dump(ostream &out, const string &prefix) const {
for (FuncList::const_iterator iter = funcs.begin();
iter != funcs.end();
++iter
)
(*iter)->dump(out, prefix);
for (ParentVec::const_iterator parent = parents.begin();
parent != parents.end();
++parent
)
(*parent)->dump(out, prefix);
}
void OverloadDef::display(ostream &out, const string &prefix) const {
for (FuncList::const_iterator iter = funcs.begin();
iter != funcs.end();
++iter
) {
(*iter)->display(out, prefix + " ");
out << '\n';
}
for (ParentVec::const_iterator parent = parents.begin();
parent != parents.end();
++parent
)
(*parent)->display(out, prefix);
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_IntConst_h_
#define _model_IntConst_h_
#include "Context.h"
#include "Expr.h"
#include <stdint.h>
namespace model {
SPUG_RCPTR(IntConst);
// There's only one kind of integer constant - it can be specialized based on
// context - e.g. 32 bit, 64 bit, signed versus unsigned...
class IntConst : public Expr {
public:
union {
int64_t sval;
uint64_t uval;
} val;
bool reqUnsigned; // > INT64_MAX so requires unsigned 64
bool uneg; // "unsigned negative"
IntConst(TypeDef *type, int64_t val);
IntConst(TypeDef *type, uint64_t val);
virtual ResultExprPtr emit(Context &context);
virtual ExprPtr convert(Context &context, TypeDef *newType);
virtual void writeTo(std::ostream &out) const;
virtual bool isAdaptive() const;
virtual IntConstPtr create(int64_t v);
virtual IntConstPtr create(uint64_t v);
/** Return the default type for the value. */
static TypeDef *selectType(Context &context, int64_t val);
ExprPtr foldAdd(Expr *other);
ExprPtr foldSub(Expr *other);
ExprPtr foldMul(Expr *other);
ExprPtr foldSDiv(Expr *other);
ExprPtr foldUDiv(Expr *other);
ExprPtr foldSRem(Expr *other);
ExprPtr foldURem(Expr *other);
ExprPtr foldOr(Expr *other);
ExprPtr foldAnd(Expr *other);
ExprPtr foldXor(Expr *other);
ExprPtr foldShl(Expr *other);
ExprPtr foldLShr(Expr *other);
ExprPtr foldAShr(Expr *other);
ExprPtr foldNeg();
ExprPtr foldBitNot();
};
} // namespace parser
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_ResultExpr_h_
#define _model_ResultExpr_h_
#include "Expr.h"
namespace model {
SPUG_RCPTR(ResultExpr);
/**
* A result expression is the stored result of a previous expression used for
* cleanup.
*
* This is an abstract class: the builder should produce a concrete derived
* class implementing the "emit()" method.
*/
class ResultExpr : public Expr {
public:
ExprPtr sourceExpr;
ResultExpr(Expr *sourceExpr) :
Expr(sourceExpr->type.get()),
sourceExpr(sourceExpr) {
}
/**
* Does garbage collection processing for an assignment: if the original
* expression was productive, does nothing (the variable being
* assigned will consume the new reference). If not, generates a
* "bind" operation to cause the expression to be owned by the
* variable.
*/
void handleAssignment(Context &context);
/**
* Handles the cleanup of a transient reference. If the source
* expression is productive, adds it to the cleanups.
*/
void handleTransient(Context &context);
/**
* Forces the expression to be added to cleanups, whether it is
* productive or not (but not if it has no 'oper release').
*/
void forceCleanup(Context &context);
/** Overrides isProductive() to delegate to the source expr. */
virtual bool isProductive() const;
virtual void writeTo(std::ostream &out) const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_LocalNamespace_h_
#define _model_LocalNamespace_h_
#include "Namespace.h"
namespace model {
SPUG_RCPTR(LocalNamespace);
/** A single-parent namespace for block or function contexts. */
class LocalNamespace : public Namespace {
private:
NamespacePtr parent;
public:
LocalNamespace(Namespace *parent, const std::string &cName) :
// if we have a parent, create a canonical name
// based on it and the given cName. if cName is empty
// though (think local subcontext in a module), we use
// just the parent name. if we don't have a parent,
// we just use cName
Namespace((parent && !parent->getNamespaceName().empty())?
((cName.empty())?parent->getNamespaceName() :
parent->getNamespaceName()+"."+cName) :
cName),
parent(parent) {}
/** required implementation of Namespace::getModule() */
virtual ModuleDefPtr getModule();
virtual NamespacePtr getParent(unsigned index);
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "Expr.h"
#include "builder/Builder.h"
#include "Context.h"
#include "TypeDef.h"
using namespace model;
Expr::Expr(TypeDef *type) : type(type) {}
Expr::~Expr() {}
void Expr::emitCond(Context &context) {
context.builder.emitTest(context, this);
}
ExprPtr Expr::convert(Context &context, TypeDef *newType) {
// see if we're already of the right type
if (newType->matches(*type))
return this;
// see if there's a converter
FuncDefPtr converter = type->getConverter(context, *newType);
if (converter) {
FuncCallPtr convCall =
context.builder.createFuncCall(converter.get());
convCall->receiver = this;
return convCall;
}
// can't convert
return 0;
}
bool Expr::isProductive() const {
// by default, all expresssions returning pointer types are productive
return type->pointer;
}
bool Expr::isAdaptive() const {
return false;
}
ExprPtr Expr::foldConstants() { return this; }
void Expr::dump() const { writeTo(std::cerr); } | C++ |
// copyright 2012 Google Inc.
#ifndef _model_Deserializer_h_
#define _model_Deserializer_h_
#include <string>
#include <map>
namespace model {
class Deserializer {
private:
std::istream &src;
// the deserializer's object map
typedef std::map<int, void *> ObjMap;
ObjMap objMap;
public:
/**
* interface for object reader classes - these know how to read a
* specific object from the stream and are used as a callback for
* readObject().
*/
struct ObjectReader {
virtual void *read(Deserializer &src) const = 0;
};
Deserializer(std::istream &src) : src(src) {}
unsigned int readUInt();
/**
* Read a sized blob (block of binary data) from the stream.
* If a buffer is provided, it attempts to use the buffer. Otherwise
* it returns a new, allocated buffer containing the data
* This function always returns a pointer to the buffer, the caller
* should delete[] the buffer if it is not the input
* buffer.
* @param size (input/output) on input this is this size of 'buffer'.
* On output it is the size of the blob that was read. The
* input value is ignore if 'buffer' is null.
* @param buffer If specified, this is a pointer to a buffer for the
* blob to be stored in. If this is not null, 'size' must be
* provided.
*/
char *readBlob(size_t &size, char *buffer);
/**
* Read a block of binary data as a string. expectedMaxSize is a
* reasonable size for the buffer - if it is greater then more space
* will be allocated.
* This implements the common case of creating a string from the blob.
*/
std::string readString(size_t expectedMaxSize);
/**
* Read the next object from the stream. This returns a pointer to an
* existing object if the object possibly calling reader.read() to
* deserialize the object from the stream.
*/
void *readObject(const ObjectReader &reader);
};
}
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_AssignExpr_h_
#define _model_AssignExpr_h_
#include "Expr.h"
namespace parser {
class Token;
};
namespace model {
class Context;
SPUG_RCPTR(Expr);
SPUG_RCPTR(TypeDef);
SPUG_RCPTR(VarDef);
SPUG_RCPTR(AssignExpr);
/**
* An assignment expression.
*/
class AssignExpr : public Expr {
public:
ExprPtr aggregate, value;
VarDefPtr var;
AssignExpr(Expr *aggregate, VarDef *var, Expr *value);
/**
* Create a new AssignExpr, check for errors.
* @param aggregate the aggregate that the variable is a member of
* @param var the variable
* @param value the value to be assigned to the variable.
*/
static AssignExprPtr create(Context &context,
Expr *aggregate,
VarDef *var,
Expr *value
);
/**
* Create a new AssignExpr, check for errors. Just like the other
* create() method only for non-instance variables (statics, globals
* and locals)
*
* @param var the variable
* @param value the value to be assigned to the variable.
*/
static AssignExprPtr create(Context &context,
VarDef *var,
Expr *value
) {
return create(context, 0, var, value);
}
/** Emit the expression in the given context. */
virtual ResultExprPtr emit(Context &context);
// overrides Expr, assignments are non-productive.
virtual bool isProductive() const;
virtual void writeTo(std::ostream &out) const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
// Copyright 2010 Shannon Weyrick <weyrick@mozek.us>
#ifndef _model_FloatConst_h_
#define _model_FloatConst_h_
#include "Context.h"
#include "Expr.h"
namespace model {
SPUG_RCPTR(FloatConst);
// As with integers, there's only one kind of float constant -
// it can be specialized based on context - e.g. 32 bit or 64 bit
class FloatConst : public Expr {
public:
double val;
FloatConst(TypeDef *type, double val);
virtual ResultExprPtr emit(Context &context);
virtual ExprPtr convert(Context &context, TypeDef *newType);
virtual void writeTo(std::ostream &out) const;
bool isAdaptive() const;
virtual FloatConstPtr create(double val) const;
ExprPtr foldFAdd(Expr *other);
ExprPtr foldFSub(Expr *other);
ExprPtr foldFMul(Expr *other);
ExprPtr foldFDiv(Expr *other);
ExprPtr foldFRem(Expr *other);
ExprPtr foldNeg();
};
} // namespace parser
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_AllocExpr_h_
#define _model_AllocExpr_h_
#include <string>
#include <vector>
#include "Expr.h"
namespace model {
SPUG_RCPTR(AllocExpr);
class AllocExpr : public Expr {
public:
AllocExpr(TypeDef *type) : Expr(type) {}
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_VarDefImpl_h_
#define _model_VarDefImpl_h_
#include <spug/RCBase.h>
#include <spug/RCPtr.h>
namespace model {
class AssignExpr;
SPUG_RCPTR(ResultExpr);
class VarRef;
SPUG_RCPTR(VarDefImpl);
/**
* Variable definition implementation that knows how to emit a reference to
* the variable.
*/
class VarDefImpl : public spug::RCBase {
public:
VarDefImpl() {}
virtual ResultExprPtr emitRef(Context &context, VarRef *var) = 0;
virtual ResultExprPtr emitAssignment(Context &context,
AssignExpr *assign
) = 0;
virtual bool hasInstSlot() const = 0;
};
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "AllocExpr.h"
#include "builder/Builder.h"
#include "Context.h"
#include "TypeDef.h"
#include "ResultExpr.h"
using namespace model;
using namespace std;
ResultExprPtr AllocExpr::emit(Context &context) {
return context.builder.emitAlloc(context, this);
}
void AllocExpr::writeTo(ostream &out) const {
out << "alloc(" << type->name << ")";
}
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_CompositeNamespace_h_
#define _model_CompositeNamespace_h_
#include <vector>
#include "Namespace.h"
namespace model {
SPUG_RCPTR(CompositeNamespace);
/**
* A virtual namespace that delegates to several other namespaces.
*
* All new definitions added to the namespace will be stored in the first
* parent.
*/
class CompositeNamespace : public Namespace {
private:
std::vector<NamespacePtr> parents;
public:
CompositeNamespace(Namespace *parent0, Namespace *parent1);
virtual ModuleDefPtr getModule();
virtual NamespacePtr getParent(unsigned index);
virtual void addDef(VarDef *def);
virtual void removeDef(VarDef *def);
virtual void addAlias(VarDef *def);
virtual OverloadDefPtr addAlias(const std::string &name, VarDef *def);
virtual void addUnsafeAlias(const std::string &name, VarDef *def);
virtual void replaceDef(VarDef *def);
};
} // namespace model
#endif
| C++ |
// Copyright 2012 Google Inc.
#ifndef _model_ImportedDef_h_
#define _model_ImportedDef_h_
#include <string>
#include <vector>
namespace model {
// stores the names for an imported definition.
struct ImportedDef {
// the "local name" is the alias that a symbol is imported under.
// the "source name" is the unqualified name that the definition has in
// the module we are importing it from.
std::string local, source;
ImportedDef(const std::string &local, const std::string &source) :
local(local),
source(source) {
}
/**
* Initialize both the local and source names to "name".
*/
ImportedDef(const std::string &name) :
local(name),
source(name) {
}
};
typedef std::vector<ImportedDef> ImportedDefVec;
} // namespace model
#endif
| C++ |
// Copyright 2009 Google Inc.
#ifndef _model_StrConst_h_
#define _model_StrConst_h_
#include "Context.h"
#include "Expr.h"
namespace model {
class StrConst : public Expr {
public:
std::string val;
StrConst(TypeDef *type, const std::string &val);
virtual ResultExprPtr emit(Context &context);
virtual void writeTo(std::ostream &out) const;
};
} // namespace parser
#endif
| C++ |
// Copyright 2009 Google Inc.
#include "FuncDef.h"
#include <sstream>
#include "Context.h"
#include "ArgDef.h"
#include "Expr.h"
#include "TypeDef.h"
#include "VarDefImpl.h"
using namespace model;
using namespace std;
FuncDef::FuncDef(Flags flags, const std::string &name, size_t argCount) :
// function types are assigned after the fact.
VarDef(0, name),
flags(flags),
args(argCount) {
}
bool FuncDef::matches(Context &context, const vector<ExprPtr> &vals,
vector<ExprPtr> &newVals,
FuncDef::Convert convertFlag
) {
ArgVec::iterator arg;
vector<ExprPtr>::const_iterator val;
int i;
for (arg = args.begin(), val = vals.begin(), i = 0;
arg != args.end() && val != vals.end();
++arg, ++val, ++i
) {
switch (convertFlag) {
case adapt:
case adaptSecondary:
if ((convertFlag == adapt || i) &&
(*val)->isAdaptive()
) {
newVals[i] = (*val)->convert(context, (*arg)->type.get());
if (!newVals[i])
return false;
} else if ((*arg)->type->matches(*(*val)->type)) {
newVals[i] = *val;
} else {
return false;
}
break;
case convert:
newVals[i] = (*val)->convert(context, (*arg)->type.get());
if (!newVals[i])
return false;
break;
case noConvert:
if (!(*arg)->type->matches(*(*val)->type))
return false;
break;
}
}
// make sure that we checked everything in both lists
if (arg != args.end() || val != vals.end())
return false;
return true;
}
bool FuncDef::matches(const ArgVec &other_args) {
ArgVec::iterator arg;
ArgVec::const_iterator other_arg;
for (arg = args.begin(), other_arg = other_args.begin();
arg != args.end() && other_arg != other_args.end();
++arg, ++other_arg
)
// if the types don't _exactly_ match, the signatures don't match.
if ((*arg)->type.get() != (*other_arg)->type.get())
return false;
// make sure that we checked everything in both lists
if (arg != args.end() || other_arg != other_args.end())
return false;
return true;
}
bool FuncDef::matchesWithNames(const ArgVec &other_args) {
ArgVec::iterator arg;
ArgVec::const_iterator other_arg;
for (arg = args.begin(), other_arg = other_args.begin();
arg != args.end() && other_arg != other_args.end();
++arg, ++other_arg
) {
// if the types don't _exactly_ match, the signatures don't match.
if ((*arg)->type.get() != (*other_arg)->type.get())
return false;
// if the arg names don't exactly match, the signatures don't match.
if ((*arg)->name != (*other_arg)->name)
return false;
}
// make sure that we checked everything in both lists
if (arg != args.end() || other_arg != other_args.end())
return false;
return true;
}
bool FuncDef::isOverridable() const {
return flags & virtualized || name == "oper init" || flags & forward;
}
bool FuncDef::hasInstSlot() {
return false;
}
bool FuncDef::isStatic() const {
return !(flags & method);
}
string FuncDef::getDisplayName() const {
ostringstream out;
display(out, "");
return out.str();
}
bool FuncDef::isVirtualOverride() const {
return flags & virtualized && pathToFirstDeclaration.size();
}
TypeDef *FuncDef::getReceiverType() const {
TypeDef *result;
if (pathToFirstDeclaration.size())
result = pathToFirstDeclaration.back().ancestor.get();
else
result = TypeDefPtr::cast(owner);
return result;
}
TypeDef *FuncDef::getThisType() const {
return TypeDefPtr::cast(owner);
}
bool FuncDef::isConstant() {
return true;
}
ExprPtr FuncDef::foldConstants(const vector<ExprPtr> &args) const {
return 0;
}
void FuncDef::dump(ostream &out, const string &prefix) const {
out << prefix << returnType->getFullName() << " " << getFullName() <<
args << "\n";
}
void FuncDef::dump(ostream &out, const ArgVec &args) {
out << '(';
bool first = true;
for (ArgVec::const_iterator iter = args.begin(); iter != args.end();
++iter
) {
if (!first)
out << ", ";
else
first = false;
out << (*iter)->type->getFullName() << ' ' << (*iter)->name;
}
out << ")";
}
void FuncDef::display(ostream &out, const ArgVec &args) {
out << '(';
bool first = true;
for (ArgVec::const_iterator iter = args.begin(); iter != args.end();
++iter
) {
if (!first)
out << ", ";
else
first = false;
out << (*iter)->type->getDisplayName() << ' ' << (*iter)->name;
}
out << ")";
}
void FuncDef::display(ostream &out, const string &prefix) const {
out << prefix << returnType->getDisplayName() << " " <<
VarDef::getDisplayName();
display(out, args);
} | C++ |
#include <string.h>
#include "ext/Func.h"
#include "ext/Module.h"
#include "ext/Type.h"
#include "ext/util.h"
#include <iostream>
using namespace crack::ext;
using namespace std;
class MyType {
public:
int a;
const char *b;
MyType(int a, const char *b) : a(a), b(b) {}
static MyType *oper_new() {
return new MyType(100, "test");
}
static void init(MyType *inst, int a, const char *b) {
inst->a = a;
inst->b = b;
}
static const char *echo(MyType *inst, const char *data) { return data; }
};
const char *echo(const char *data) { return data; }
extern "C" const char *cecho(const char *data) { return data; }
int *copyArray(int count, int *array) {
int *result = new int[count];
return (int *)memcpy(result, array, count * sizeof(int));
}
int callback(int (*cb)(int)) {
return cb(100);
}
extern "C" void testext_rinit(void) {
cout << "in testext" << endl;
}
// a class with virtual functions
struct MyVirtual {
int *delFlag;
MyVirtual(int *delFlag = 0) : delFlag(delFlag) {}
virtual ~MyVirtual() {
if (delFlag)
*delFlag = 999;
}
virtual int vfunc(int val) {
return val;
}
static int statFunc() {
return 369;
}
};
struct MyVirtual_Proxy;
// its adapter class
struct MyVirtual_Adapter : public MyVirtual {
// translation functions for virtuals
virtual int vfunc(int val);
virtual ~MyVirtual_Adapter();
// static wrapper functions
static int callVFunc(MyVirtual *inst, int val) {
return inst->MyVirtual::vfunc(val);
}
static void *operator new(size_t size, void *mem) { return mem; }
static void init(void *inst) {
new(inst) MyVirtual();
}
static void init1(void *inst, int *delFlag) {
new(inst) MyVirtual(delFlag);
}
static void operator delete(void *mem) {}
static void del(MyVirtual_Adapter *inst) {
inst->MyVirtual::~MyVirtual();
}
};
struct MyVirtual_VTable {
void *classInst;
int (*vfunc)(MyVirtual_Adapter *inst, int val);
int (*del)(MyVirtual_Adapter *inst);
};
struct MyVirtual_Proxy {
MyVirtual_VTable *vtable;
MyVirtual_Adapter adapter;
};
// adapter call to dispatch to the Crack vtable
int MyVirtual_Adapter::vfunc(int val) {
MyVirtual_Proxy *inst = getCrackProxy<MyVirtual_Proxy>(this);
return inst->vtable->vfunc(this, val);
}
MyVirtual_Adapter::~MyVirtual_Adapter() {
MyVirtual_Proxy *inst = getCrackProxy<MyVirtual_Proxy>(this);
inst->vtable->del(this);
}
extern "C" void testext_cinit(Module *mod) {
Func *f = mod->addFunc(mod->getByteptrType(), "echo", (void *)echo);
f->addArg(mod->getByteptrType(), "data");
Type *type = mod->addType("MyType", sizeof(MyType));
type->addInstVar(mod->getIntType(), "a", CRACK_OFFSET(MyType, a));
type->addInstVar(mod->getByteptrType(), "b", CRACK_OFFSET(MyType, b));
type->addStaticMethod(type, "oper new", (void *)MyType::oper_new);
f = type->addMethod(mod->getByteptrType(), "echo", (void *)MyType::echo);
f->addArg(mod->getByteptrType(), "data");
f = type->addConstructor();
f = type->addConstructor("init", (void *)MyType::init);
f->addArg(mod->getIntType(), "a");
f->addArg(mod->getByteptrType(), "b");
type->finish();
mod->addConstant(mod->getIntType(), "INT_CONST", 123);
mod->addConstant(mod->getFloatType(), "FLOAT_CONST", 1.23);
Type *arrayType = mod->getType("array");
vector<Type *> params(1);
params[0] = mod->getIntType();
Type *intArrayType = arrayType->getSpecialization(params);
f = mod->addFunc(intArrayType, "copyArray", (void *)copyArray);
f->addArg(mod->getIntType(), "count");
f->addArg(intArrayType, "array");
Type *funcType = mod->getType("function");
vector<Type *> fparams(2);
fparams[0] = mod->getIntType(); // return type
fparams[1] = mod->getIntType(); // 1st param
Type *intFuncType = funcType->getSpecialization(fparams);
f = mod->addFunc(mod->getIntType(), "callback", (void *)callback);
f->addArg(intFuncType, "cb");
// create a type with virtual methods. We create a hidden type to
// strictly correspond to the instance area of the underlying type, then
// derive our proxy type from VTableBase and our hidden type.
type = mod->addType("MyVirtual", sizeof(MyVirtual_Adapter),
true // hasVTable - necessary for virtual types!
);
// we need some constructors to call the C++ class's constructors
type->addConstructor("oper init", (void *)MyVirtual_Adapter::init);
f = type->addConstructor("oper init", (void *)MyVirtual_Adapter::init1);
f->addArg(intArrayType, "delFlag");
// the order in which we add virtual methods must correspond to the order
// that they are defined in MyVirtual_VTable.
f = type->addMethod(mod->getIntType(), "vfunc",
(void *)MyVirtual_Adapter::callVFunc
);
f->addArg(mod->getIntType(), "val");
f->setVWrap(true);
// need a virtual destructor
f = type->addMethod(mod->getVoidType(), "oper del",
(void *)MyVirtual_Adapter::del
);
f->setVWrap(true);
// adding a static method just to test that we can call it from another
// method defined inline.
f = type->addStaticMethod(mod->getIntType(), "statFunc",
(void *)MyVirtual::statFunc
);
// finish the type
type->finish();
Type *typeMyVirtual = type;
// verify that we can create a class that calls static methods of a plain
// class and a virtual class.
type = mod->addType("Caller", 0);
type->addConstructor();
type->addMethod(mod->getIntType(), "callMyTest",
"return MyType().a;"
);
type->addMethod(typeMyVirtual, "createMyVirtual",
"return MyVirtual();"
);
type->addMethod(mod->getIntType(), "statFunc",
"return 369; //return MyVirtual.statFunc();"
);
type->finish();
}
| C++ |
// Copyright (c) 2013 Oliver Lau <ola@ct.de>, Heise Zeitschriften Verlag
// All rights reserved.
#ifndef __IMAGEWIDGET_H_
#define __IMAGEWIDGET_H_
#include <QWidget>
#include <QImage>
#include <QByteArray>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDropEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QResizeEvent>
#include <QPaintEvent>
#include <QScopedPointer>
class ImageWidgetPrivate;
class ImageWidget : public QWidget
{
Q_OBJECT
public:
explicit ImageWidget(QWidget *parent = NULL);
virtual ~ImageWidget();
QImage image(void);
public slots:
bool setRaw(const QByteArray&);
void setBPos(int);
void showHelp(bool);
signals:
void imageDropped(const QImage&);
void refresh(void);
void positionChanged(int pos, int maxPos);
protected:
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
void dragEnterEvent(QDragEnterEvent*);
void dragLeaveEvent(QDragLeaveEvent*);
void dropEvent(QDropEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void wheelEvent(QWheelEvent*);
private:
void calcDestRect(void);
private:
QScopedPointer<ImageWidgetPrivate> d_ptr;
Q_DECLARE_PRIVATE(ImageWidget)
Q_DISABLE_COPY(ImageWidget)
};
#endif // __IMAGEWIDGET_H_
| C++ |
// Copyright (c) 2008-2012 Oliver Lau <oliver@von-und-fuer-lau.de>
// Alle Rechte vorbehalten.
#ifndef __ABSTRACTNUMBERGENERATOR_H_
#define __ABSTRACTNUMBERGENERATOR_H_
#include <cstdlib>
#include <limits>
namespace randomtools {
template <typename VariateType>
class RandomNumberGenerator
{
public:
RandomNumberGenerator(void) {}
virtual ~RandomNumberGenerator() {}
virtual VariateType operator()(void) = 0;
virtual void seed(VariateType) { }
virtual inline VariateType min(void) const { return std::numeric_limits<VariateType>::min(); }
virtual inline VariateType max(void) const { return std::numeric_limits<VariateType>::max(); }
static VariateType makeSeed(void);
};
typedef RandomNumberGenerator<unsigned int> UIntRandomNumberGenerator;
}
#endif // __ABSTRACTNUMBERGENERATOR_H_
| C++ |
// Copyright (c) 2008-2013 Oliver Lau <oliver@von-und-fuer-lau.de>
// Alle Rechte vorbehalten.
#ifndef __RND_H_
#define __RND_H_
#include <QtGlobal>
#include "mersenne_twister.h"
extern MT::MersenneTwister rng;
namespace RAND {
extern void initialize(void);
inline quint32 rnd(void)
{
return rng.next();
}
inline quint32 rnd(int a)
{
Q_ASSERT(a != 0);
return rng.next() % a;
}
inline int rnd(int lo, int hi)
{
lo = qMin(lo, hi);
hi = qMax(lo, hi);
return lo + RAND::rnd(1 + hi - lo);
}
inline qreal rnd1(void)
{
return (qreal)RAND::rnd() / rng.max();
}
inline qreal rnd1(qreal a, qreal b)
{
Q_ASSERT(b >= a);
return a + RAND::rnd1() * (b - a);
}
inline int dInt(int v, int deltaMax)
{
const int r = RAND::rnd(-int(deltaMax), int(deltaMax));
return v + r;
}
inline int dInt(int v, int deltaMax, int L /* lower boundary */, int U /* upper boundary */)
{
return qBound(L, dInt(v, deltaMax), U);
}
inline qreal dReal(qreal v, qreal deltaMax)
{
return v + RAND::rnd1(-deltaMax, deltaMax);
}
inline qreal dReal(qreal v, qreal deltaMax, qreal L /* lower boundary */, qreal U /* upper boundary */)
{
return qBound(L, dReal(v, deltaMax), U);
}
}
#endif // __RND_H_
| C++ |
// Copyright (c) 2008-2012 Oliver Lau <oliver@von-und-fuer-lau.de>
// Alle Rechte vorbehalten.
#ifndef __MERSENNETWISTER_H_
#define __MERSENNETWISTER_H_
#include <QtGlobal>
#include "abstract_random_number_generator.h"
namespace MT {
class MersenneTwister : public randomtools::UIntRandomNumberGenerator
{
public:
MersenneTwister(void) {}
quint32 operator()();
inline quint32 next(void) { return (*this)(); }
void seed(quint32 _Seed = 9U);
private:
static const int N = 624;
static const int M = 397;
static const quint32 LO = 0x7fffffffU;
static const quint32 HI = 0x80000000U;
static const quint32 A[2];
quint32 y[N];
int index;
private: // methods
void warmup(void);
};
}
#endif // __MERSENNETWISTER_H_
| C++ |
// Copyright (c) 2008-2012 Oliver Lau <oliver@von-und-fuer-lau.de>
// Alle Rechte vorbehalten.
#include "mersenne_twister.h"
namespace MT {
void MersenneTwister::seed(quint32 _Seed)
{
quint32 r = _Seed;
quint32 s = 3402U;
for (int i = 0; i < N; ++i) {
r = 509845221U * r + 3U;
s *= s + 1U;
y[i] = s + (r >> 10);
}
index = 0;
warmup();
}
void MersenneTwister::warmup(void)
{
for (int i = 0; i < 10000; ++i)
(*this)();
}
quint32 MersenneTwister::operator()()
{
if (index >= N) {
quint32 h;
for (int k = 0 ; k < N-M ; ++k) {
h = (y[k] & HI) | (y[k+1] & LO);
y[k] = y[k+M] ^ (h >> 1) ^ A[h & 1];
}
for (int k = N-M ; k < N-1 ; ++k) {
h = (y[k] & HI) | (y[k+1] & LO);
y[k] = y[k+(M-N)] ^ (h >> 1) ^ A[h & 1];
}
h = (y[N-1] & HI) | (y[0] & LO);
y[N-1] = y[M-1] ^ (h >> 1) ^ A[h & 1];
index = 0;
}
quint32 e = y[index++];
e ^= (e >> 11);
e ^= (e << 7) & 0x9d2c5680;
e ^= (e << 15) & 0xefc60000;
e ^= (e >> 18);
return e;
}
const quint32 MersenneTwister::A[2] = { 0U, 0x9908b0dfU };
}
| C++ |
// Copyright (c) 2008-2012 Oliver Lau <oliver@von-und-fuer-lau.de>
// Alle Rechte vorbehalten.
#include "rnd.h"
#include <QDateTime>
MT::MersenneTwister rng;
namespace RAND {
void initialize(void)
{
rng.seed(QDateTime::currentDateTime().toTime_t());
}
}
| C++ |
// Copyright (c) 2013 Oliver Lau <ola@ct.de>, Heise Zeitschriften Verlag
// All rights reserved.
#ifndef __QLITCHAPPLICATION_H_
#define __QLITCHAPPLICATION_H_
#include <QApplication>
#include <QEvent>
#include <QTranslator>
#include <QLocale>
#include <QString>
class QlitchApplication : public QApplication
{
public:
explicit QlitchApplication(int &argc, char *argv[]);
virtual ~QlitchApplication();
public:
static const QString Company;
static const QString Name;
static const QString Url;
static const QString Author;
static const QString AuthorMail;
static const QString Version;
static const QString MinorVersion;
static const QString VersionNoDebug;
static const QString Platform;
};
#endif // __QLITCHAPPLICATION_H_
| C++ |
// Copyright (c) 2013 Oliver Lau <ola@ct.de>, Heise Zeitschriften Verlag
// All rights reserved.
#include "imagewidget.h"
#include <QtCore/QDebug>
#include <QPainter>
#include <QImage>
#include <QSizePolicy>
#include <QMimeData>
#include <QUrl>
#include <QMouseEvent>
#include <QPoint>
#include <QRect>
#include <QMessageBox>
class ImageWidgetPrivate {
public:
ImageWidgetPrivate(void)
: windowAspectRatio(0)
, imageAspectRatio(0)
, mouseDown(false)
, showHelp(true)
, bPos(0)
, maxPos(0)
{ /* ... */ }
~ImageWidgetPrivate()
{ /* ... */ }
QImage image;
QRect destRect;
qreal windowAspectRatio;
qreal imageAspectRatio;
bool mouseDown;
bool showHelp;
int bPos;
int maxPos;
};
ImageWidget::ImageWidget(QWidget *parent)
: QWidget(parent)
, d_ptr(new ImageWidgetPrivate)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setMinimumSize(320, 240);
setAcceptDrops(true);
setFocus();
}
ImageWidget::~ImageWidget()
{
// ...
}
QImage ImageWidget::image(void)
{
Q_D(ImageWidget);
return d->image;
}
void ImageWidget::setBPos(int bPos)
{
Q_D(ImageWidget);
d->bPos = bPos;
update();
}
void ImageWidget::resizeEvent(QResizeEvent* e)
{
Q_D(ImageWidget);
d->windowAspectRatio = qreal(e->size().width()) / e->size().height();
calcDestRect();
}
void ImageWidget::paintEvent(QPaintEvent*)
{
Q_D(ImageWidget);
QPainter p(this);
p.fillRect(rect(), Qt::black);
if (d->image.isNull() || qFuzzyIsNull(d->imageAspectRatio))
return;
p.drawImage(d->destRect, d->image);
if (d->showHelp) {
const QRect &leftTopBoundingBox = QRect(5, 5, 200, 100);
const QRect &leftTopTextBox = leftTopBoundingBox.marginsRemoved(QMargins(5, 5, 5, 5));
const QRect &rightTopBoundingBox = QRect(width() - 205, 5, 200, 100);
const QRect &rightTopTextBox = rightTopBoundingBox.marginsRemoved(QMargins(5, 5, 5, 5));
p.setBrush(QColor(0, 0, 0, 128));
p.setPen(Qt::transparent);
p.drawRect(leftTopBoundingBox);
p.setBrush(Qt::transparent);
p.setPen(Qt::white);
p.drawText(leftTopTextBox, tr("Click and move cursor to select glitch position. Turn mouse wheel to randomize."));
p.setBrush(QColor(0, 0, 0, 128));
p.setPen(Qt::transparent);
p.drawRect(rightTopBoundingBox);
p.setBrush(Qt::transparent);
p.setPen(Qt::white);
p.drawText(rightTopTextBox, tr("Position: %1%").arg(1e2 * d->bPos / d->maxPos, 6, 'g', 3), QTextOption(Qt::AlignRight));
}
}
bool ImageWidget::setRaw(const QByteArray &raw)
{
Q_D(ImageWidget);
QImage image;
bool ok = image.loadFromData(raw, "JPG");
if (ok) {
d->image = image.convertToFormat(QImage::Format_ARGB32);
d->imageAspectRatio = qreal(d->image.width()) / d->image.height();
calcDestRect();
}
update();
return ok;
}
void ImageWidget::showHelp(bool enabled)
{
Q_D(ImageWidget);
d->showHelp = enabled;
update();
}
void ImageWidget::dragEnterEvent(QDragEnterEvent *e)
{
const QMimeData* const d = e->mimeData();
if (d->hasUrls() && d->urls().first().toString().contains(QRegExp("\\.(png|jpg|gif|ico|mng|tga|tiff?)$")))
e->acceptProposedAction();
else
e->ignore();
}
void ImageWidget::dragLeaveEvent(QDragLeaveEvent *e)
{
e->accept();
}
void ImageWidget::dropEvent(QDropEvent *e)
{
const QMimeData *const d = e->mimeData();
if (d->hasUrls()) {
QString fileUrl = d->urls().first().toString();
if (fileUrl.contains(QRegExp("file://.*\\.(png|jpg|jpeg|gif|ico|mng|tga|tiff?)$")))
#if defined(_WIN32) || defined(_WIN64)
fileUrl.remove("file:///");
#else
fileUrl.remove("file://");
#endif
emit imageDropped(QImage(fileUrl));
}
}
void ImageWidget::mousePressEvent(QMouseEvent *e)
{
Q_D(ImageWidget);
if (e->button() == Qt::LeftButton) {
d->mouseDown = true;
update();
}
e->accept();
}
template <typename T>
inline T clamp(T x, T a, T b) {
return (x < a) ? a : (x > b) ? b : x;
}
void ImageWidget::mouseMoveEvent(QMouseEvent *e)
{
Q_D(ImageWidget);
if (d->mouseDown) {
QPoint p = e->pos() - d->destRect.topLeft();
p.setX(clamp(p.x(), 0, d->destRect.width()));
p.setY(clamp(p.y(), 0, d->destRect.height()));
d->bPos = p.x() + p.y() * d->destRect.width();
emit positionChanged(d->bPos, d->maxPos);
update();
}
}
void ImageWidget::mouseReleaseEvent(QMouseEvent *e)
{
Q_D(ImageWidget);
if (e->button() == Qt::LeftButton) {
d->mouseDown = false;
update();
}
}
void ImageWidget::wheelEvent(QWheelEvent *)
{
emit refresh();
}
void ImageWidget::calcDestRect(void)
{
Q_D(ImageWidget);
if (d->windowAspectRatio < d->imageAspectRatio) {
const int h = int(width() / d->imageAspectRatio);
d->destRect = QRect(0, (height()-h)/2, width(), h);
}
else {
const int w = int(height() * d-> imageAspectRatio);
d->destRect = QRect((width()-w)/2, 0, w, height());
}
d->maxPos = d->destRect.width() * d->destRect.height();
}
| C++ |
// Copyright (c) 2013 Oliver Lau <ola@ct.de>, Heise Zeitschriften Verlag
// All rights reserved.
#ifndef __MAINWINDOW_H_
#define __MAINWINDOW_H_
#include <QtCore/QDebug>
#include <QMainWindow>
#include <QScopedPointer>
#include "imagewidget.h"
namespace Ui {
class MainWindow;
}
enum Algorithm {
ALGORITHM_NONE = -1,
ALGORITHM_ZERO = 0,
ALGORITHM_ONE = 1,
ALGORITHM_XOR
};
class MainWindowPrivate;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = NULL);
virtual ~MainWindow();
private: // methods
void saveSettings(void);
void restoreSettings(void);
private: // variables
Ui::MainWindow *ui;
QScopedPointer<MainWindowPrivate> d_ptr;
Q_DECLARE_PRIVATE(MainWindow)
Q_DISABLE_COPY(MainWindow)
protected:
void keyPressEvent(QKeyEvent*);
void closeEvent(QCloseEvent*);
private slots:
void setImage(const QImage&);
bool openImage(const QString &filename);
void openImage(void);
void saveImageAs(void);
void updateImageWidget(void);
void positionChanged(int, int);
void singleBitModeChanged(bool);
void setAlgorithm(Algorithm a = ALGORITHM_NONE);
void copyToClipboard(void);
void pasteFromClipboard(void);
void about(void);
void aboutQt(void);
};
#endif // __MAINWINDOW_H_
| C++ |
// Copyright (c) 2013 Oliver Lau <ola@ct.de>, Heise Zeitschriften Verlag
// All rights reserved.
#include "mainwindow.h"
#include "qlitchapplication.h"
int main(int argc, char *argv[])
{
QlitchApplication a(argc, argv);
qApp->addLibraryPath("plugins");
qApp->addLibraryPath("./plugins");
qApp->addLibraryPath(".");
#ifdef Q_OS_MAC
qApp->addLibraryPath("../plugins");
#endif
QTranslator translator;
bool ok = translator.load(":/translations/qlitch_" + QLocale::system().name());
#ifndef QT_NO_DEBUG
if (!ok)
qWarning() << "Could not load translations for" << QLocale::system().name() << "locale";
#endif
if (ok)
a.installTranslator(&translator);
MainWindow w;
w.show();
return a.exec();
}
| C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.