class Metasm::C::Case

Attributes

expr[RW]
exprup[RW]

Public Class Methods

dump_indent(s, short=false) click to toggle source
# File metasm/parse_c.rb, line 3910
def self.dump_indent(s, short=false)
        case s
        when /^(case|default)\W/; CRenderString.new(short ? '    ' : "\t") << s
        when /^\s+(case|default)\W/; CRenderString.new("\t") << s
        when /:$/; s
        else CRenderString.new("\t") << s
        end
end
new(expr, exprup, statement) click to toggle source
# File metasm/parse_c.rb, line 918
def initialize(expr, exprup, statement)
        @expr, @statement = expr, statement
        @exprup = exprup if exprup
end
parse(parser, scope, nest) click to toggle source
# File metasm/parse_c.rb, line 923
def self.parse(parser, scope, nest)
        raise parser, 'invalid case' if not expr = CExpression.parse(parser, scope) or not expr.constant? or not expr.type.integral?
        raise tok || parser, '":" or "..." expected' if not tok = parser.skipspaces or tok.type != :punct or (tok.raw != ':' and tok.raw != '.')
        if tok.raw == '.'
                raise tok || parser, '".." expected' if not tok = parser.skipspaces or tok.type != :punct or tok.raw != '.'
                raise tok || parser,  '"." expected' if not tok = parser.skipspaces or tok.type != :punct or tok.raw != '.'
                raise tok, 'invalid case range' if not exprup = CExpression.parse(parser, scope) or not exprup.constant? or not exprup.type.integral?
                raise tok || parser, '":" expected' if not tok = parser.skipspaces or tok.type != :punct or tok.raw != ':'
        end
        body = parser.parse_statement scope, nest
        new expr, exprup, body
end

Public Instance Methods

dump(scope, r=[CRenderString.new], dep=[]) click to toggle source
# File metasm/parse_c.rb, line 3894
def dump(scope, r=[CRenderString.new], dep=[])
        case @expr
        when 'default'
                r.last << @expr
        else
                r.last << CRenderString.new(self, 'case ')
                r, dep = CExpression.dump(@expr, scope, r, dep)
                if exprup
                        r.last << ' ... '
                        r, dep = CExpression.dump(@exprup, scope, r, dep)
                end
        end
        r.last << ':'
        dump_inner(scope, r, dep)
end
precompile(compiler, scope) click to toggle source
Calls superclass method Metasm::C::Label#precompile
# File metasm/compile_c.rb, line 936
def precompile(compiler, scope)
        @expr = CExpression.precompile_inner(compiler, scope, @expr)
        @exprup = CExpression.precompile_inner(compiler, scope, @exprup) if exprup
        super(compiler, scope)
end