Replace ast::as calls with visitor, added result struct to common.