Module: CType

Defined in:
lib/dbc/ctype.rb,
lib/dbc/ctype.rb

Overview

Module

Defined Under Namespace

Modules: BaseReference, Qualifiers, Specifiers Classes: Base, Enum, EvaluationError, List, Parser, Pointer, Primitive, Struct, StructUnion, Type, Union

Constant Summary collapse

@@typedefs =
{}

Class Method Summary collapse

Class Method Details

.[](val) ⇒ Object



62
63
64
# File 'lib/dbc/ctype.rb', line 62

def CType.[](val)
	@@typedefs[val]
end

.[]=(val, new_val) ⇒ Object

Raises:

  • (ParseError)


70
71
72
73
74
# File 'lib/dbc/ctype.rb', line 70

def CType.[]=(val, new_val)
	raise "expecting a String got #{val.class}" if val.class != String
	raise ParseError, "type #{val} already defined" if @@typedefs.include?(val)
	@@typedefs[val] = new_val
end

.evaluation_error(part) ⇒ Object

Raises:



38
39
40
# File 'lib/dbc/ctype.rb', line 38

def CType.evaluation_error(part)
	raise EvaluationError, "cannot evaluate '#{part}'"
end

.include?(val) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/dbc/ctype.rb', line 66

def CType.include?(val)
	@@typedefs.include?(val)
end

.parse(source) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dbc/ctype.rb', line 43

def CType.parse(source)
	tokens = CTokenizer::SkipMacros.new(source)
	ctype_parser = Parser.new()

	until tokens.empty?
		results = ctype_parser.parse(tokens)
		until tokens.scope == 0 or tokens.empty?
			# get back to group zero
			tokens.shift
		end
		if results
			results = [results] unless results.class == Array
			results.each do |t|
				@@typedefs[t.to_s] = t if t.typedef?
			end
		end
	end
end