Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- do memory profile only when MEMORY_PROFILE is defined
- use $CLAGS in Makefile.common
- more comments in Makefile.vc
- ensure that variable declarations are first in a block in Modelica.g (for Visual Studio CL crap compiler)
- do not use void inside macros in ModelicaParserCommon.h (for Visual Studio CL crap compiler)
- ensure that variable declarations are first in a block in parse.c (for Visual Studio CL crap compiler)



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6126 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Sep 14, 2010
1 parent c85d03e commit 7702c15
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Parser/Makefile.common
Expand Up @@ -2,7 +2,7 @@ COMPILERHOME=../Compiler/
RMLINC = -I$(RMLHOME)/include/plain

ANTLRCMD=java -cp ./antlr-3.2/lib/antlr-3.2.jar org.antlr.Tool -report
CFLAGS=-O3
CFLAGS=-O3
CPPFLAGS=-I$(COMPILERHOME) $(RMLINC) -I. -Iantlr-3.2/runtime/C -Iantlr-3.2/runtime/C/include
CC=g++

Expand All @@ -11,7 +11,7 @@ all: libantlr3.a libomparse.a

libantlr3.a: antlr-3.2/runtime/C/src/* antlr-3.2/runtime/C/include/*
# build the library
gcc -O3 -c antlr-3.2/runtime/C/src/*.c -Iantlr-3.2/runtime/C/include -Iantlr-3.2/runtime/C
gcc ${CFLAGS} -c antlr-3.2/runtime/C/src/*.c -Iantlr-3.2/runtime/C/include -Iantlr-3.2/runtime/C
rm -f $@
ar -ru libantlr3.a antlr3*.o
ranlib libantlr3.a
Expand Down
1 change: 1 addition & 0 deletions Parser/Makefile.vc
Expand Up @@ -37,6 +37,7 @@ parse.obj: $(HFILES)

libomparse.lib: parse.obj $(OBJS) libantlr3.lib
@del /F /S $@
REM build the OMC Parser library that includes libantlr3.lib (the ANTLR3 C library)
LINK /LIB /LTCG /OUT:$@ parse.obj $(OBJS) libantlr3.lib

parsergen = ModelicaParser.c ModelicaParser.h
Expand Down
21 changes: 15 additions & 6 deletions Parser/Modelica.g
Expand Up @@ -76,7 +76,9 @@ goto rule ## func ## Ex; }}
#define mk_tuple2(x1,x2) mk_box2(0,x1,x2)
#define make_redeclare_keywords(replaceable,redeclare) (replaceable && redeclare ? Absyn__REDECLARE_5fREPLACEABLE : replaceable ? Absyn__REPLACEABLE : redeclare ? Absyn__REDECLARE : NULL)
#define make_inner_outer(i,o) (i && o ? Absyn__INNEROUTER : i ? Absyn__INNER : o ? Absyn__OUTER : Absyn__UNSPECIFIED)
#if 1 /* mk_bcon will be defined in RML later */
#define mk_bcon(x) (x ? RML_TRUE : RML_FALSE)
#endif
#if 0
/* Enable if you don't want to generate the tree */
void* mk_box_eat_all(int ix, ...);
Expand Down Expand Up @@ -437,6 +439,7 @@ component_clause returns [void* ast] @declarations {
fprintf(stderr, "component_clause error\n");
}

{ /* adrpo - use the ANSI C standard */
// no arr was set, inspect ar_option and fix it
struct rml_struct *p = (struct rml_struct*)RML_UNTAGPTR(ar_option);
if (RML_GETHDR(ar_option) == RML_STRUCTHDR(0,0)) // is NONE
Expand All @@ -447,6 +450,7 @@ component_clause returns [void* ast] @declarations {
{
arr = p->data[0];
}
}

ast = Absyn__COMPONENTS(Absyn__ATTR(tp.flow, tp.stream, tp.variability, tp.direction, arr), path, clst);
}
Expand Down Expand Up @@ -659,8 +663,10 @@ assign_clause_a returns [void* ast] @declarations {
{
modelicaParserAssert(RML_GETHDR(e1) == RML_STRUCTHDR(2, Absyn__CALL_3dBOX2), "Only function call expressions may stand alone in an algorithm section",
assign_clause_a, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition);
{ /* uselsess block for ANSI C crap */
struct rml_struct *p = (struct rml_struct*)RML_UNTAGPTR(e1);
$ast = Absyn__ALG_5fNORETCALL(p->data[0],p->data[1]);
}
}
)
;
Expand Down Expand Up @@ -909,16 +915,19 @@ primary returns [void* ast] @declarations {
{
char* chars = (char*)$v.text->chars;
char* endptr;
const char* args[2] = {NULL};
long l = 0;
errno = 0;
long l = strtol(chars,&endptr,10);
const char* args[2] = {chars,
RML_SIZE_INT == 8 ? "OpenModelica (64-bit) only supports 63"
: errno || *endptr != 0 ? "Modelica only supports 32"
: "OpenModelica only supports 31"};
l = strtol(chars,&endptr,10);
args[0] = chars;
args[1] = RML_SIZE_INT == 8 ? "OpenModelica (64-bit) only supports 63"
: errno || *endptr != 0 ? "Modelica only supports 32"
: "OpenModelica only supports 31";

if (errno || *endptr != 0) {
double d = 0;
errno = 0;
double d = strtod(chars,&endptr);
d = strtod(chars,&endptr);
modelicaParserAssert(*endptr == 0 && errno==0, "Number is too large to represent as a long or double on this machine", primary, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition+1);
c_add_source_message(2, "SYNTAX", "Warning", "\%s-bit signed integers! Transforming: \%s into a real",
args, 2, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition+1,
Expand Down
6 changes: 3 additions & 3 deletions Parser/ModelicaParserCommon.h
Expand Up @@ -46,9 +46,9 @@ extern const char *ModelicaParser_filename_C;
#define PARSE_META_MODELICA 1<<1
#define PARSE_EXPRESSION 1<<2
#define PARSE_CODE_EXPRESSION 1<<3
#define metamodelica_enabled(void) (ModelicaParser_flags&PARSE_META_MODELICA)
#define code_expressions_enabled(void) (ModelicaParser_flags&PARSE_CODE_EXPRESSION)
#define flat_modelica_enabled(void) (ModelicaParser_flags&PARSE_FLAT)
#define metamodelica_enabled() (ModelicaParser_flags&PARSE_META_MODELICA)
#define code_expressions_enabled() (ModelicaParser_flags&PARSE_CODE_EXPRESSION)
#define flat_modelica_enabled() (ModelicaParser_flags&PARSE_FLAT)

#ifdef __cplusplus
}
Expand Down
39 changes: 21 additions & 18 deletions Parser/parse.c
@@ -1,9 +1,9 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
Expand All @@ -14,7 +14,7 @@
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
Expand Down Expand Up @@ -45,6 +45,7 @@ extern "C" {
#include <MetaModelica_Lexer.h>
#include <Modelica_3_Lexer.h>
#include <ModelicaParser.h>
#include <antlr3intstream.h>

#include "runtime/errorext.h"
#include "runtime/rtopts.h" /* for accept_meta_modelica_grammar() function */
Expand All @@ -58,10 +59,11 @@ void Parser_5finit(void)

void lexNoRecover(pANTLR3_LEXER lexer)
{
pANTLR3_INT_STREAM inputStream = NULL;
lexer->rec->state->error = ANTLR3_TRUE;
lexer->rec->state->failed = ANTLR3_TRUE;
pANTLR3_INT_STREAM istream = lexer->input->istream;
istream->consume(istream);
inputStream = lexer->input->istream;
inputStream->consume(inputStream);
}

void noRecover(pANTLR3_BASE_RECOGNIZER recognizer)
Expand Down Expand Up @@ -152,23 +154,21 @@ static void* noRecoverFromMismatchedToken(pANTLR3_BASE_RECOGNIZER recognizer, AN

static void handleLexerError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 * tokenNames)
{
pANTLR3_LEXER lexer;
pANTLR3_EXCEPTION ex;
pANTLR3_LEXER lexer = (pANTLR3_LEXER)(recognizer->super);
pANTLR3_EXCEPTION ex = lexer->rec->state->exception;
pANTLR3_STRING ftext;

lexer = (pANTLR3_LEXER)(recognizer->super);

ex = lexer->rec->state->exception;
int isEOF = lexer->input->istream->_LA(lexer->input->istream, 1) == -1;

char* chars[] = {
isEOF ? strdup("<EOF>") : strdup((const char*)(lexer->input->substr(lexer->input, lexer->getCharIndex(lexer), lexer->getCharIndex(lexer)+10)->chars)),
strdup((const char*)lexer->getText(lexer)->chars)
};
int line = 0;
int offset = 0;

if (strlen(chars[1]) > 20)
chars[1][20] = '\0';
int line = lexer->getLine(lexer);
int offset = lexer->getCharPositionInLine(lexer)+1;
line = lexer->getLine(lexer);
offset = lexer->getCharPositionInLine(lexer)+1;
if (*chars[1])
c_add_source_message(2, "SYNTAX", "Error", "Lexer got '%s' but failed to recognize the rest: '%s'", (const char**) chars, 2, line, offset, line, offset, false, ModelicaParser_filename_C);
else
Expand Down Expand Up @@ -267,11 +267,12 @@ void* parseStream(pANTLR3_INPUT_STREAM input)
pANTLR3_LEXER pLexer;
pANTLR3_COMMON_TOKEN_STREAM tstream;
pModelicaParser psr;
void* lxr = 0;
void* res = NULL;

// TODO: Add flags to the actual Parser.parse() call instead of here?
if (accept_meta_modelica_grammar()) ModelicaParser_flags |= PARSE_META_MODELICA;

void* lxr = 0;
if (ModelicaParser_flags & PARSE_META_MODELICA) {
lxr = MetaModelica_LexerNew(input);
if (lxr == NULL ) { fprintf(stderr, "Unable to create the lexer due to malloc() failure1\n"); exit(ANTLR3_ERR_NOMEM); }
Expand Down Expand Up @@ -304,7 +305,6 @@ void* parseStream(pANTLR3_INPUT_STREAM input)
psr->pParser->rec->recoverFromMismatchedToken = noRecoverFromMismatchedToken;
// psr->pParser->rec->recoverFromMismatchedSet = noRecoverFromMismatchedSet;

void* res = NULL;
/* if (ModelicaParser_flags & PARSE_FLAT)
res = psr->flat_class(psr);
else */ if (ModelicaParser_flags & PARSE_EXPRESSION)
Expand Down Expand Up @@ -338,14 +338,16 @@ void* parseFile(void* fileNameRML, int flags)

pANTLR3_UINT8 fName;
pANTLR3_INPUT_STREAM input;
int len = 0;

ModelicaParser_filename_C = RML_STRINGDATA(fileNameRML);
/* For some reason we get undefined values if we use the old pointer; but only in rare cases */
ModelicaParser_filename_RML = mk_scon((char*)ModelicaParser_filename_C);
ModelicaParser_flags = flags;

if (debug) { fprintf(stderr, "Starting parsing of file: %s\n", ModelicaParser_filename_C); }

int len = strlen(ModelicaParser_filename_C);
len = strlen(ModelicaParser_filename_C);
if (len > 3 && 0==strcmp(ModelicaParser_filename_C+len-4,".mof"))
ModelicaParser_flags |= PARSE_FLAT;

Expand All @@ -365,6 +367,7 @@ void* parseString(void* stringRML, int flags)

pANTLR3_UINT8 fName;
pANTLR3_INPUT_STREAM input;
char* data = NULL;

ModelicaParser_filename_C = "<interactive>";
/* For some reason we get undefined values if we use the old pointer; but only in rare cases */
Expand All @@ -374,7 +377,7 @@ void* parseString(void* stringRML, int flags)
if (debug) { fprintf(stderr, "Starting parsing of file: %s\n", ModelicaParser_filename_C); }

fName = (pANTLR3_UINT8)ModelicaParser_filename_C;
char* data = RML_STRINGDATA(stringRML);
data = RML_STRINGDATA(stringRML);
input = antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)data,strlen(data),fName);
if ( input == NULL ) {
fprintf(stderr, "Unable to open file %s\n", ModelicaParser_filename_C);
Expand Down

0 comments on commit 7702c15

Please sign in to comment.