Changeset c12b2ae in mainline for uspace/app/bithenge/transform.c
- Timestamp:
- 2012-08-07T05:00:41Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ad5c8a48
- Parents:
- a8be91a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.c
ra8be91a rc12b2ae 179 179 bithenge_scope_inc_ref(outer); 180 180 self->outer = outer; 181 self->barrier = false; 181 182 self->num_params = 0; 182 183 self->params = NULL; … … 202 203 } 203 204 205 /** Get the outer scope of a scope, which may be NULL. 206 * @param self The scope to examine. 207 * @return The outer scope, which may be NULL. */ 208 bithenge_scope_t *bithenge_scope_outer(bithenge_scope_t *self) 209 { 210 return self->outer; 211 } 212 204 213 /** Set the current node being created. Takes a reference to @a node. 205 214 * @param scope The scope to set the current node in. … … 211 220 bithenge_node_dec_ref(scope->current_node); 212 221 scope->current_node = node; 222 } 223 224 /** Set a scope as a barrier. 225 * @param self The scope to change. */ 226 void bithenge_scope_set_barrier(bithenge_scope_t *self) 227 { 228 self->barrier = true; 229 } 230 231 /** Check whether a scope is a barrier, meaning that variable lookup stops at 232 * it. 233 * @param self The scope to check. 234 * @return Whether the scope is a barrier. */ 235 bool bithenge_scope_is_barrier(bithenge_scope_t *self) 236 { 237 return self->barrier; 213 238 } 214 239 … … 277 302 bithenge_transform_t base; 278 303 bithenge_transform_t *transform; 279 } scope_transform_t;280 281 static inline scope_transform_t *transform_as_param(304 } barrier_transform_t; 305 306 static inline barrier_transform_t *transform_as_barrier( 282 307 bithenge_transform_t *base) 283 308 { 284 return ( scope_transform_t *)base;285 } 286 287 static inline bithenge_transform_t * param_as_transform(288 scope_transform_t *self)309 return (barrier_transform_t *)base; 310 } 311 312 static inline bithenge_transform_t *barrier_as_transform( 313 barrier_transform_t *self) 289 314 { 290 315 return &self->base; 291 316 } 292 317 293 static int scope_transform_apply(bithenge_transform_t *base,318 static int barrier_transform_apply(bithenge_transform_t *base, 294 319 bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out) 295 320 { 296 scope_transform_t *self = transform_as_param(base);321 barrier_transform_t *self = transform_as_barrier(base); 297 322 bithenge_scope_t *inner_scope; 298 323 int rc = bithenge_scope_new(&inner_scope, scope); 299 324 if (rc != EOK) 300 325 return rc; 326 bithenge_scope_set_barrier(inner_scope); 301 327 rc = bithenge_transform_apply(self->transform, scope, in, out); 302 328 bithenge_scope_dec_ref(inner_scope); … … 304 330 } 305 331 306 static int scope_transform_prefix_length(bithenge_transform_t *base,332 static int barrier_transform_prefix_length(bithenge_transform_t *base, 307 333 bithenge_scope_t *scope, bithenge_blob_t *in, aoff64_t *out) 308 334 { 309 scope_transform_t *self = transform_as_param(base); 310 return bithenge_transform_prefix_length(self->transform, scope, in, 311 out); 312 } 313 314 static void scope_transform_destroy(bithenge_transform_t *base) 315 { 316 scope_transform_t *self = transform_as_param(base); 335 barrier_transform_t *self = transform_as_barrier(base); 336 bithenge_scope_t *inner_scope; 337 int rc = bithenge_scope_new(&inner_scope, scope); 338 if (rc != EOK) 339 return rc; 340 bithenge_scope_set_barrier(inner_scope); 341 rc = bithenge_transform_prefix_length(self->transform, scope, in, out); 342 bithenge_scope_dec_ref(inner_scope); 343 return rc; 344 } 345 346 static int barrier_transform_prefix_apply(bithenge_transform_t *base, 347 bithenge_scope_t *scope, bithenge_blob_t *in, bithenge_node_t **out_node, 348 aoff64_t *out_length) 349 { 350 barrier_transform_t *self = transform_as_barrier(base); 351 bithenge_scope_t *inner_scope; 352 int rc = bithenge_scope_new(&inner_scope, scope); 353 if (rc != EOK) 354 return rc; 355 bithenge_scope_set_barrier(inner_scope); 356 rc = bithenge_transform_prefix_apply(self->transform, scope, in, 357 out_node, out_length); 358 bithenge_scope_dec_ref(inner_scope); 359 return rc; 360 } 361 362 static void barrier_transform_destroy(bithenge_transform_t *base) 363 { 364 barrier_transform_t *self = transform_as_barrier(base); 317 365 bithenge_transform_dec_ref(self->transform); 318 366 free(self); 319 367 } 320 368 321 static const bithenge_transform_ops_t scope_transform_ops = { 322 .apply = scope_transform_apply, 323 .prefix_length = scope_transform_prefix_length, 324 .destroy = scope_transform_destroy, 325 }; 326 327 /** Create a wrapper transform that creates a new outer scope. This ensures 328 * nothing from the transform's users is passed in, other than parameters. The 329 * wrapper may have a different value for num_params. Takes a reference to 330 * @a transform, which it will use for all operations. 369 static const bithenge_transform_ops_t barrier_transform_ops = { 370 .apply = barrier_transform_apply, 371 .prefix_length = barrier_transform_prefix_length, 372 .prefix_apply = barrier_transform_prefix_apply, 373 .destroy = barrier_transform_destroy, 374 }; 375 376 /** Create a wrapper transform that creates a new scope. This ensures nothing 377 * from the outer scope is passed in, other than parameters. The wrapper may 378 * have a different value for num_params. Takes a reference to @a transform, 379 * which it will use for all operations. 331 380 * @param[out] out Holds the created transform. 332 381 * @param transform The transform to wrap. 333 382 * @param num_params The number of parameters to require, which may be 0. 334 383 * @return EOK on success or an error code from errno.h. */ 335 int bithenge_new_ scope_transform(bithenge_transform_t **out,384 int bithenge_new_barrier_transform(bithenge_transform_t **out, 336 385 bithenge_transform_t *transform, int num_params) 337 386 { … … 340 389 341 390 int rc; 342 scope_transform_t *self = malloc(sizeof(*self));391 barrier_transform_t *self = malloc(sizeof(*self)); 343 392 if (!self) { 344 393 rc = ENOMEM; 345 394 goto error; 346 395 } 347 rc = bithenge_init_transform( param_as_transform(self),348 & scope_transform_ops, num_params);396 rc = bithenge_init_transform(barrier_as_transform(self), 397 &barrier_transform_ops, num_params); 349 398 if (rc != EOK) 350 399 goto error; 351 400 self->transform = transform; 352 *out = param_as_transform(self);401 *out = barrier_as_transform(self); 353 402 return EOK; 354 403 error:
Note:
See TracChangeset
for help on using the changeset viewer.