Removed redundant "struct ArrayValue"

git-svn-id: http://picoc.googlecode.com/svn/trunk@369 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-11-01 21:10:48 +00:00
parent 18acb6dc1a
commit f1aeadb077
6 changed files with 16 additions and 21 deletions

View file

@ -245,7 +245,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
if (NextArg->Typ->Base == TypePointer) if (NextArg->Typ->Base == TypePointer)
Str = NextArg->Val->NativePointer; Str = NextArg->Val->NativePointer;
else else
Str = NextArg->Val->Array.Data; Str = NextArg->Val->ArrayData;
if (Str == NULL) if (Str == NULL)
PrintStr("NULL", Stream); PrintStr("NULL", Stream);
@ -304,7 +304,7 @@ void LibSPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Val
void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{ {
struct Value *CharArray = (struct Value *)(Param[0]->Val->NativePointer); struct Value *CharArray = (struct Value *)(Param[0]->Val->NativePointer);
char *ReadBuffer = CharArray->Val->Array.Data; char *ReadBuffer = CharArray->Val->ArrayData;
char *Result; char *Result;
ReturnValue->Val->NativePointer = NULL; ReturnValue->Val->NativePointer = NULL;

View file

@ -98,7 +98,7 @@ void ExpressionStackShow(struct ExpressionStack *StackTop)
if (StackTop->Val->Val->Pointer.Segment == NULL) if (StackTop->Val->Val->Pointer.Segment == NULL)
printf("ptr(NULL)"); printf("ptr(NULL)");
else if (StackTop->Val->Typ->FromType->Base == TypeChar) else if (StackTop->Val->Typ->FromType->Base == TypeChar)
printf("\"%s\":string", (char *)StackTop->Val->Val->Pointer.Segment->Val->Array.Data + StackTop->Val->Val->Pointer.Offset); printf("\"%s\":string", (char *)StackTop->Val->Val->Pointer.Segment->Val->ArrayData + StackTop->Val->Val->Pointer.Offset);
else else
printf("ptr(0x%lx,%d)", (long)StackTop->Val->Val->Pointer.Segment, StackTop->Val->Val->Pointer.Offset); printf("ptr(0x%lx,%d)", (long)StackTop->Val->Val->Pointer.Segment, StackTop->Val->Val->Pointer.Offset);
break; break;
@ -287,7 +287,7 @@ void ExpressionAssignToPointer(struct ParseState *Parser, struct Value *ToValue,
else if (FromValue->Typ->Base == TypeArray && PointedToType == FromValue->Typ->FromType) else if (FromValue->Typ->Base == TypeArray && PointedToType == FromValue->Typ->FromType)
{ {
/* the form is: blah *x = array of blah */ /* the form is: blah *x = array of blah */
ToValue->Val->NativePointer = FromValue->Val->Array.Data; ToValue->Val->NativePointer = FromValue->Val->ArrayData;
} }
else if (FromValue->Typ->Base == TypePointer && FromValue->Typ->FromType->Base == TypeArray && PointedToType == FromValue->Typ->FromType->FromType) else if (FromValue->Typ->Base == TypePointer && FromValue->Typ->FromType->Base == TypeArray && PointedToType == FromValue->Typ->FromType->FromType)
{ {
@ -345,7 +345,7 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct
if (DestValue->Typ->ArraySize != SourceValue->Typ->ArraySize) if (DestValue->Typ->ArraySize != SourceValue->Typ->ArraySize)
AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, DestValue->Typ->ArraySize, SourceValue->Typ->ArraySize, FuncName, ParamNo); AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, DestValue->Typ->ArraySize, SourceValue->Typ->ArraySize, FuncName, ParamNo);
memcpy((void *)DestValue->Val->Array.Data, (void *)SourceValue->Val->Array.Data, DestValue->Typ->ArraySize); memcpy((void *)DestValue->Val->ArrayData, (void *)SourceValue->Val->ArrayData, DestValue->Typ->ArraySize);
break; break;
case TypeStruct: case TypeStruct:
@ -553,7 +553,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
/* make the array element result */ /* make the array element result */
switch (BottomValue->Typ->Base) switch (BottomValue->Typ->Base)
{ {
case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->Array.Data + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break; case TypeArray: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->ArrayData + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
case TypePointer: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->NativePointer + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break; case TypePointer: Result = VariableAllocValueFromExistingData(Parser, BottomValue->Typ->FromType, (union AnyValue *)((char *)BottomValue->Val->NativePointer + TypeSize(BottomValue->Typ->FromType, 0, TRUE) * ArrayIndex), BottomValue->IsLValue, BottomValue->LValueFrom); break;
default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ); default: ProgramFail(Parser, "this %t is not an array", BottomValue->Typ);
} }

4
lex.c
View file

@ -306,9 +306,9 @@ enum LexToken LexGetStringConstant(struct LexState *Lexer, struct Value *Value)
if (ArrayValue == NULL) if (ArrayValue == NULL)
{ {
/* create and store this string literal */ /* create and store this string literal */
ArrayValue = VariableAllocValueAndData(NULL, sizeof(struct ArrayValue), FALSE, NULL, TRUE); ArrayValue = VariableAllocValueAndData(NULL, sizeof(void *), FALSE, NULL, TRUE);
ArrayValue->Typ = CharArrayType; ArrayValue->Typ = CharArrayType;
ArrayValue->Val->Array.Data = RegString; ArrayValue->Val->ArrayData = RegString;
VariableStringLiteralDefine(RegString, ArrayValue); VariableStringLiteralDefine(RegString, ArrayValue);
} }

View file

@ -159,21 +159,16 @@ struct FuncDef
}; };
/* values */ /* values */
struct ArrayValue
{
void *Data; /* pointer to the array data */
};
union AnyValue union AnyValue
{ {
char Character; unsigned char Character;
short ShortInteger; short ShortInteger;
int Integer; int Integer;
unsigned char UnsignedCharacter; unsigned char UnsignedCharacter;
unsigned short UnsignedShortInteger; unsigned short UnsignedShortInteger;
unsigned int UnsignedInteger; unsigned int UnsignedInteger;
char *Identifier; char *Identifier;
struct ArrayValue Array; void *ArrayData;
struct ParseState Parser; struct ParseState Parser;
struct ValueType *Typ; struct ValueType *Typ;
struct FuncDef FuncDef; struct FuncDef FuncDef;

6
type.c
View file

@ -53,7 +53,7 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P
switch (Base) switch (Base)
{ {
case TypePointer: Sizeof = sizeof(void *); break; case TypePointer: Sizeof = sizeof(void *); break;
case TypeArray: Sizeof = sizeof(struct ArrayValue) + ArraySize * ParentType->Sizeof; break; case TypeArray: Sizeof = sizeof(void *) + ArraySize * ParentType->Sizeof; break;
case TypeEnum: Sizeof = sizeof(int); break; case TypeEnum: Sizeof = sizeof(int); break;
default: Sizeof = 0; break; /* structs and unions will get bigger when we add members to them */ default: Sizeof = 0; break; /* structs and unions will get bigger when we add members to them */
} }
@ -78,7 +78,7 @@ int TypeSizeValue(struct Value *Val)
else if (Val->Typ->Base != TypeArray) else if (Val->Typ->Base != TypeArray)
return Val->Typ->Sizeof; return Val->Typ->Sizeof;
else else
return sizeof(struct ArrayValue) + Val->Typ->FromType->Sizeof * Val->Typ->ArraySize; return sizeof(void *) + Val->Typ->FromType->Sizeof * Val->Typ->ArraySize;
} }
/* memory used by a variable given its type and array size */ /* memory used by a variable given its type and array size */
@ -89,7 +89,7 @@ int TypeSize(struct ValueType *Typ, int ArraySize, int Compact)
else if (Typ->Base != TypeArray) else if (Typ->Base != TypeArray)
return Typ->Sizeof; return Typ->Sizeof;
else else
return sizeof(struct ArrayValue) + Typ->FromType->Sizeof * ArraySize; return sizeof(void *) + Typ->FromType->Sizeof * ArraySize;
} }
/* memory used by the base (non-array) type of a type. This is used for alignment. */ /* memory used by the base (non-array) type of a type. This is used for alignment. */

View file

@ -106,7 +106,7 @@ struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct Value
assert(Size > 0 || Typ == &VoidType); assert(Size > 0 || Typ == &VoidType);
NewValue->Typ = Typ; NewValue->Typ = Typ;
if (Typ->Base == TypeArray) if (Typ->Base == TypeArray)
NewValue->Val->Array.Data = (void *)((char *)NewValue->Val + sizeof(struct ArrayValue)); NewValue->Val->ArrayData = (void *)((char *)NewValue->Val + sizeof(void *));
return NewValue; return NewValue;
} }
@ -187,12 +187,12 @@ void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LV
/* define a global variable shared with a platform global. Ident will be registered */ /* define a global variable shared with a platform global. Ident will be registered */
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable) void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable)
{ {
struct Value *SomeValue = VariableAllocValueAndData(NULL, (Typ->Base == TypeArray) ? sizeof(struct ArrayValue) : 0, IsWritable, NULL, TRUE); struct Value *SomeValue = VariableAllocValueAndData(NULL, (Typ->Base == TypeArray) ? sizeof(void *) : 0, IsWritable, NULL, TRUE);
SomeValue->Typ = Typ; SomeValue->Typ = Typ;
if (Typ->Base != TypeArray) if (Typ->Base != TypeArray)
SomeValue->Val = FromValue; SomeValue->Val = FromValue;
else else
SomeValue->Val->Array.Data = FromValue; SomeValue->Val->ArrayData = FromValue;
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue)) if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue))
ProgramFail(Parser, "'%s' is already defined", Ident); ProgramFail(Parser, "'%s' is already defined", Ident);