Skip to content

Commit

Permalink
Fixing scope on parameters, plus some indents. Adding "adhoc_isset_ar…
Browse files Browse the repository at this point in the history
…ray".
  • Loading branch information
pieman72 committed Nov 30, 2014
1 parent ad8a725 commit c3a1664
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions adhoc.h
Expand Up @@ -554,6 +554,10 @@ void adhoc_insertNode(ASTnode* n){
// Determine the node's scope
if(parent->which==ACTION_DEFIN){
adhoc_assignScope(n, parent);
}else if(parent->childType == PARAMETER
&& parent->parentId
){
adhoc_assignScope(n, parent->parent->scope);
}else if(parent->scope){
adhoc_assignScope(n, parent->scope);
}
Expand Down
25 changes: 24 additions & 1 deletion c.h
Expand Up @@ -319,7 +319,10 @@ void lang_c_generate_action(bool isInit, bool defin, ASTnode* n, short indent, F
}

// Indent this function call
if(n->childType == STATEMENT) lang_c_indent(indent, outFile);
if(n->childType == STATEMENT
|| n->childType == IF
|| n->childType == ELSE
) lang_c_indent(indent, outFile);

// Special handling for library functions
if(!strcmp(n->package, "System")){
Expand Down Expand Up @@ -594,6 +597,26 @@ void lang_c_generate_action(bool isInit, bool defin, ASTnode* n, short indent, F
}
fprintf(outFile, "%s(", n->name);

// isset array - checks whether an index is used in an array
}else if(!strcmp(n->name, "adhoc_isset_array")){
if(n->children[0]->dataType != TYPE_ARRAY){
adhoc_errorNode = n->children[0];
sprintf(
errBuf
,"Node %d: First parameter to 'isset array' must be an array"
,n->children[0]->id
);
}
if(n->children[1]->dataType != TYPE_INT){
adhoc_errorNode = n->children[1];
sprintf(
errBuf
,"Node %d: Array indices must be strings"
,n->children[1]->id
);
}
fprintf(outFile, "%s(", n->name);

// append to array - pushes second arg onto the end of the first
}else if(!strcmp(n->name, "adhoc_append_to_array")){
if(n->children[0]->dataType != TYPE_ARRAY){
Expand Down
13 changes: 11 additions & 2 deletions libadhoc.c
Expand Up @@ -187,9 +187,9 @@ void* adhoc_getData(adhoc_data* d){
// Get the simple data at a particular index of an array
void* adhoc_getSArrayData(adhoc_data* arr, int i){
// TODO: Throw warning instead of returning 0
// If the index is beyond the bounds of the array, return 0
// If the index is beyond the bounds of the array, return NULL
if(i >= arr->sizeData) return NULL;
// If the field is unset, return 0
// If the field is unset, return NULL
if(!(arr->mappedData[i/DATA_MAP_BIT_FIELD_SIZE]
& (1<<(i%DATA_MAP_BIT_FIELD_SIZE)))
) return NULL;
Expand Down Expand Up @@ -649,6 +649,15 @@ int adhoc_find_in_string(adhoc_data* baseString, adhoc_data* targetsString){
}

//-- ARRAYS --//
// Check whether arr[i] has been set
bool adhoc_isset_array(adhoc_data* arr, int i){
// If the index is beyond the bounds of the array, return false
if(i >= arr->sizeData) return false;
// Return whether the field is set
return (arr->mappedData[i/DATA_MAP_BIT_FIELD_SIZE]
& (1<<(i%DATA_MAP_BIT_FIELD_SIZE)));
}

// Append one item to an existing array
void adhoc_append_to_array(char* format, adhoc_data* baseArray, ...){
adhoc_referenceData(baseArray);
Expand Down
3 changes: 3 additions & 0 deletions libadhoc.h
Expand Up @@ -113,6 +113,9 @@ adhoc_data* adhoc_splice_string(adhoc_data* baseString, adhoc_data* replacement,
// Finds the first occurrence of targetsString in baseString
int adhoc_find_in_string(adhoc_data* baseString, adhoc_data* targetsString);

// Check whether arr[i] has been set
bool adhoc_isset_array(adhoc_data* arr, int i);

// Append one item to an existing array
void adhoc_append_to_array(char* format, adhoc_data* baseArray, ...);

Expand Down
Binary file modified programs/array_suite.adh
Binary file not shown.
Binary file modified programs/if_else.adh
Binary file not shown.
Binary file added programs/library_tests.adh
Binary file not shown.
Binary file modified programs/quicksort.adh
Binary file not shown.
Binary file modified programs/test.adh
Binary file not shown.

0 comments on commit c3a1664

Please sign in to comment.