printf() now supports field widths, zero-padding and left/right justification.
git-svn-id: http://picoc.googlecode.com/svn/trunk@342 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
0d83e26880
commit
d5811d37d5
24
expression.c
24
expression.c
|
@ -388,8 +388,11 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
|||
break;
|
||||
|
||||
case TokenSizeof:
|
||||
/* XXX */
|
||||
ProgramFail(Parser, "not supported");
|
||||
/* return the size of the argument */
|
||||
if (TopValue->Typ == &TypeType)
|
||||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Val->Typ, TopValue->Val->Typ->ArraySize, TRUE));
|
||||
else
|
||||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE));
|
||||
break;
|
||||
|
||||
case TokenLeftSquareBracket:
|
||||
|
@ -1112,6 +1115,23 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
|
|||
PrefixState = FALSE;
|
||||
ExpressionStackPushValue(Parser, &StackTop, LexValue);
|
||||
}
|
||||
else if (IS_TYPE_TOKEN(Token))
|
||||
{
|
||||
/* it's a type. push it on the stack like a value. this is used in sizeof() */
|
||||
struct ValueType *Typ;
|
||||
char *Identifier;
|
||||
struct Value *TypeValue;
|
||||
|
||||
if (!PrefixState)
|
||||
ProgramFail(Parser, "type not expected here");
|
||||
|
||||
PrefixState = FALSE;
|
||||
*Parser = PreState;
|
||||
TypeParse(Parser, &Typ, &Identifier);
|
||||
TypeValue = VariableAllocValueFromType(Parser, &TypeType, FALSE, NULL, FALSE);
|
||||
TypeValue->Val->Typ = Typ;
|
||||
ExpressionStackPushValueNode(Parser, &StackTop, TypeValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* it isn't a token from an expression */
|
||||
|
|
2
picoc.h
2
picoc.h
|
@ -401,7 +401,7 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe
|
|||
void LibraryInit(struct Table *GlobalTable, const char *LibraryName, struct LibraryFunction (*FuncList)[]);
|
||||
void CLibraryInit();
|
||||
void PrintCh(char OutCh, struct OutputStream *Stream);
|
||||
void PrintInt(int Num, struct OutputStream *Stream);
|
||||
void PrintInt(int Num, int FieldWidth, int ZeroPad, int LeftJustify, struct OutputStream *Stream);
|
||||
void PrintStr(const char *Str, struct OutputStream *Stream);
|
||||
void PrintFP(double Num, struct OutputStream *Stream);
|
||||
void PrintType(struct ValueType *Typ, struct OutputStream *Stream);
|
||||
|
|
|
@ -124,7 +124,7 @@ void PlatformVPrintf(const char *Format, va_list Args)
|
|||
switch (*FPos)
|
||||
{
|
||||
case 's': PrintStr(va_arg(Args, char *), &CStdOut); break;
|
||||
case 'd': PrintInt(va_arg(Args, int), &CStdOut); break;
|
||||
case 'd': PrintInt(va_arg(Args, int), 0, FALSE, FALSE, &CStdOut); break;
|
||||
case 'c': PrintCh(va_arg(Args, int), &CStdOut); break;
|
||||
case 't': PrintType(va_arg(Args, struct ValueType *), &CStdOut); break;
|
||||
#ifndef NO_FP
|
||||
|
|
Loading…
Reference in a new issue