void statements(ast a, FILE * f) { int condn =0; Node temp_node; if(a->temp->children[0]==NULL) { while(!condn) { if(!strcmp(a->temp->info.token_name,"TK_STOP")) { return; } if(!strcmp(a->temp->info.token_name,"TK_ELSE")) { label=label+1; fprintf(f,"\tJMP Label %d\n",label); printf("\tJMP Label %d\n",label); fprintf(f,"\tLabel %d\n",label-1); printf("\t Label %d\n",label-1); } if(!strcmp(a->temp->info.token_name,"TK_ENDIF")) { fprintf(f,"\tLabel %d\n",label); printf("\tLabel %d\n",label); } if(a->temp->position_children+1<a->temp->parent->number_children) { a->temp=a->temp->parent->children[a->temp->position_children+1]; condn=1; } else { a->temp=a->temp->parent; } } statements(a,f); } else { if(!strcmp(a->temp->info.token_name,"inputst")||!strcmp(a->temp->info.token_name,"outputst")) { temp_node=a->temp; if(!strcmp(a->temp->children[0]->info.node_symbol,"TK_IP")) { if(f==NULL) { printf("ERROR FILE POINTER IS NULL\n"); } read_generation(a,f); } if(!strcmp(a->temp->children[0]->info.node_symbol,"TK_OP")) { if(f==NULL) { printf("ERROR FILE POINTER IS NULL\n"); } write_generation(a,f); } a->temp=temp_node; a->temp=a->temp->children[0]; } else if(!strcmp(a->temp->info.token_name,"TK_ASSIGN")) { temp_node=a->temp; assign_generation(a,f); a->temp=temp_node; a->temp=a->temp->children[0]; } else if(!strcmp(a->temp->info.token_name,"iteratst")) { temp_node=a->temp; iterat_generation(a,f); a->temp=temp_node; a->temp=a->temp->children[0]; } else if(!strcmp(a->temp->info.token_name,"selst")) { temp_node=a->temp; sel_generation(a,f); a->temp=temp_node; a->temp=a->temp->children[0]; } else { a->temp=a->temp->children[0]; } statements(a,f); } }
int main(int argc, char* argv[]) { // Parse command line arguments. if (! example_get_opts(argc, argv, EXAMPLE_BASIC_OPTS)) { exit(-1); } // Connect to the aerospike database cluster. aerospike as; example_connect_to_aerospike(&as); // Start clean. example_remove_test_record(&as); as_error err; // Create an as_record object with one (integer value) bin. By using // as_record_inita(), we won't need to destroy the record if we only set // bins using as_record_set_int64(). as_record rec; as_record_inita(&rec, 1); as_record_set_int64(&rec, TEST_BIN, 1001); // Log its contents. LOG("as_record object to write to database:"); example_dump_record(&rec); // Write the record to the database. If the record isn't already in the // database, it will be created with generation = 1. if (aerospike_key_put(&as, &err, NULL, &g_key, &rec) != AEROSPIKE_OK) { LOG("aerospike_key_put() returned %d - %s", err.code, err.message); example_cleanup(&as); exit(-1); } LOG("write succeeded"); uint16_t gen; // Read the record back, and get its generation. if (! read_generation(&as, &gen)) { example_cleanup(&as); exit(-1); } // Update the as_record object with a different bin value. In general it's // ok to do this - all as_record_set_... calls destroy any previous value. as_record_set_int64(&rec, TEST_BIN, 1002); // Set its generation equal to that of the record in the database. rec.gen = gen; // Require that the next write will only succeed if generations match. as_policy_write wpol; as_policy_write_init(&wpol); wpol.gen = AS_POLICY_GEN_EQ; // Log its contents. LOG("as_record object to write to database:"); example_dump_record(&rec); // Re-write the record in the database. The write should succeed, and // increment the generation. if (aerospike_key_put(&as, &err, &wpol, &g_key, &rec) != AEROSPIKE_OK) { LOG("aerospike_key_put() returned %d - %s", err.code, err.message); example_cleanup(&as); exit(-1); } LOG("re-write requiring generation = %u succeeded", rec.gen); // Read the record back, and get its generation. if (! read_generation(&as, &gen)) { example_cleanup(&as); exit(-1); } // Update the record object with a different bin value. as_record_set_int64(&rec, TEST_BIN, 1003); // Set its generation way past that of the record in the database. rec.gen = gen + 10; // Log its contents. LOG("as_record object to write to database:"); example_dump_record(&rec); // Try to re-write the record in the database. Use the same write policy, // requiring generations to match. This write should fail. if (aerospike_key_put(&as, &err, &wpol, &g_key, &rec) != AEROSPIKE_ERR_RECORD_GENERATION) { LOG("aerospike_key_put() returned %d - %s, expected " "AEROSPIKE_ERR_RECORD_GENERATION", err.code, err.message); example_cleanup(&as); exit(-1); } LOG("re-write requiring generation = %u failed as expected", rec.gen); // Now require that the next write will only succeed if the specified // generation is greater than that of the record in the database. wpol.gen = AS_POLICY_GEN_GT; // Log its contents. LOG("as_record object to write to database:"); example_dump_record(&rec); // Try again. This write should succeed, and increment the generation. (Note // that it does not write the record with the local generation!) if (aerospike_key_put(&as, &err, &wpol, &g_key, &rec) != AEROSPIKE_OK) { LOG("aerospike_key_put() returned %d - %s", err.code, err.message); example_cleanup(&as); exit(-1); } LOG("re-write requiring generation < %u succeeded", rec.gen); // Read the record back, and get its generation. if (! read_generation(&as, &gen)) { example_cleanup(&as); exit(-1); } // Cleanup and disconnect from the database cluster. example_cleanup(&as); LOG("generation example successfully completed"); return 0; }