Skip to content

Commit

Permalink
- use g++ for now to compile the generated parser/lexeer code until
Browse files Browse the repository at this point in the history
  MetaModelica problems with the alignment of double is solved.
- fix compilation errors and warnings due to compilation using g++ vs. gcc.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6079 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Sep 9, 2010
1 parent 8a07489 commit 957aab9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Parser/Makefile.common
Expand Up @@ -4,7 +4,7 @@ RMLINC = -I$(RMLHOME)/include/plain
ANTLRCMD=java -cp ./antlr-3.2/lib/antlr-3.2.jar org.antlr.Tool -report
CFLAGS=-O3
CPPFLAGS=-I$(COMPILERHOME) $(RMLINC) -I. -Iantlr-3.2/runtime/C -Iantlr-3.2/runtime/C/include
CC=gcc
CC=g++

.PHONY: all
all: libantlr3.a libomparse.a
Expand Down
36 changes: 22 additions & 14 deletions Parser/Modelica.g
Expand Up @@ -41,15 +41,23 @@ import MetaModelica_Lexer; /* Makes all tokens defined */
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "rml.h"
#include "Absyn.h"
#include "Interactive.h"
#ifdef __cplusplus
}
#endif
#include "ModelicaParserCommon.h"
#include "runtime/errorext.h"
#define ModelicaParserException -1
#define ModelicaLexerException -2
#define ModelicaParserException 100
#define ModelicaLexerException 200
#define modelicaParserAssert(cond,msg,func,_line1,_offset1,_line2,_offset2) {if (!(cond)) { \
fileinfo* __info = malloc(sizeof(fileinfo)); \
fileinfo* __info = (fileinfo*)malloc(sizeof(fileinfo)); \
CONSTRUCTEX(); \
EXCEPTION->type = ModelicaParserException; \
EXCEPTION->message = (void *) msg; \
Expand Down Expand Up @@ -92,7 +100,7 @@ goto rule ## func ## Ex; }}
#undef RML_STRUCTHDR
#define RML_STRUCTHDR(x,y) 0
#endif
#define token_to_scon(tok) mk_scon(tok->getText(tok)->chars)
#define token_to_scon(tok) mk_scon((char*)tok->getText(tok)->chars)
#define NYI(void) fprintf(stderr, "NYI \%s \%s:\%d\n", __FUNCTION__, __FILE__, __LINE__); exit(1);
#define INFO(start) Absyn__INFO(ModelicaParser_filename_RML, isReadOnly, mk_icon(start->line), mk_icon(start->charPosition+1), mk_icon(LT(1)->line), mk_icon(LT(1)->charPosition+1), Absyn__TIMESTAMP(mk_rcon(0),mk_rcon(0)))
typedef struct fileinfo_struct {
Expand Down Expand Up @@ -174,15 +182,15 @@ class_specifier returns [void* ast, void* name] @declarations {
} :
( i1=IDENT spec=class_specifier2
{
s1 = $i1.text->chars;
s1 = (char*)$i1.text->chars;
modelicaParserAssert($spec.s2 == NULL || !strcmp(s1,$spec.s2), "The identifier at start and end are different", class_specifier, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition);
$ast = $spec.ast;
$name = mk_scon(s1);
}
| EXTENDS i1=IDENT (mod=class_modification)? cmt=string_comment comp=composition T_END i2=IDENT
{
s1 = $i1.text->chars;
s2 = $i2.text->chars;
s1 = (char*)$i1.text->chars;
s2 = (char*)$i2.text->chars;
modelicaParserAssert(!strcmp(s1,s2), "The identifier at start and end are different", class_specifier, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition);
$name = mk_scon(s1);
$ast = Absyn__CLASS_5fEXTENDS($name, or_nil(mod), mk_some_or_none(cmt), comp);
Expand All @@ -196,7 +204,7 @@ class_specifier2 returns [void* ast, const char *s2] @init {
(
cmt=string_comment c=composition T_END i2=IDENT
{
$s2 = $i2.text->chars;
$s2 = (const char*)$i2.text->chars;
$ast = Absyn__PARTS(c, mk_some_or_none(cmt));
}
| EQUALS attr=base_prefix path=type_specifier ( cm=class_modification )? cmt=comment
Expand Down Expand Up @@ -230,9 +238,9 @@ ident_list returns [void* ast]:


overloading returns [void* ast] :
OVERLOAD LPAR name_list RPAR cmt=comment
OVERLOAD LPAR nl=name_list RPAR cmt=comment
{
ast = Absyn__OVERLOAD(name_list, mk_some_or_none(cmt));
ast = Absyn__OVERLOAD(nl, mk_some_or_none(cmt));
}
;

Expand Down Expand Up @@ -898,7 +906,7 @@ primary returns [void* ast] @declarations {
} :
( v=UNSIGNED_INTEGER
{
char* chars = $v.text->chars;
char* chars = (char*)$v.text->chars;
char* endptr;
errno = 0;
long l = strtol(chars,&endptr,10);
Expand Down Expand Up @@ -928,8 +936,8 @@ primary returns [void* ast] @declarations {
}
}
}
| v=UNSIGNED_REAL {$ast = Absyn__REAL(mk_rcon(atof($v.text->chars)));}
| v=STRING {$ast = Absyn__STRING(mk_scon($v.text->chars));}
| v=UNSIGNED_REAL {$ast = Absyn__REAL(mk_rcon(atof((char*)$v.text->chars)));}
| v=STRING {$ast = Absyn__STRING(mk_scon((char*)$v.text->chars));}
| T_FALSE {$ast = Absyn__BOOL(RML_FALSE);}
| T_TRUE {$ast = Absyn__BOOL(RML_TRUE);}
| ptr=component_reference__function_call {$ast = ptr;}
Expand Down Expand Up @@ -1121,7 +1129,7 @@ string_comment returns [void* ast]
@declarations {
pANTLR3_STRING t1;
} :
( s1=STRING {t1 = s1->getText(s1);} (PLUS s2=STRING {t1->appendS(t1,s2->getText(s2));})* {ast = mk_scon(t1->chars);})?
( s1=STRING {t1 = s1->getText(s1);} (PLUS s2=STRING {t1->appendS(t1,s2->getText(s2));})* {ast = mk_scon((char*)t1->chars);})?
;
annotation returns [void* ast] :
Expand Down
11 changes: 11 additions & 0 deletions Parser/ModelicaParserCommon.h
Expand Up @@ -32,7 +32,14 @@
#ifndef MODELICA_PARSER_COMMON_H
#define MODELICA_PARSER_COMMON_H

#ifndef __cplusplus
typedef unsigned char bool;
#endif

#ifdef __cplusplus
extern "C" {
#endif

extern int ModelicaParser_flags;
extern int ModelicaParser_readonly;
extern void *ModelicaParser_filename_RML;
Expand All @@ -47,4 +54,8 @@ extern const char *ModelicaParser_filename_C;
#define code_expressions_enabled(void) (ModelicaParser_flags&PARSE_CODE_EXPRESSION)
#define flat_modelica_enabled(void) (ModelicaParser_flags&PARSE_FLAT)

#ifdef __cplusplus
}
#endif

#endif
30 changes: 20 additions & 10 deletions Parser/parse.c
Expand Up @@ -34,10 +34,15 @@
#include <MetaModelica_Lexer.h>
#include <Modelica_3_Lexer.h>
#include <ModelicaParser.h>
#include "runtime/errorext.h"

#include <errno.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "runtime/errorext.h"
#include "runtime/rtopts.h" /* for accept_meta_modelica_grammar() function */

long unsigned int szMemoryUsed = 0;
long lexerFailed;

Expand Down Expand Up @@ -117,7 +122,7 @@ static void* noRecoverFromMismatchedToken(pANTLR3_BASE_RECOGNIZER recognizer, AN
if ( recognizer->mismatchIsUnwantedToken(recognizer, is, ttype) == ANTLR3_TRUE)
{
recognizer->state->exception->type = ANTLR3_UNWANTED_TOKEN_EXCEPTION;
recognizer->state->exception->message = ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME;
recognizer->state->exception->message = (void*)ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME;
recognizer->state->exception->expecting = ttype;
return NULL;
}
Expand All @@ -126,7 +131,7 @@ static void* noRecoverFromMismatchedToken(pANTLR3_BASE_RECOGNIZER recognizer, AN
{
matchedSymbol = recognizer->getMissingSymbol(recognizer, is, recognizer->state->exception, ttype, follow);
recognizer->state->exception->type = ANTLR3_MISSING_TOKEN_EXCEPTION;
recognizer->state->exception->message = ANTLR3_MISSING_TOKEN_EXCEPTION_NAME;
recognizer->state->exception->message = (void*)ANTLR3_MISSING_TOKEN_EXCEPTION_NAME;
recognizer->state->exception->token = matchedSymbol;
recognizer->state->exception->expecting = ttype;
return NULL;
Expand All @@ -151,8 +156,8 @@ static void handleLexerError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *
int isEOF = lexer->input->istream->_LA(lexer->input->istream, 1) == -1;

char* chars[] = {
isEOF ? strdup("<EOF>") : strdup(lexer->input->substr(lexer->input, lexer->getCharIndex(lexer), lexer->getCharIndex(lexer)+10)->chars),
strdup(lexer->getText(lexer)->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)
};
if (strlen(chars[1]) > 20)
chars[1][20] = '\0';
Expand Down Expand Up @@ -226,7 +231,7 @@ void handleParseError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 * tokenN
c_add_source_message(2, "SYNTAX", "Error", "Missing token: %s", token_text, 1, p_line, p_offset, p_line, p_offset, false, ModelicaParser_filename_C);
break;
case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
token_text[0] = preToken->getText(preToken)->chars;
token_text[0] = (const char*)preToken->getText(preToken)->chars;
c_add_source_message(2, "SYNTAX", "Error", "No viable alternative near token: %s", token_text, 1, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C);
break;
case ModelicaParserException:
Expand All @@ -241,8 +246,8 @@ void handleParseError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 * tokenN
case ANTLR3_EARLY_EXIT_EXCEPTION:
case ANTLR3_RECOGNITION_EXCEPTION:
default:
token_text[2] = ex->message;
token_text[1] = preToken->getText(preToken)->chars;
token_text[2] = (const char*)ex->message;
token_text[1] = (const char*)preToken->getText(preToken)->chars;
token_text[0] = preToken->type == ANTLR3_TOKEN_EOF ? "<EOF>" : (const char*) tokenNames[preToken->type];
c_add_source_message(2, "SYNTAX", "Error", "Parser error: %s near: %s (%s)", token_text, 3, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C);
break;
Expand Down Expand Up @@ -363,7 +368,7 @@ void* parseString(void* stringRML, int flags)

fName = (pANTLR3_UINT8)ModelicaParser_filename_C;
char* data = RML_STRINGDATA(stringRML);
input = antlr3NewAsciiStringInPlaceStream(data,strlen(data),fName);
input = antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)data,strlen(data),fName);
if ( input == NULL ) {
fprintf(stderr, "Unable to open file %s\n", ModelicaParser_filename_C);
return NULL;
Expand Down Expand Up @@ -422,3 +427,8 @@ RML_BEGIN_LABEL(Parser__parsestringexp)
}
}
RML_END_LABEL


#ifdef __cplusplus
}
#endif

0 comments on commit 957aab9

Please sign in to comment.