Skip to content

Commit

Permalink
循環参照の問題を解決しました。詳しくはリリースノートを見てください。
Browse files Browse the repository at this point in the history
  • Loading branch information
ab25cq committed Nov 20, 2017
1 parent ec713d9 commit d4a1adc
Show file tree
Hide file tree
Showing 14 changed files with 894 additions and 803 deletions.
11 changes: 6 additions & 5 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ $(OBJ): src/*.h Makefile configure
#########################################################
install:
rm -f ./*.oclcl
./cclover2 -core Fundamental.clcl
./cclover2 -core Container.clcl
./cclover2 -core String.clcl
./cclover2 -core File.clcl
./cclover2 -core Command.clcl
# ./cclover2 -core Fundamental.clcl
# ./cclover2 -core Container.clcl
# ./cclover2 -core String.clcl
# ./cclover2 -core File.clcl
# ./cclover2 -core Command.clcl
./cclover2 -core MyOwnLibrary.clcl

mkdir -p ~/.clover2
Expand Down Expand Up @@ -280,6 +280,7 @@ permission:
########################################################
clean:
rm -fR clover2 clover2.dSYM cclover2 cclover2.dSYM iclover2 iclover2.dSYM src/*.o config.log config.status *.stackdump autom4te.cache .DS_Store core.* a.out *.oclcl *.bc *.s *.o *.ocl code/*.ocl *.clm a.c src/*.dwo *.ll *.so.1.0.0 *.so
(cd examples/; make clean)

distclean: clean
rm -fR config.h Makefile autom4te.cache
Expand Down
2 changes: 2 additions & 0 deletions examples/Dep1.clcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include "Dep2.clcl"

class Dep1 {
def p():static {
Dep2.p();
Expand Down
2 changes: 2 additions & 0 deletions examples/Dep2.clcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include "Dep1.clcl"

class Dep2 {
def p():static {
Dep1.p();
Expand Down
Binary file removed examples/Hello.ocl
Binary file not shown.
Binary file removed examples/Hello2.ocl
Binary file not shown.
Binary file removed examples/Hello2.oclcl
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdlib.h>

int main()
{
exit(0);
}
Binary file removed examples/fun.ocl
Binary file not shown.
93 changes: 57 additions & 36 deletions src/class_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ static BOOL parse_class_on_alloc_classes_phase(sParserInfo* info, sCompileInfo*
info->klass->mFlags |= CLASS_FLAGS_ALLOCATED;
}

if(!info->included_source) {
info->klass->mFlags |= CLASS_FLAGS_MODIFIED;
}
info->klass->mFlags |= CLASS_FLAGS_MODIFIED;

if(!skip_block(info)) {
return FALSE;
Expand Down Expand Up @@ -1048,13 +1046,28 @@ static BOOL parse_class_source(sParserInfo* info, sCompileInfo* cinfo);

static BOOL include_file(sParserInfo* info, sCompileInfo* cinfo)
{
/// get file name ///
/// includeするファイル名を得る ///
char file_name[PATH_MAX+1];

expect_next_character_with_one_forward("\"", info);

char* p = file_name;

/// ファイル名を絶対パスにしておく ///
if(*info->p != '/') {
char* pwd = getenv("PWD");

if(pwd) {
char* p2 = pwd;

while(*p2) {
*p++ = *p2++;
}

*p++ = '/';
}
}

while(1) {
if(*info->p == '"') {
info->p++;
Expand All @@ -1076,53 +1089,55 @@ static BOOL include_file(sParserInfo* info, sCompileInfo* cinfo)
}
*p = '\0';

/// load source file ///
sBuf source;
sBuf_init(&source);
if(strcmp(info->fname, file_name) != 0) { /// コンパイル中のファイルのincludeは禁止させる
/// load source file ///
sBuf source;
sBuf_init(&source);

if(!read_source(file_name, &source)) {
MFREE(source.mBuf);
return FALSE;
}
if(!read_source(file_name, &source)) {
MFREE(source.mBuf);
return FALSE;
}

sBuf source2;
sBuf_init(&source2);
sBuf source2;
sBuf_init(&source2);

if(!delete_comment(&source, &source2)) {
MFREE(source.mBuf);
MFREE(source2.mBuf);
return FALSE;
}
if(!delete_comment(&source, &source2)) {
MFREE(source.mBuf);
MFREE(source2.mBuf);
return FALSE;
}

char* info_p_before = info->p;
info->p = source2.mBuf;
char* info_p_before = info->p;
info->p = source2.mBuf;

char* info_sname_before = info->sname;
info->sname = file_name;
char* info_sname_before = info->sname;
info->sname = file_name;

int info_sline_before = info->sline;
info->sline = 1;
int info_sline_before = info->sline;
info->sline = 1;

BOOL info_included_source_before = info->included_source;
info->included_source = TRUE;
BOOL info_included_source_before = info->included_source;
info->included_source = TRUE;

if(!parse_class_source(info, cinfo)) {
info->p = info_p_before;
info->sname = info_sname_before;
info->sline = info_sline_before;
info->included_source = info_included_source_before;
MFREE(source.mBuf);
return FALSE;
}

if(!parse_class_source(info, cinfo)) {
info->p = info_p_before;
info->sname = info_sname_before;
info->sline = info_sline_before;
info->included_source = info_included_source_before;

MFREE(source.mBuf);
return FALSE;
MFREE(source2.mBuf);
}

info->p = info_p_before;
info->sname = info_sname_before;
info->sline = info_sline_before;
info->included_source = info_included_source_before;

MFREE(source.mBuf);
MFREE(source2.mBuf);

return TRUE;
}

Expand Down Expand Up @@ -1195,6 +1210,12 @@ BOOL compile_class_source(char* fname, char* source)
info.parse_phase = 0;
info.included_source = FALSE;

char fname2[PATH_MAX+1];

append_cwd_for_path(fname, fname2); // ファイル名を絶対パスにしておく

info.fname = fname2;

sCompileInfo cinfo;

memset(&cinfo, 0, sizeof(sCompileInfo));
Expand Down
3 changes: 3 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ struct sCompileInfoStruct;
struct sParserInfoStruct
{
char* p;
char* fname;
char* sname;
int sline;
int err_num;
Expand Down Expand Up @@ -839,6 +840,7 @@ BOOL compile_block_with_result(sNodeBlock* block, sCompileInfo* info);
BOOL compile_script(char* fname, char* source);
BOOL read_source(char* fname, sBuf* source);
BOOL delete_comment(sBuf* source, sBuf* source2);
void append_cwd_for_path(char* fname, char* fname2);

/// script.c ///
BOOL eval_file(char* fname, int stack_size);
Expand Down Expand Up @@ -1723,6 +1725,7 @@ BOOL dependency_compile(char* cwd, char* class_name, char* class_file_name, size
void dependency_final();

/// klass_compile_time.c ///
sCLClass* load_class_on_compile_time(char* class_name);
BOOL add_method_to_class(sCLClass* klass, char* method_name, sParserParam* params, int num_params, sNodeType* result_type, BOOL native_, BOOL static_, sGenericsParamInfo* ginfo);
BOOL add_field_to_class(sCLClass* klass, char* name, BOOL private_, BOOL protected_, sNodeType* result_type);
BOOL add_typedef_to_class(sCLClass* klass, char* class_name1, char* class_name2);
Expand Down
1 change: 1 addition & 0 deletions src/klass_compile_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ static BOOL search_for_class_file_on_compile_time(char* class_name, char* class_
if(rc == 0) {
snprintf(class_file_name, class_file_name_size, "%s/%s.oclcl", cwd, class_name);


if(access(class_file_name, F_OK) == 0) {
return TRUE;
}
Expand Down
Loading

0 comments on commit d4a1adc

Please sign in to comment.