rust/src/test/run-pass/issue-2804.rs
Tim Chevalier 78ec6fe30c Obliterate the callee_id hack
Exprs that could be applications of overloaded operators
(expr_unary, expr_binary, expr_index) relied on the previous node ID
being "reserved" to carry extra typechecking info. This was
incredibly error-prone. Fixed it; now all exprs have two node IDs
(which will be wasted in some cases; future work could make this
an option instead if the extra int field ends up being a performance
problem).

Closes #2804
2012-07-12 19:02:07 -07:00

70 lines
1.5 KiB
Rust

use std;
import io;
import io::writer_util;
import std::map::hashmap;
enum object
{
bool_value(bool),
int_value(i64),
}
fn lookup(table: std::map::hashmap<str, std::json::json>, key: str, default: str) -> str
{
alt table.find(key)
{
option::some(std::json::string(s))
{
*s
}
option::some(value)
{
#error["%s was expected to be a string but is a %?", key, value];
default
}
option::none
{
default
}
}
}
fn add_interface(store: int, managed_ip: str, data: std::json::json) -> (str, object)
{
alt data
{
std::json::dict(interface)
{
let name = lookup(interface, "ifDescr", "");
let label = #fmt["%s-%s", managed_ip, name];
(label, bool_value(false))
}
_
{
#error["Expected dict for %s interfaces but found %?", managed_ip, data];
("gnos:missing-interface", bool_value(true))
}
}
}
fn add_interfaces(store: int, managed_ip: str, device: std::map::hashmap<str, std::json::json>) -> [(str, object)]/~
{
alt device["interfaces"]
{
std::json::list(interfaces)
{
do vec::map(*interfaces) |interface| {
add_interface(store, managed_ip, interface)
}
}
_
{
#error["Expected list for %s interfaces but found %?", managed_ip, device["interfaces"]];
[]/~
}
}
}
fn main() {}