Class: C::FunctionDef

Inherits:
Object
  • Object
show all
Defined in:
lib/csquare.rb

Overview

Add helper functions to CAST’s C module.

Instance Method Summary collapse

Instance Method Details

#has_local?(var, blueprint = nil) ⇒ Boolean

Does some local exist at the base scope?

Returns:

  • (Boolean)


280
281
282
283
284
# File 'lib/csquare.rb', line 280

def has_local? var, blueprint=nil
  h = params.has_key?(var) || self.def.locals.has_key?(var)
  h = blueprint.externs.has_key?(var) || blueprint.generator.externs.has_key?(var) if !h && !blueprint.nil?
  h
end

#params(as = nil) ⇒ Object

Get function parameters.



275
276
277
# File 'lib/csquare.rb', line 275

def params(as=nil)
  self.type.to_h(as)
end

#type_of(var, blueprint = nil) ⇒ Object

Determine the type of some variable declared in this scope.



287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/csquare.rb', line 287

def type_of var, blueprint=nil
  t = params[var] || self.def.locals[var]
  t = blueprint.externs[var] || blueprint.generator.externs[var] if t.nil? && !blueprint.nil?
  return nil if t.nil?

  if t.is_a?(C::Type)
    t = t.clone      # return a copy, which should be marked as non-const
    t.const = false
  end

  t
end