In the present work, an in-depth analysis of the theoretical structure of the smoothed-particle hydrodynamics (hereinafter SPH) is provided for an inviscid, weakly compressible, and barotropic flow in the presence of a free surface. The role of the free surface in the SPH scheme is indeed little addressed in literature. In the present analysis, the general continuous formulation of the SPH method is considered. A detailed description of the free-surface influence on the smoothed differential operators is supplied. New and existing forms are analyzed in detail, in terms of convergence and conservation properties. The proposed analysis is based on the principle of virtual works, which permits to exhibit the link with the enforcement of the dynamic free-surface boundary condition. Finally, possible SPH formulations resulting from this analysis are investigated, in terms of consistency, conservation, and dynamic free-surface boundary condition.