예제 #1
0
파일: const.c 프로젝트: ArtemioUrbina/huc
/*
 *	scalar initializer
 *
 */
long scalar_initializer (long typ, long id, long stor)
{
	long i;

	if (stor == CONST)
		new_const();
	if (match("=")) {
		if (stor != CONST)
			error("can't initialize non-const scalars");
		blanks();
		if (ch() == ';') {
			error("value missing");
			return (-1);
		}
		if (ch() == '\"' && id == POINTER)
			i = get_string_ptr(typ);
		else
			i = get_raw_value(';');
		if (const_val_idx < MAX_CONST_VALUE)
			const_val[const_val_idx++] = i;
		blanks();
		if (ch() != ';') {
			error("syntax error");
			return (-1);
		}
	}
	return (1);
}
예제 #2
0
/*---------------------------------------------------------------------------*\
| \fn       echo_order
| \brief    Echoes order to stdout
\*---------------------------------------------------------------------------*/
void echo_order(
    TOrderMap&  order )
{
    std::cout
    << std::endl
    << order["orderNum"]
    << ":"
    << std::endl;

    auto maxlen = 0;

    for ( const auto info : order )
    {
        maxlen = std::max<size_t>( maxlen, info.first.length() );
    }

    for ( TOrderMap::iterator info = order.begin(); info != order.end(); ++info )
    {
        auto numblanks = maxlen - info->first.length() + 1;

        std::string blanks( numblanks, ' ' );
        std::cout
        << "\t"
        << info->first
        << blanks
        << " = "
        << info->second
        << std::endl;
    }

    std::cout << "\tendOfOrder" << std::endl;
}
void MapCSSPaintstyle::loadPainters(const QString& filename)
{
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
        return;
    QByteArray css = file.readAll();
    QString cssS(css);
    file.close();

    /* Remove comments */
    QRegExp cssComments("/\\*.*\\*/");
    cssComments.setMinimal(true);
    cssS.replace(cssComments, "");

    /* Styles */
    QRegExp cssStyle("\\s*(.*)\\s*\\{(.*)\\}");
    cssStyle.setMinimal(true);

    QRegExp blanks("\\s*");
    QRegExp attSep("\\s*;\\s*");
    QHash <QString, QStringList> styles;
    int pos=0;
    while (cssStyle.indexIn(cssS, pos) != -1) {
        QString selector = parseSelector(cssStyle.capturedTexts().at(1).trimmed());
        QString attributes = cssStyle.capturedTexts().at(2).trimmed();
        styles[selector] = attributes.split(attSep);

        pos += cssStyle.matchedLength();
    }
    qDebug() << styles;


}
예제 #4
0
파일: goto.c 프로젝트: z88dk/z88dk
int dolabel()
{
    int savelptr;
    char sname[NAMESIZE];
    SYMBOL* ptr;
    blanks();
    savelptr = lptr;
    if (symname(sname)) {
        if (gch() == ':') {
            if ((ptr = findgoto(sname)) && ptr->ident == ID_GOTOLABEL) {
                /* Label already goto'd, find some others with
                                 * same stack
                                 */
                debug(DBG_GOTO, "Starting chase %s\n", sname);
                ChaseGoto(ptr);
                ptr->type = KIND_PTR;
            } else {
                ptr = addgotosym(sname);
                ptr->type = KIND_PTR;
            }
            debug(DBG_GOTO, "Adding label not called %s\n", sname);
            ptr->offset.i = Zsp; /* Save stack for label */
            postlabel(ptr->size = getlabel());
            return (1);
        }
    }
    lptr = savelptr;
    return (0);
}
예제 #5
0
파일: primary.c 프로젝트: beretta42/FUZIX
/**
 * perform a function call
 * called from "hier11", this routine will either call the named
 * function, or if the supplied ptr is zero, will call the contents
 * of HL
 * @param ptr name of the function
 */
void callfunction(char *ptr) {
    int     nargs;

    nargs = 0;
    blanks ();
    if (ptr == 0)
        gen_push (HL_REG);
    while (!streq (line + lptr, ")")) {
        if (endst ())
            break;
        expression (NO);
        if (ptr == 0)
            gen_swap_stack ();
        gen_push (HL_REG);
        nargs = nargs + INTSIZE;
        if (!match (","))
            break;
    }
    needbrack (")");
    if (aflag)
        gnargs(nargs / INTSIZE);
    if (ptr)
        gen_call (ptr);
    else
        callstk ();
    stkp = gen_modify_stack (stkp + nargs);
}
예제 #6
0
파일: main.c 프로젝트: JamesLinus/FUZIX
/**
 * parse top level declarations
 * @param stclass storage
 * @param mtag
 * @param is_struct
 * @return 
 */
int do_declarations(int stclass, TAG_SYMBOL *mtag, int is_struct) {
    int type;
    int otag;   // tag of struct object being declared
    int sflag;		// TRUE for struct definition, zero for union
    char sname[NAMESIZE];
    int ns = 0;
    
    blanks();
    if ((sflag=amatch("struct", 6)) || amatch("union", 5)) {
        if (symname(sname) == 0) { // legal name ?
            illname();
        }
        if ((otag=find_tag(sname)) == -1) { // structure not previously defined
            otag = define_struct(sname, stclass, sflag);
        }
        declare_global(STRUCT, stclass, mtag, otag, is_struct);
    } else if ((type = get_type()) != 1) {
        ns = declare_global(type, stclass, mtag, 0, is_struct);
    } else if (stclass == PUBLIC) {
        return (0);
    } else {
        ns = declare_global(CINT, stclass, mtag, 0, is_struct);
    }
    if (!ns)
        need_semicolon();
    return (1);
}
예제 #7
0
파일: main.c 프로젝트: ArtemioUrbina/huc
/*
 *		parse top level declarations
 */
long dodcls (long stclass, TAG_SYMBOL *mtag, int is_struct)
{
	long err;
	struct type t;

	blanks();

	if (match_type(&t, NO, YES)) {
		if (t.type == CSTRUCT && t.otag == -1)
			t.otag = define_struct(t.sname, stclass, !!(t.flags & F_STRUCT));
		else if (t.type == CENUM) {
			if (t.otag == -1)
				t.otag = define_enum(t.sname, stclass);
			t.type = enum_types[t.otag].base;
		}
		err = declglb(t.type, stclass, mtag, t.otag, is_struct);
	}
	else if (stclass == PUBLIC)
		return (0);
	else
		err = declglb(CINT, stclass, mtag, NULL_TAG, is_struct);

	if (err == 2)	/* function */
		return (1);
	else if (err) {
		kill();
		return (0);
	}
	else
		ns();
	return (1);
}
예제 #8
0
파일: lex.c 프로젝트: EtchedPixels/FUZIX
/**
 * looks for a match between a literal string and the current token in
 * the input line. It skips over the token and returns true if a match occurs
 * otherwise it retains the current position in the input line and returns false
 * there is no verification that all of the token was matched
 * @param lit
 * @return 
 */
int match(char *lit) {
    int k;
    blanks();
    if ((k = streq (line + lptr, lit)) != 0) {
        lptr = lptr + k;
        return (1);
    }
    return (0);
}
예제 #9
0
파일: main.c 프로젝트: ArtemioUrbina/huc
/*
 *	process all input text
 *
 *	at this level, only static declarations, defines, includes,
 *	and function definitions are legal.
 *
 */
void parse (void)
{
	if (!startup_incl) {
		inc_startup();
		incl_globals();
	}

	while (1) {
		blanks();
		if (feof(input))
			break;
// Note:
// At beginning of 'parse' call, the header has been output to '.s'
// file, as well as all the -Asym=val operands from command line.
//
// But initial '#include "startup.asm"' statement was not yet output
// (allowing for additional asm define's to be parsed and output first.
//
// We can parse some trivial tokens first (including the asmdef...),
// but the #include "startup.asm" line must be output before actual code
// (And only once...)
//
		if (amatch("#asmdef", 7)) {
			doasmdef();
			continue;
		}

		if (amatch("extern", 6))
			dodcls(EXTERN, NULL_TAG, 0);
		else if (amatch("static", 6)) {
			if (amatch("const", 5)) {
				/* XXX: what about the static part? */
				dodcls(CONST, NULL_TAG, 0);
			}
			else
				dodcls(STATIC, NULL_TAG, 0);
		}
		else if (amatch("const", 5))
			dodcls(CONST, NULL_TAG, 0);
		else if (amatch("typedef", 7))
			dotypedef();
		else if (dodcls(PUBLIC, NULL_TAG, 0)) ;
		else if (match("#asm"))
			doasm();
		else if (match("#include"))
			doinclude();
		else if (match("#inc"))
			dopsdinc();
		else if (match("#def"))
			dopsddef();
		else
			newfunc(NULL, 0, 0, 0, 0);
	}
	if (optimize)
		flush_ins();
}
예제 #10
0
void TableFormat::writeWholeTable(
  std::ostream& out,
  const std::string& header,
  const Array<std::string>& columnNames,
  const Array<TableColumn>& columns
  ) const
{

  /* compute the total width */
  int pgWidth = 0;
  for (Array<TableColumn>::size_type i=0; i<columnNames.size(); i++)
  {
    int cw = defaultColumnWidth();
    if (columnWidths_.size() != 0) cw = columnWidths_[i];
    pgWidth += cw;
  }
  setPageWidth(std::max(pageWidth_, pgWidth));
  
  /* write the header */
  out << thickline() << std::endl;
  out << std::endl;
  int numBlanks = (pageWidth_ - header.length())/2;
  out << blanks(numBlanks) << header << std::endl;
  out << std::endl;

  /* write the column titles */
  for (Array<std::string>::size_type i=0; i<columnNames.size(); i++)
  {
    int cw = defaultColumnWidth();
    if (columnWidths_.size() != 0) cw = columnWidths_[i];

    out << std::left << std::setw(cw) << columnNames[i];
  }
  out << std::endl;

  /* ensure that all columns have the same number of rows */
  int numRows = columns[0].numRows();
  for (Array<TableColumn>::size_type i=1; i<columns.size(); i++)
  {
    TEUCHOS_ASSERT_EQUALITY(columns[i].numRows(), numRows);
  }
  
  /* write the table data */
  for (int i=0; i<numRows; i++)
  {
    if (i % lineInterval_ == 0)
      out << std::left << thinline() << std::endl;   
    writeRow(out, i, columns);
  }
  
  /* write the footer */
  out << thickline() << std::endl;

}
예제 #11
0
파일: c80.c 프로젝트: adamsch1/scc
doinclude()
{
  blanks();  /* skip over to name */
  if((input2=fopen(line+lptr,"r"))==NULL)
    {input2=0;
    error("Open failure on include file");
    }
  kill();    /* clear rest of line */
      /* so next read will come from */
      /* new file (if open */
}
예제 #12
0
파일: lex.c 프로젝트: EtchedPixels/FUZIX
void junk(void) {
    if (alphanumeric (inbyte ()))
        while (alphanumeric (ch ()))
            gch ();
    else
        while (alphanumeric (ch ())) {
            if (ch () == 0)
                break;
            gch ();
        }
    blanks ();
}
예제 #13
0
파일: lex.c 프로젝트: EtchedPixels/FUZIX
/**
 * compares two string both must be zero ended, otherwise no match found
 * advances line pointer only if match found
 * it assumes that an alphanumeric (including underscore) comparison
 * is being made and guarantees that all of the token in the source line is
 * scanned in the process
 * @param lit
 * @param len
 * @return 
 */
int amatch(char *lit, int len) {
    int k;

    blanks();
    if ((k = astreq (line + lptr, lit, len)) != 0) {
        lptr = lptr + k;
        while (alphanumeric (ch ()))
            inbyte ();
        return (1);
    }
    return (0);
}
예제 #14
0
파일: c80.c 프로젝트: adamsch1/scc
/*  definitions are legal...  */
parse()
  {
  while (eof==0)    /* do until no more input */
    {
    if(amatch("char",4)){declglb(cchar);ns();}
    else if(amatch("int",3)){declglb(cint);ns();}
    else if(match("#asm"))doasm();
    else if(match("#include"))doinclude();
    else if(match("#define"))addmac();
    else newfunc();
    blanks();  /* force eof if pending */
    }
  }
예제 #15
0
/**
 * local declarations
 * @param stclass
 * @return
 */
do_local_declares(int stclass) {
        int type = 0;
        blanks();
        if (type = get_type()) {
            declare_local(type, stclass);
        } else if (stclass == LSTATIC || stclass == DEFAUTO) {
            declare_local(CINT, stclass);
        } else {
            return(0);
        }
        need_semicolon();
        return(1);
}
예제 #16
0
파일: stmt.c 프로젝트: BouKiCHi/husic_git
int doldcls(int stclass)
{
	blanks();
	if (amatch("char", 4))
		declloc(CCHAR, stclass);
	else if (amatch("int", 3))
		declloc(CINT, stclass);
	else if (stclass == LSTATIC || stclass == DEFAUTO)
		declloc(CINT, stclass);
	else
		return(0);
	ns();
	return(1);
}
예제 #17
0
파일: lex.c 프로젝트: blakewford/BPM
junk ()
{
        if (an (inbyte ()))
                while (an (ch ()))
                        gch ();
        else
                while (an (ch ())) {
                        if (ch () == 0)
                                break;
                        gch ();
                }
        blanks ();

}
예제 #18
0
파일: main.c 프로젝트: meesokim/z88dk
void parse()
{
        while ( eof == 0 ) {            /* do until no more input */
                if ( amatch("extern") )
                        dodeclare(EXTERNAL, NULL_TAG, 0) ;
                else if (amatch("static"))
                        dodeclare(LSTATIC, NULL_TAG, 0) ;
                else if (amatch("typedef"))
                        dodeclare(TYPDEF,NULL_TAG,0) ;
                else if (dodeclare(STATIK, NULL_TAG, 0) ) ;
                else if ( ch() == '#' ) {
                        if (match("#asm")) doasm();
                        else if (match("#include")) doinclude() ;
                        else if (match("#define") ) addmac() ;
                        else 
                        {
                                clear();
                                blanks();
                        }
                }
                else newfunc();
                blanks();       /* force eof if pending */
        }
}
예제 #19
0
파일: sym.c 프로젝트: EtchedPixels/FUZIX
/**
 * test if next input string is legal symbol name
 */
int symname(char *sname) {
    int k;

    blanks();
    if (!alpha (ch ()))
        return (0);
    k = 0;
    while (alphanumeric(ch ()))
        if (k < NAMEMAX)
            sname[k++] = gch ();
        else
            gch();

    sname[k] = 0;
    return (1);
}
예제 #20
0
/*
 * initialise aggregate
 */
void agg_init(int size, int type, int ident, int *dim, int more, TAG_SYMBOL *tag)
{
    while (*dim) {
	if (ident == ARRAY && type == STRUCT) {
	    /* array of struct */
	    needchar('{');
	    str_init(tag);
	    --*dim;
	    needchar('}');
	} else {
	    init(size, ident, dim, more, (ident == ARRAY && more == CCHAR),0);
	}
	
	if (cmatch(',') == 0)
	    break;	
	blanks();
    }
}
예제 #21
0
/*
 *	open an include file
 */
doinclude ()
{
	FILE	*inp2;

	blanks ();
	if (inp2 = fixiname ())
		if (inclsp < INCLSIZ) {
			inclstk[inclsp++] = input2;
			input2 = inp2;
		} else {
			fclose (inp2);
			error ("too many nested includes");
		}
	else {
		error ("Could not open include file");
	}
	kill ();
}
예제 #22
0
파일: CC12.C 프로젝트: lubing521/protocols
/*
** Small C - 8088/8086 version - modified by R. Grehan, BYTE Magazine
** open an include file
*/
doinclude()  {
  char *cp;
  blanks();			/* skip over to name */
  switch (*lptr) {
    case '"': case '<': cp = ++lptr;
    while(*cp) {
      switch(*cp) {case '"': case '>': *cp=NULL;}
      ++cp;
      }
    }
  if((input2=fopen(lptr,"r"))==NULL) {
    input2=EOF;
    error("open failure on include file");
    }
  kill();			/* clear rest of line */
				/* so next read will come from */
				/* new file (if open) */
  }
예제 #23
0
파일: main.c 프로젝트: meesokim/z88dk
/*
 *      Open an include file
 */
void doinclude()
{
        char name[FILENAME_LEN+1], *cp ;

        blanks();       /* skip over to name */
        if (verbose)
        {
        toconsole();
        outstr(line); nl();
        tofile();
        }

        if ( inpt2 )
                error(E_NEST);
        else {
                /* ignore quotes or angle brackets round file name */
                strcpy(name, line+lptr) ;
                cp = name ;
                if ( *cp == '"' || *cp == '<' ) {
                        name[strlen(name)-1] = '\0' ;
                        ++cp ;
                }
                if ( (inpt2=fopen(cp, "r") ) == NULL ) {
                        error(E_INCLUDE) ;
                        closeout();
                        exit(1);
                }
                else {
                        saveline = lineno ;
                        savecurr = currfn ;
                        saveinfn = infunc ;
                        savestart = fnstart ;
                        newfile() ;
                }
        }
        clear();                /* clear rest of line */
                                /* so next read will come from */
                                /* new file (if open) */
}
예제 #24
0
파일: main.c 프로젝트: JamesLinus/FUZIX
/**
 * process all input text
 * at this level, only static declarations, defines, includes,
 * and function definitions are legal.
 */
void parse(void) {
    while (!input_eof) {
        if (match("#")) {
            if (match("asm"))
                doasm();
            else if (match("include"))
                doinclude();
            else if (match("define"))
                dodefine();
            else if (match("undef"))
                doundef();
        }
        else if (amatch("extern", 6))
            do_declarations(EXTERN, NULL_TAG, 0);
        else if (amatch("static", 6))
            do_declarations(STATIC, NULL_TAG, 0);
        else if (do_declarations(PUBLIC, NULL_TAG, 0))
            ;
        else {
            newfunc();
        }
        blanks();
    }
}
예제 #25
0
파일: stmt.c 프로젝트: beretta42/FUZIX
/**
 * local declarations
 * @param stclass
 * @return 
 */
int do_local_declares(int stclass) {
    int type = 0;
    int otag;   // tag of struct object being declared
    int sflag;  // TRUE for struct definition, zero for union
    char sname[NAMESIZE];
    blanks();
    if ((sflag=amatch("struct", 6)) || amatch("union", 5)) {
        if (symname(sname) == 0) { // legal name ?
            illname();
        }
        if ((otag=find_tag(sname)) == -1) { // structure not previously defined
            otag = define_struct(sname, stclass, sflag);
        }
        declare_local(STRUCT, stclass, otag);
    } else if ((type = get_type()) != 0) {
        declare_local(type, stclass, -1);
    } else if (stclass == LSTATIC || stclass == DEFAUTO) {
        declare_local(CINT, stclass, -1);
    } else {
        return(0);
    }
    need_semicolon();
    return(1);
}
예제 #26
0
파일: function.c 프로젝트: JamesLinus/FUZIX
void newfunc_typed(int storage, char *n, int type)
{
    int idx;
    SYMBOL *symbol;
    char an[NAMESIZE];

    fexitlab = getlabel();

    if ((idx = find_global(n)) > -1) {
        symbol = &symbol_table[idx];
        if (symbol->identity != FUNCTION)
            multidef(n);
    } else {
        /* extern implies global scope */
        idx = add_global(n, FUNCTION, CINT, 0, storage == EXTERN ? PUBLIC : storage);
        symbol = &symbol_table[idx];
    }
    local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC;
    argstk = 0;
    // ANSI style argument declaration
    if (doAnsiArguments()) {
        if (storage == EXTERN) {
            need_semicolon();
            return;
        }
        /* No body .. just a definition */
        if (match(";"))
            return;
    } else {
        // K&R style argument declaration
        while (!match(")")) {
            if (symname(an)) {
                if (find_locale(an) > -1)
                    multidef(an);
                else {
                    /* FIXME: struct */
                    add_local(an, 0, 0, argstk, AUTO);
                    argstk = argstk + INTSIZE;
                }
            } else {
                error("illegal argument name");
                junk();
            }
            blanks();
            if (!streq(line + lptr, ")")) {
                if (!match(","))
                    error("expected comma");
            }
            if (endst())
                break;
        }
        if (storage == EXTERN) {
            need_semicolon();
            return;
        }
        /* No body .. just a definition */
        if (match(";"))
            return;
        stkp = 0;
        argtop = argstk;
        while (argstk) {
            if ((type = get_type()) != -1) {
                notvoid(type);
                getarg(type);
                need_semicolon();
            } else {
                error("wrong number args");
                break;
            }
        }
    }
    if (symbol->offset == FUNCTION)
            multidef(n);
    symbol->offset = FUNCTION;
    output_string(n);
    output_label_terminator();
    newline();
    gen_prologue();
    statement(YES);
    print_label(fexitlab);
    output_label_terminator();
    newline();
    gen_epilogue();
    gen_modify_stack(0);
    gen_ret();
    stkp = 0;
    local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC;
}
예제 #27
0
파일: function.c 프로젝트: blakewford/BPM
newfunc ()
{
        char    n[NAMESIZE], *ptr;
        fexitlab = getlabel();

        if (!symname (n) ) {
                error ("illegal function or declaration");
                kill ();
                return;
        }
        if (ptr = findglb (n)) {
                if (ptr[IDENT] != FUNCTION)
                        multidef (n);
                else if (ptr[OFFSET] == FUNCTION)
                        multidef (n);
                else
                        ptr[OFFSET] = FUNCTION;
        } else
                addglb (n, FUNCTION, CINT, FUNCTION, PUBLIC);
        prologue ();
        if (!match ("("))
                error ("missing open paren");
        prefix ();
        outstr (n);
        col ();
        nl ();
        locptr = STARTLOC;
        argstk = 0;
        while (!match (")")) {
                if (symname (n)) {
                        if (findloc (n))
                                multidef (n);
                        else {
                                addloc (n, 0, 0, argstk, AUTO);
                                argstk = argstk + intsize();
                        }
                } else {
                        error ("illegal argument name");
                        junk ();
                }
                blanks ();
                if (!streq (line + lptr, ")")) {
                        if (!match (","))
                                error ("expected comma");
                }
                if (endst ())
                        break;
        }
        stkp = 0;
        argtop = argstk;
        while (argstk) {
                if (amatch ("register", 8)) {
                        if (amatch("char", 4))
                                getarg(CCHAR);
                        else if (amatch ("int", 3))
                                getarg(CINT);
                        else
                                getarg(CINT);
                        ns();
                } else if (amatch ("char", 4)) {
                        getarg (CCHAR);
                        ns ();
                } else if (amatch ("int", 3)) {
                        getarg (CINT);
                        ns ();
                } else {
                        error ("wrong number args");
                        break;
                }
        }
        statement(YES);
        printlabel(fexitlab);
        col();
        nl();
        modstk (0);
        gret ();
        stkp = 0;
        locptr = STARTLOC;

}
예제 #28
0
파일: declfunc.c 프로젝트: dex4er/deb-z88dk
void DoFnKR(
SYMBOL *currfn,
char   simple)
{
    char n[NAMESIZE];
    SYMBOL *prevarg;       /* ptr to symbol table entry of most recent argument */
    SYMBOL *cptr;
    TAG_SYMBOL *otag ;     /* structure tag for structure argument */
    struct varid var;

    prevarg=0;
    Zsp=0;                  /* Reset stack pointer */
    undeclared=0;
    infunc=1;



    while ( !simple && cmatch(')') == 0 ) {    /* then count args */
        /* any legal name bumps arg count */
        if ( symname(n) ) {
            /* add link to argument chain */
            if ( (cptr=addloc(n,0,CINT,0,0)) )
                cptr->offset.p = prevarg ;
            prevarg = cptr ;
            ++undeclared ;
        }
        else {
            error(E_ARGNAME);
            junk();
        }
        blanks();
        /* if not closing paren, should be comma */
        if ( ch() != ')' && cmatch(',') == 0 ) {
            warning(W_EXPCOM);
        }
        if ( endst() ) break ;
    }

    Zsp = 0 ;                       /* preset stack ptr */

    while ( undeclared ) {
		char	regit=NO;
		if (amatch("register") ) regit=YES;
        /* Auto is be default in function defns, but someone might
         * try it on...
         */
		if (amatch("auto") ) warning(W_AUTO);

        otag=GetVarID(&var,STATIK);

        if (var.type==STRUCT) {
            getarg(STRUCT, otag,NO,0,0, var.zfar,NO) ;
        } else if (var.type || regit) {
			if (regit && var.type == NO ) var.type=CINT;
            getarg(var.type,NULL_TAG,NO,0,var.sign,var.zfar,NO);
        } else {
            error(E_BADARG) ;
            break ;
        }
    }
    /* Have finished K&R parsing */
    setlocvar(prevarg,currfn);
}
예제 #29
0
파일: declvar.c 프로젝트: dex4er/deb-z88dk
/*
 *      Declare a static variable (i.e. define for use)
 *
 *  makes an entry in the symbol table so subsequent
 *  references can call symbol by name
 */
void declglb(
int typ ,               /* typ is CCHAR, CINT, DOUBLE, STRUCT, LONG, */
int storage,
TAG_SYMBOL *mtag ,              /* tag of struct whose members are being declared, or zero */
TAG_SYMBOL *otag ,              /* tag of struct for object being declared */
int is_struct ,                 /* TRUE if struct member being declared, zero if union */
char sign ,                    /* TRUE if need signed */
char zfar )                      /* TRUE if far */
{
    char sname[NAMESIZE];
    int size, ident, more, itag, type, size_st;
    long addr = -1;
    char    flagdef,match,ptrtofn;
    char    libdef,fastcall,callee;
    SYMBOL *myptr ;

    do {
        if ( endst() ) break;   /* do line */

        type = typ ;
        size = 1 ;                              /* assume 1 element */
        more =                                  /* assume dummy symbol not required */
            itag = 0 ;                              /* just for tidiness */
        flagdef=libdef=fastcall=callee=NO;


		match=ptrtofn=NO;

        while (blanks(),rcmatch('_') ) {
			match=NO;
            if (amatch("__APPFUNC__") ) { match=YES; flagdef=1; }
            if (amatch("__LIB__") /* && libdef==0 */) {match=YES; libdef|=LIBRARY; }
            if (amatch("__FASTCALL__") ) {match=YES; fastcall=REGCALL; }
            if (amatch("__SHARED__") ) {match=YES; libdef|=SHARED; }
			if (amatch("__SHAREDC__") ) {match=YES; libdef|=SHAREDC; }
			if (amatch("__CALLEE__") ) {match=YES; callee=CALLEE; }
			if (match ==NO )break;
        }

        ident = get_ident() ;
        if (storage==TYPDEF && ident !=VARIABLE && mtag ==0 ) warning(W_TYPEDEF);

        if ( symname(sname) == 0 )      /* name ok? */
            illname(sname) ;                     /* no... */

        if ( ident == PTR_TO_FNP ) {
            /* function returning pointer needs dummy symbol */
            more = dummy_idx(typ, otag) ;
            type = (zfar ? CPTR : CINT );
            size=0;
			ptrtofn=YES;
        } 
        else if ( ident == PTR_TO_FN ) {
            ident = POINTER ;
			ptrtofn=YES;
#if 0
        } else if ( cmatch('@') ) {
			storage = EXTERNP;
			constexpr(&addr,1);
#endif
        } else if ( cmatch('(') ) {
            /*
             * Here we check for functions, but we can never have a pointer to
             * function because thats considered above. Which means as a very
             * nice side effect that we don't have to consider structs/unions
             * since they can't contain functions, only pointers to functions
             * this, understandably(!) makes the work here a lot, lot easier!
             */
            storage=AddNewFunc(sname,type,storage,zfar,sign,otag,ident,&addr);
            /*
             *      On return from AddNewFunc, storage will be:
             *      EXTERNP  = external pointer, in which case addr will be set
             *  !!    FUNCTION = have prototyped a function (NOT USED!)
             *      0        = have declared a function/!! prototyped ANSI
             *
             *      If 0, then we have to get the hell out of here, FUNCTION
             *      then gracefully loop round again, if EXTERNP, carry on with
             *      this function, anything else means that we've come up
             *      against a K&R style function definition () so carry on
             *      as normal!
             *
             *      If we had our function prefixed with __APPFUNC__ then we want
             *      to write it out to the zcc_opt.def file (this bloody thing
             *      is becoming invaluable for messaging!
             *
             *	__SHARED__ indicates in a library so preserve carry flag
             * 	(so we can test with iferror)
             *
             *	__CALLEE__ indicates that the function called cleans up
             *	the stack
             *
             *	__SHAREDC__ is indicates call by rst 8 but is unused..
             *	(old idea unused, but may yet be useful)
             */
            if (flagdef) WriteDefined(sname,0);
            if (currfn) {
                /* djm 1/2/03 - since we can override lib functions don't reset the library
                   flag
                   currfn->flags&=(~LIBRARY);
                */
                if (libdef) {
                    //		currfn->flags|=LIBRARY;
                    currfn->flags|=libdef;
                }
				if (callee && (libdef&SHARED) != SHARED && \
				    (libdef&SHAREDC) != SHAREDC )
					currfn->flags|=callee;
                if (fastcall) currfn->flags|=fastcall;
            }
            if (storage==0) {
                if ( addr != -1 ) {
                    currfn->size = addr;
                }
				return;
			}
            /*
             *      External pointer..check for the closing ')'
             */
            if (storage==EXTERNP) {
                needchar(')');
            } else {
                /*
                 *  Must be a devilishly simple prototype! ();/, type...
                 */
                ptrerror(ident) ;
                if ( ident == POINTER ) {
                    /* function returning pointer needs dummy symbol */
                    more = dummy_idx(typ, otag) ;
                    type = (zfar ? CPTR : CINT );
                    ident=FUNCTIONP;
                } else {
                    ident=FUNCTION;
                }
                size = 0 ;
                                
            }
        }
        if (cmatch('[')) {         /* array? */
            ptrerror(ident) ;
            if ( ident == POINTER) {
                /* array of pointers needs dummy symbol */
                more = dummy_idx(typ, otag) ;
                type = (zfar ? CPTR : CINT );
            }
            size = needsub() ;      /* get size */
            if (size == 0 && ident == POINTER ) size=0;
            ident = ARRAY;
			if ( ptrtofn ) needtoken(")()");
        } else if ( ptrtofn ) {
            needtoken(")()") ;
		} else if ( ident == PTR_TO_PTR ) {
            ident = POINTER ;
            more = dummy_idx(typ, otag) ;
            type = (zfar ? CPTR : CINT );
        }

		if ( cmatch('@') ) {
			storage = EXTERNP;
			constexpr(&addr,1);
		}
예제 #30
0
파일: lex.c 프로젝트: EtchedPixels/FUZIX
int endst(void) {
    blanks ();
    return ((streq (line + lptr, ";") | (ch () == 0)));
}