Class: RMasm::Report

Inherits:
Object show all
Defined in:
lib/rmasm/align.rb,
lib/rmasm/binio.rb,
lib/rmasm/report.rb,
lib/rmasm/struct.rb,
lib/rmasm/stacker.rb,
lib/rmasm/data_core.rb,
lib/rmasm/data_primitive.rb,
lib/rmasm/report_error_codes.rb

Overview

Add errors for align.

Defined Under Namespace

Classes: Message

Constant Summary collapse

R1001 =
"Invalid align value type [%s]. Must be an Integer"
R1012 =
"Invalid align value [%s]. Expecting value to be [%s]"
R5002 =
"Invalid default binary io value [%s]. The default value must be :little or :big"
REPORT_FORMATS =
[:ruby, :vs, :object]
RMASM_FILES =

Use a static version in order to work under rawr-jruby

["rmasm/align\\.rb", "rmasm/assembler\\.rb", "rmasm/bincoff\\.rb", "rmasm/binio\\.rb", "rmasm/core_override\\.rb", "rmasm/data\\.rb", "rmasm/data_core\\.rb", "rmasm/data_primitive\\.rb", "rmasm/data_struct\\.rb", "rmasm/data_type\\.rb", "rmasm/directive\\.rb", "rmasm/error\\.rb", "rmasm/expression\\.rb", "rmasm/extern\\.rb", "rmasm/instruction\\.rb", "rmasm/label\\.rb", "rmasm/modifier\\.rb", "rmasm/primitive\\.rb", "rmasm/register\\.rb", "rmasm/report\\.rb", "rmasm/report_error_codes\\.rb", "rmasm/section\\.rb", "rmasm/stacker\\.rb", "rmasm/struct\\.rb", "rmasm/symbol_manager\\.rb", "rmasm/utility\\.rb", "rmasm/x86/x86_assembler\\.rb", "rmasm/x86/x86_instruction_set\\.rb"]
W2001 =
"Cannot declare a struct outside a module/class (Unexpected owner : [%s])"
R2002 =
"Cannot change alignment for struct [%s] once it is defined. Current value is [%s]"
R2012 =
"Invalid struct name type [%s:%s]. Expecting a :SymbolName"
R2021 =
"Invalid struct name [%s]. Must start with a uppercase letter and must contain only [a-zA-Z_0-9]"
R2031 =
"Invalid parent class [%s] for struct [%s]. Parent struct class must be a struct"
R2041 =
"Invalid parent class [%s]. Cannot inherit from a parent class that is being declared (nested struct cannot inherit from declaring struct"
R2052 =
"Invalid field [%s] in struct [:%s] definition. Expecting symbol with :your_symbol"
R2062 =
"Invalid field [%s] in struct [:%s] definition. Field is already declared or used by keywords"
R2071 =
"Nested struct reference [%s] does not exist"
R2081 =
"Unable to use struct [%s]. This struct contains declaration errors."
R2092 =
"Invalid field name [:%s] in struct [%s]. This field does not exist"
R20A1 =
"Cannot use struct [%s] inside itself"
R20B2 =
"Unable to find reference to struct/method [%s] inside struct [%s]"
R20C2 =
"Struct [%s] cannot inherit from struct [%s]. This struct contains declaration errors."
R20D1 =
"Unable to initialize field [%s] inside struct [%s]"
R20E2 =
"Unable to access field or method [:%s] in the following struct path [%s]"
R20F2 =
"#{R20E2}. The last field is a primitive"
R20G3 =
"Invalid use of an array index [%s] in struct path [%s]. The field [%s] is not an array"
R20H2 =
"Array index [%s] in struct path [%s] must be a constant number"
R20I3 =
"Array index [%s] is out of array index range [%s] in struct path [%s]"
R20J3 =
"Invalid array size [%s] for field [%s] in struct [%s]. Array size must be an integer >= 0"
R20K3 =
"Invalid field index [%s] for struct [%s]. Must be in the range [%s]"
R20L3 =
"Cannot add field [%s] to struct [%s] because last field [%s] contains a variable array"
R20M3 =
"Unable to reference struct [%s] inside struct [%s]. Struct [%s] contains declaration errors"
R20N3 =
"Cannot add array field [%s] to struct [%s] because this field type contains a variable array in [%s]"
R20O2 =
"Invalid field name [:%s] in struct [:%s] definition. Must start with [_A-Za-z], followed by [_A-Za-z0-9]+ and an optional [? or !] character"
R20P1 =
"Invalid struct name [%s]. A structure/class/module/constant with the same name already exist in this scope"
R20Q2 =
"Invalid parent class with symbol [%s] for struct [%s]. Parent struct class does not exist"
R20R0 =
"Invalid field declaration. This field cannot be nil"
R3001 =
"Cannot pop top level value from %s"
R4002 =
"Invalid default value [%s]. The default value must be a byte in the range[%s]"
R4011 =
"Invalid array size declaration [%s]. Expecting only one association [size => default_value]"
R4022 =
"Invalid array size [%s] in [%s]. Array size must be a positive integer"
R4033 =
"Invalid array default value [%s] for type [%s]. Default value must be in the range [%s]"
R4041 =
"Invalid array size [%s]. Array size is empty"
R4053 =
"Invalid value type [%s] for data declaration for [%s] with value [%s]"
R4062 =
"Invalid array default value [%s] for structure [%s]. Default value must be a byte"
R4A03 =
"Invalid value [%s] for type [%s]. Value must be in the range [%s]"
R4A14 =
"Unexpected datatype [%s] with value [%s]. Value must be [%s] in the range [%s]"
R4A23 =
"Unexpected datatype [%s] with value [%s]. No conversion is available from a string to the type [%s]"
R4A33 =
"Index out of range [%s] in Hash declaration for datatype [%s] with array size [%s]"
R4A43 =
"Invalid range index [%s] for datatype [%s] The range index begin...end must be integers"
R4A53 =
"Range index out of range [%s] in range [%s] for hash declaration with datatype [%s] and array size [%s]"
R4A63 =
"Unexpected key [%s] in hash declaration for datatype [%s] with array size [%s]. Valid keys are number and range"
R4A72 =
"Invalid initialization value [%s] for datatype [%s]. Expecting single value"
R4A83 =
"Out of range initialization for array datatype [%s]. Maximum number of values expected is [%s]. Current is [%s]"
R4A94 =
"Initialization from hash failed with value [%s]. Length of string [%s] must be equal to the sizeof destination datatype [%s,%s]"
R0013 =
"Invalid number of arguments [%d] instead of [%s] for [%s] instruction"
ARGS =
R0013
R0021 =
"Expecting only one integer value in [] declaration for symbol [:%s]"
R0031 =
"Error while declaring label [:%s]. Expecting :symbol "
R0041 =
"Size array must be a constant for symbol :%s"
R0053 =
"Nested [%s] for [%s] is not allowed inside a [%s] declaration"
R0061 =
"Expecting body (do .... end) for [%s]"
BLOCK_BODY =
R0061
R00B1 =
"Invalid data declaration. Data [:%s] must be followed by arguments"
R00C1 =
"Invalid size [%d] for alignement. Possible values are [%s]"
R00D1 =
"Invalid value [%s] for alignement."
R00E1 =
"Unexpected declaration in section [:%s]. Expecting :symbol for name "
R00F1 =
"Cannot close the section [%s]. This section is being defined in a block do ... end and cannot be closed inside this block"
R00G1 =
"section.end failed. This command can only be used inside an opened section."
@@report_format =
:ruby
@@log =
[]

Class Method Summary collapse

Class Method Details

.error(*args) ⇒ Object



64
65
66
# File 'lib/rmasm/report.rb', line 64

def self.error(*args)
  send_message(:error, *args)
end

.logObject



68
69
70
# File 'lib/rmasm/report.rb', line 68

def self.log()
  @@log
end

.report_format(type) ⇒ Object



59
60
61
62
# File 'lib/rmasm/report.rb', line 59

def self.report_format(type)
  raise "Format [#{type}] not supported [%s]" % (REPORT_FORMATS * ",") if ! REPORT_FORMATS.include?(type)
  @@report_format = type
end

.send_message(msg_type, *args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rmasm/report.rb', line 76

def self.send_message(msg_type, *args)
  exception = nil

  error_code = :R0000

  # Check if first arg is a symbol
  if args[0].is_a?(Symbol)
    # if yes, use error_code system
    error_code = args[0]
    exception = self.const_get(args[0])
    args = args[1..-1]
    exception = exception % args
  else
    exception = args[0]
  end

  backtrace = nil
  message = ""
  if exception.is_a?(String)
    message = exception
  elsif exception.is_a?(Exception)
    backtrace = exception.backtrace
    message = "#{exception.class.name} #{exception.message}"
  else
    raise ArgumentError.new("Invalid argument #{exception}. Must be a string or an exception")
  end

  if backtrace.nil?
    backtrace = caller
  end

#      backtrace_str = exception.backtrace * "\n"
#      puts "Backtrace #{backtrace_str}"

  found_error = []

  filename_to_find = nil
  if ! Assembler.file_includes.empty?
    filename_to_find = Regexp.escape( Assembler.file_includes[-1] )
  end

  # Find first include_rasm_file to log the error on the correct line
  # if no include is found, than log an error on the first stack trace

  backtrace.each do |trace|
    # If we are inside an include "...rasm", then look for the first include to report a correct error
    if !filename_to_find.nil?
      match = trace.match(/(.*#{filename_to_find}):(\d+)(.*)/)
      if ! match.nil?
        found_error = [match[1], match[2]]
        break
      end
    else
      # else try to report an error on the first file that is not a rmasm file
      found_rmasm_file = false
      for rmasm_file in RMASM_FILES
        match = trace.match(/(.*#{rmasm_file}):(\d+)(.*)/)
        if !match.nil?
          found_rmasm_file = true
          break
        end
      end

      # If no rmasm file
      if !found_rmasm_file
        match = trace.match(/(.*):(\d+)(.*)/)
        if ! match.nil?
          found_error = [match[1], match[2]]
          break
        end
      end
    end
  end

  # Should not happen but who knows?
  if found_error.empty?
    trace = backtrace[0]
    match = trace.match(/(.*):(\d+)(.*)/)
    found_error = [$1, $2]
  end

  error_object = Message.new(msg_type, error_code, message)
  case @@report_format
    when :ruby
      STDERR.puts "#{found_error[0]}:#{found_error[1]}: #{msg_type} #{error_code}: #{message} "
    when :vs
      STDERR.puts "#{found_error[0]}(#{found_error[1]}) : #{msg_type} #{error_code}: #{message} "
    when :object
      @@log << error_object
  end

  # Log all errors in RMasm object
  if !$rmasm.nil?
    $rmasm.errors << error_object
  end

  nil
end

.warning(*args) ⇒ Object



72
73
74
# File 'lib/rmasm/report.rb', line 72

def self.warning(*args)
  send_message(:warning, *args)
end