Class: BOAST::Expression
Instance Attribute Summary collapse
-
#operand1 ⇒ Object
readonly
Returns the value of attribute operand1.
-
#operand2 ⇒ Object
readonly
Returns the value of attribute operand2.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Class Method Summary collapse
Instance Method Summary collapse
- #! ⇒ Object
- #*(x) ⇒ Object
- #+(x) ⇒ Object
- #-(x) ⇒ Object
- #-@ ⇒ Object
- #/(x) ⇒ Object
- #<(x) ⇒ Object
- #==(x) ⇒ Object
- #===(x) ⇒ Object
- #>(x) ⇒ Object
- #>=(x) ⇒ Object
- #dereference ⇒ Object
-
#initialize(operator, operand1, operand2) ⇒ Expression
constructor
A new instance of Expression.
- #print(final = true) ⇒ Object
- #struct_reference(x) ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #to_var ⇒ Object
Constructor Details
#initialize(operator, operand1, operand2) ⇒ Expression
Returns a new instance of Expression.
211 212 213 214 215 |
# File 'lib/BOAST/Algorithm.rb', line 211 def initialize(operator, operand1, operand2) @operator = operator @operand1 = operand1 @operand2 = operand2 end |
Instance Attribute Details
#operand1 ⇒ Object (readonly)
Returns the value of attribute operand1.
209 210 211 |
# File 'lib/BOAST/Algorithm.rb', line 209 def operand1 @operand1 end |
#operand2 ⇒ Object (readonly)
Returns the value of attribute operand2.
210 211 212 |
# File 'lib/BOAST/Algorithm.rb', line 210 def operand2 @operand2 end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
208 209 210 |
# File 'lib/BOAST/Algorithm.rb', line 208 def operator @operator end |
Class Method Details
.parens(*args, &block) ⇒ Object
204 205 206 |
# File 'lib/BOAST/Algorithm.rb', line 204 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#! ⇒ Object
264 265 266 |
# File 'lib/BOAST/Algorithm.rb', line 264 def ! return Expression::new("!",nil,self) end |
#*(x) ⇒ Object
244 245 246 |
# File 'lib/BOAST/Algorithm.rb', line 244 def *(x) return Expression::new("*",self,x) end |
#+(x) ⇒ Object
228 229 230 |
# File 'lib/BOAST/Algorithm.rb', line 228 def +(x) return Expression::new("+",self,x) end |
#-(x) ⇒ Object
260 261 262 |
# File 'lib/BOAST/Algorithm.rb', line 260 def -(x) return Expression::new("-",self,x) end |
#-@ ⇒ Object
268 269 270 |
# File 'lib/BOAST/Algorithm.rb', line 268 def -@ return Expression::new("-",nil,self) end |
#/(x) ⇒ Object
248 249 250 |
# File 'lib/BOAST/Algorithm.rb', line 248 def /(x) return Expression::new("/",self,x) end |
#<(x) ⇒ Object
236 237 238 |
# File 'lib/BOAST/Algorithm.rb', line 236 def <(x) return Expression::new("<",self,x) end |
#==(x) ⇒ Object
224 225 226 |
# File 'lib/BOAST/Algorithm.rb', line 224 def ==(x) return Expression::new("==",self,x) end |
#===(x) ⇒ Object
220 221 222 |
# File 'lib/BOAST/Algorithm.rb', line 220 def ===(x) return Expression::new("=",self,x) end |
#>(x) ⇒ Object
232 233 234 |
# File 'lib/BOAST/Algorithm.rb', line 232 def >(x) return Expression::new(">",self,x) end |
#>=(x) ⇒ Object
240 241 242 |
# File 'lib/BOAST/Algorithm.rb', line 240 def >=(x) return Expression::new(">=",self,x) end |
#dereference ⇒ Object
252 253 254 |
# File 'lib/BOAST/Algorithm.rb', line 252 def dereference return Expression::new("*",nil,self) end |
#print(final = true) ⇒ Object
322 323 324 325 326 327 328 329 |
# File 'lib/BOAST/Algorithm.rb', line 322 def print(final=true) s="" s += " "*BOAST::get_indent_level if final s += self.to_str s += ";" if final and [C, CL, CUDA].include?( BOAST::get_lang ) BOAST::get_output.puts s if final return s end |
#struct_reference(x) ⇒ Object
256 257 258 |
# File 'lib/BOAST/Algorithm.rb', line 256 def struct_reference(x) return Expression::new(".",self,x) end |
#to_s ⇒ Object
216 217 218 |
# File 'lib/BOAST/Algorithm.rb', line 216 def to_s self.to_str end |
#to_str ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/BOAST/Algorithm.rb', line 291 def to_str op1 = nil op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var) op2 = nil op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var) if op1 and op2 then r_t, oper = BOAST::transition(op1, op2, @operator) else oper = @operator end op1 = @operand1 if not op1 op2 = @operand2 if not op2 s = "" if op1 then s += "(" if (oper == "*" or oper == "/") s += op1.to_s s += ")" if (oper == "*" or oper == "/") end s += " " unless oper == "++" or oper == "." s += oper s += " " unless oper == "." or oper == "&" or ( oper == "*" and op1.nil? ) if op2 then s += "(" if (oper == "*" or oper == "/" or oper == "-") s += op2.to_s s += ")" if (oper == "*" or oper == "/" or oper == "-") end return s end |
#to_var ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/BOAST/Algorithm.rb', line 272 def to_var op1 = nil op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var) op2 = nil op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var) res_exp = Expression::new(@operator, op1.nil? ? @operand1 : op1, op2.nil? ? @operand2 : op2) if op1 and op2 then r_t, oper = BOAST::transition(op1, op2, @operator) return r_t.copy("#{res_exp}", :const => nil, :constant => nil) elsif op1 return op1.copy("#{res_exp}", :const => nil, :constant => nil) elsif op2 return op2.copy("#{res_exp}", :const => nil, :constant => nil) else STDERR.puts "#{@operand1} #{@operand2}" raise "Expression on no operand!" end end |