From 96c742d9ef4907c71bfcf69ffc0c06b449e45ef6 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 6 Jun 2012 15:36:18 -0400 Subject: [PATCH] Updated makefile and AST class. AST class now has a full constructor that allows you to set type text and children --- Makefile | 61 ++++++++++++++++++++++++++++++--------- source/parser/ast/ast.cpp | 15 ++++++++++ source/parser/ast/ast.h | 1 + 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 04c5de8..3ee1bf7 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,24 @@ # ############################################################################### +# Utility Function Definitions +#----------------------------- +# Function for generating an file list +flist = $(shell env find $(1) -name *.$(strip $(2)) -print) + +# Function for generating an file list +dlist = $(shell env find $(1) -type d -print) + +# Function for generating an include list +incdirs = $(addprefix -I, $(call dlist, $(1))) + +# Function for generating file dependencies +define make-depend + $(CXX) $(CXXFLAGS) -M $1 | \ + sed -e 's,\($(notdir $2)\) *:,$(dir $2)\1 $(subst .o,.d,$2): ,' \ + > $(subst .o,.d,$2) +endef + # Project and Artifact Names #--------------------------- PROJ_NAME = parseutils @@ -15,12 +33,20 @@ STATIC_NAME = lib$(PROJ_NAME).a # File and Directory Settings #---------------------------- +# Root Directories SRC_ROOT = source/ -SRC_FTYPE = cpp -SRC_FILES = $(shell find $(SRC_ROOT) -name *.$(SRC_FTYPE) -print) -OBJ_FILES = $(SRC_FILES:%.$(SRC_FTYPE)=%.o) -SRC_DIRS = $(dir $(SRC_FILES)) -INC_DIRS = $(addprefix -I,$(SRC_DIRS)) +# File Extensions +SRC_EXT = cpp +# Source File Lists +SRC_FILES = $(call flist, $(SRC_ROOT), $(SRC_EXT)) + +# Object File Lists +SRC_OBJS = $(SRC_FILES:%.$(SRC_EXT)=%.o) +# Dependecy File Lists +SRC_DEPS = $(SRC_OBJS:%.o=%.d) +# Include Directories +INC_DIRS = $(call incdirs, $(SRC_ROOT)) + # Compiler and Linker Options #---------------------------- @@ -33,16 +59,25 @@ all: shared static shared: $(SHARED_NAME) static: $(STATIC_NAME) -$(SHARED_NAME): $(OBJ_FILES) - $(CXX) $(CXX_FLAGS) -shared -o $@ $(OBJ_FILES) +# Binaries +$(SHARED_NAME): $(SRC_OBJS) + @echo Linking $@... + @$(CXX) $(CXXFLAGS) -shared -o $@ $(SRC_OBJS) -$(STATIC_NAME): $(OBJ_FILES) - $(AR) $(ARFLAGS) $@ $(OBJ_FILES) +$(STATIC_NAME): $(SRC_OBJS) + @echo Linking $@... + @$(AR) $(ARFLAGS) -o $@ $(SRC_OBJS) -$(OBJ_FILES): %.o : %.$(SRC_FTYPE) +# Object Files +$(SRC_OBJS): %.o : %.$(SRC_EXT) + @echo $< + @$(call make-depend,$<,$@) + @$(CXX) -c $(CXXFLAGS) -o $@ $< +# Cleanup clean: - $(RM) $(foreach dir,$(SRC_DIRS), $(dir)*.o) - $(RM) $(SHARED_NAME) - $(RM) $(STATIC_NAME) + @$(RM) $(SRC_OBJS) + @$(RM) $(SRC_DEPS) + @$(RM) $(SHARED_NAME) + @$(RM) $(STATIC_NAME) diff --git a/source/parser/ast/ast.cpp b/source/parser/ast/ast.cpp index 9be1c15..172b16c 100644 --- a/source/parser/ast/ast.cpp +++ b/source/parser/ast/ast.cpp @@ -48,6 +48,21 @@ AST::AST(ASTNodeType type, int child_count, ...) va_end(arg_list); } +AST::AST(ASTNodeType type, std::string text, int child_count, ...) +{ + va_list arg_list; + int i = 0; + node_type = type; + node_text = text; + node_children = new list(); + va_start (arg_list, child_count); + for (i = 0; i < child_count ; i++) + { + node_children->push_back( (AST*)va_arg(arg_list, AST*) ); + } + va_end(arg_list); +} + AST::~AST() { list::iterator it = node_children->begin(); diff --git a/source/parser/ast/ast.h b/source/parser/ast/ast.h index 5e89442..5661ce1 100644 --- a/source/parser/ast/ast.h +++ b/source/parser/ast/ast.h @@ -20,6 +20,7 @@ class AST AST(ASTNodeType type, const char* text); AST(ASTNodeType type, std::string text); AST(ASTNodeType type, int child_count, ...); + AST(ASTNodeType type, std::string text, int child_count, ...); virtual ~AST(); AST& operator = (AST& rhs); -- 2.51.0