/* CTF 1.8 */

typealias integer { size = 32; align = 32; signed = true; } := int;
typealias integer { size = 32; align = 32; signed = false; } := uint;
typealias integer { size = 64; align = 64; signed = true; } := long;
typealias integer { size = 64; align = 64; } := unsigned long;

enum name1 : int {
  ZERO,
  ONE,
  TWO,
  TEN = 10,
  ELEVEN,
};

enum name2 : long { ONE, TWO };

enum name3 : unsigned long { ONE, TWO };

enum name4 : unsigned long {
  string          = 1 ... 2,
  "other string"      = 3...4,
  yet_another_string,   /* will be assigned to end_value2 + 1 */
  "some other string" = 10,
};

enum name5 : long { "int" = 1, };

enum name6 { "int" = 1, };

typealias floating_point {
  exp_dig = 8;         /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */
  mant_dig = 24;       /* FLT_MANT_DIG */
  byte_order = native;
} := float;

typealias integer {
  size = 32;
  align = 32;
  signed = false;
} := struct page *;

struct event_packet_header {
  typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
  typealias integer { size = 8; align = 8; signed = false; } := uint8_t;

  uint32_t magic;
  uint8_t  uuid[16];
  uint32_t stream_id;
};

trace {
	major = 66;
	minor = 2;
	byte_order = le;
	uuid = "1123fcea-706e-11e0-a38b-f3c28a683a3d";
	packet.header := struct event_packet_header;
};

stream {
  typealias integer { size = 64; align = 64; signed = false; } := uint64_t;
  typealias integer { size = 16; align = 16; signed = false; } := uint16_t;
  typealias integer { size = 32; align = 32; signed = true; } := int;
  typedef int pid_t;

  id = 5;
  /* Type 1 - Few event IDs; Type 2 - Many event IDs. See section 6.2. */
  event.header := struct { uint64_t timestamp; uint16_t id; };
  event.context := struct { pid_t pid; };
};

struct example {
  /* TODO gcc bitfields not supported yet. */
  /* short a:12;
  short b:5; */
};

struct name {
  typealias integer { size = 64; align = 64; signed = false; } := uint64_t;
  typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
  typealias integer { size = 32; align = 32; signed = true; } := int32_t;
  typealias integer { size = 2; align = 8; signed = false; } := uint2_t;
  typealias integer { size = 16; align = 16; signed = true; } := short;
  typealias uint32_t := unsigned int;

  enum : uint2_t { a, b, c, d } choice;
  /* Unrelated fields can be added between the variant and its tag */
  int32_t somevalue;
  variant <choice> {
    uint32_t a;
    uint64_t b;
    short c;
    struct {
      unsigned int field1;
      uint64_t field2;
    } d;
  } s;
};

typealias integer {
  size = 32;
  signed = false;
  align = 32;
} := uint32_t;

typealias string { encoding = UTF8; } := test;

struct event_packet_context {
  typealias integer { size = 64; align = 64; signed = false; } := uint64_t;
  typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
  typealias integer { size = 16; align = 16; signed = false; } := uint16_t;
  typealias integer { size = 8; align = 8; signed = false; } := uint8_t;

  uint64_t timestamp_begin;
  uint64_t timestamp_end;
  uint32_t checksum;
  uint32_t stream_packet_count;
  uint32_t events_discarded;
  uint32_t cpu_id;
  uint16_t content_size;
  uint16_t packet_size;
  uint8_t  stream_packet_count_bits;    /* Significant counter bits */
  uint8_t  compression_scheme;
  uint8_t  encryption_scheme;
  uint8_t  checksum_scheme;
};

struct event_header_1 {
  typealias integer { size = 64; align = 64; signed = false; } := uint64_t;
  typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
  typealias integer { size = 5; align = 1; signed = false; } := uint5_t;
  typealias integer { size = 27; align = 1; signed = false; } := uint27_t;

  /*
   * id: range: 0 - 30.
   * id 31 is reserved to indicate an extended header.
   */
  enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
  variant <id> {
    struct {
      uint27_t timestamp;
    } compact;
    struct {
      uint32_t id;                       /* 32-bit event IDs */
      uint64_t timestamp;                /* 64-bit timestamps */
    } extended;
  } v;
};

struct event_header_2 {
  typealias integer { size = 64; align = 64; signed = false; } := uint64_t;
  typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
  typealias integer { size = 16; align = 16; signed = false; } := uint16_t;

  /*
   * id: range: 0 - 65534.
   * id 65535 is reserved to indicate an extended header.
   */
  enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
  variant <id> {
    struct {
      uint32_t timestamp;
    } compact;
    struct {
      uint32_t id;                       /* 32-bit event IDs */
      uint64_t timestamp;                /* 64-bit timestamps */
    } extended;
  } v;
};

typedef int rootscopetest;

/* parser level only: event { a.b.c.d.e = f.g.h->i->j; }; */

event {
	name = test_event;
	id = 0;
	stream_id = 5;
	context := struct {};
	fields := struct {};
};

typealias integer { size = 32; align = 32; signed = false; } := unsigned long long *;

variant vardecl {
	int a;
	int b;
};

event {
	typealias integer { size = 8; align = 8; signed = true; } := char;
	typealias integer { size = 32; align = 32; signed = false; } := unsigned int;

	name = test_event2;
	id = 1;
	stream_id = 5;
	fields := struct {
		enum : char { a = 0, b = 1, } tag;
		variant vardecl <tag> myvariant;
		unsigned int seqlen;
		int myseq[seqlen];
	};
};

typedef int myarray[10];
