works?
This commit is contained in:
@ -57,19 +57,19 @@ Constant_Stack *Push(TableNode *type, void *value, bool isConst) {
|
||||
return cs;
|
||||
}
|
||||
|
||||
Context_stack *PushContext(int context, TableNode *typeToCompare) {
|
||||
if (context != 1 && context != 2 && context != 3 && context != 0) {
|
||||
Context_stack *PushContext(/*int context, */TableNode *typeToCompare) {
|
||||
/*if (context != 1 && context != 2 && context != 3 && context != 0) {
|
||||
printdebug(
|
||||
"invalid context passed in");
|
||||
return NULL;
|
||||
}
|
||||
}*/
|
||||
if(typeToCompare == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to PushContext. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
Context_stack *cs = (Context_stack *)calloc(1,sizeof(Context_stack));
|
||||
cs->con = context;
|
||||
//cs->con = context;
|
||||
cs->typeToCompare = typeToCompare;
|
||||
if (context_head == NULL) {
|
||||
context_head = cs;
|
||||
@ -107,7 +107,7 @@ Function_Stack *PushFunction(int arg, TableNode* FunctionType) {
|
||||
|
||||
Function_Stack *PopFunction() {
|
||||
if (function_head == NULL) {
|
||||
printf("cannot pop from an empty stack. Invalid.\n");
|
||||
printf("cannot pop from an empty stack from popfunction. Invalid.\n");
|
||||
return NULL;
|
||||
}
|
||||
Function_Stack *fs = function_head;
|
||||
@ -124,6 +124,78 @@ int getArgumentNumber(Function_Stack *fs) {
|
||||
return fs->arg;
|
||||
}
|
||||
|
||||
int getTotalNumberArguments(TableNode* function) {
|
||||
if (function == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to getTotalNumberArguments. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (getAdInfoType(function) != TYPE_FUNCTION_DECLARATION) {
|
||||
printdebug(
|
||||
"passed an invalid reference to getTotalNumberArguments. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
TableNode* functionType = getParameter(getTypeEntry(function));
|
||||
if(functionType != undefined){
|
||||
return -1;
|
||||
}
|
||||
if(getAdInfoType(functionType) != TYPE_RECORD_TYPE){
|
||||
return 1;
|
||||
}else{
|
||||
return getRecLength(functionType);
|
||||
}
|
||||
}
|
||||
|
||||
Function_Stack* setArgumentNumber(Function_Stack *fs, int arg) {
|
||||
if (fs == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to setArgumentNumber. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(arg<getTotalNumberArguments(fs->FunctionType)){
|
||||
//case where invalid argument number is being passed
|
||||
return NULL;
|
||||
}
|
||||
fs->arg = arg;
|
||||
return fs;
|
||||
}
|
||||
Function_Stack* setFunctionType(Function_Stack *fs, TableNode* functionType) {
|
||||
if (fs == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to setFunctionType. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (functionType == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to setFunctionType. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
fs->FunctionType = functionType;
|
||||
return fs;
|
||||
}
|
||||
TableNode* getFunctionType(Function_Stack *fs) {
|
||||
if (fs == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to getFunctionType. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
TableNode* tn = fs->FunctionType;
|
||||
return tn;
|
||||
}
|
||||
|
||||
Function_Stack* incrementArgumentNumber(Function_Stack *fs) {
|
||||
if (fs == NULL) {
|
||||
printdebug(
|
||||
"passed a NULL reference to incrementArgumentNumber. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
int cur=getArgumentNumber(fs);
|
||||
setArgumentNumber(fs, cur+1);
|
||||
//setFunctionType(fs, getFunctionNumberType(getFunctionType(fs), cur+1));
|
||||
return fs;
|
||||
}
|
||||
|
||||
TableNode* getRecordNumberType(TableNode* record, int arg){
|
||||
if(record == NULL){
|
||||
//case where NULL is being passed in
|
||||
@ -159,12 +231,20 @@ TableNode* getFunctionNumberType(TableNode* function, int arg){
|
||||
//case where invalid argument number is being passed
|
||||
return undefined;
|
||||
}
|
||||
if(getAdInfoType(function) == TYPE_FUNCTION_DECLARATION){
|
||||
|
||||
if(getAdInfoType(getParameter(function)) != TYPE_RECORD_TYPE){
|
||||
return getParameter(function);
|
||||
}else{
|
||||
return getRecordNumberType(getParameter(function), arg);
|
||||
}
|
||||
} else if(getAdInfoType(function) == TYPE_ARRAY_TYPE){
|
||||
return getArrType(function);
|
||||
}else{
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TableNode* getFunctionTypeContext(Function_Stack *fs) {
|
||||
if (fs == NULL) {
|
||||
@ -178,15 +258,15 @@ TableNode* getFunctionTypeContext(Function_Stack *fs) {
|
||||
|
||||
Context_stack *PopContext() {
|
||||
if (context_head == NULL) {
|
||||
printf("cannot pop from an empty stack. Invalid.\n");
|
||||
printf("cannot pop from an empty stack from popcontext. Invalid.\n");
|
||||
return NULL;
|
||||
}
|
||||
Context_stack *cs = context_head;
|
||||
context_head = context_head->next;
|
||||
printf("Popped context off stack: number %d\n", cs->con);
|
||||
//printf("Popped context off stack: number %d\n", cs->con);
|
||||
return cs;
|
||||
}
|
||||
|
||||
/*
|
||||
int getContextType(Context_stack *cs) {
|
||||
if (cs == NULL) {
|
||||
printdebug(
|
||||
@ -195,8 +275,7 @@ int getContextType(Context_stack *cs) {
|
||||
}
|
||||
return cs->con;
|
||||
}
|
||||
|
||||
//should be
|
||||
*/
|
||||
TableNode *getContextTypeEntry(Context_stack *cs) {
|
||||
if (cs == NULL) {
|
||||
printdebug(
|
||||
|
Reference in New Issue
Block a user